From 498db37a7c7d500fc0a0aa062b5177b521130442 Mon Sep 17 00:00:00 2001 From: Gleb Minaev <43728100+lounres@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:08:54 +0300 Subject: [PATCH] Add requirement on non-emptiness of composite trajectory parts list. --- .../kotlin/space/kscience/trajectory/Trajectory2D.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/trajectory-kt/src/commonMain/kotlin/space/kscience/trajectory/Trajectory2D.kt b/trajectory-kt/src/commonMain/kotlin/space/kscience/trajectory/Trajectory2D.kt index ddf7a67..9cd69a3 100644 --- a/trajectory-kt/src/commonMain/kotlin/space/kscience/trajectory/Trajectory2D.kt +++ b/trajectory-kt/src/commonMain/kotlin/space/kscience/trajectory/Trajectory2D.kt @@ -179,6 +179,10 @@ public fun CircleTrajectory2D( @Serializable @SerialName("composite") public class CompositeTrajectory2D(public val segments: List) : Trajectory2D { + init { + require(segments.isNotEmpty()) { "A composite trajectory cannot consist of an empty list of trajectories" } + } + override val length: Double get() = segments.sumOf { it.length } override val beginPose: Pose2D get() = segments.first().beginPose