From ea5305c8d878e910128543f44453fe7e20294164 Mon Sep 17 00:00:00 2001 From: Artyom Degtyarev Date: Fri, 24 Mar 2023 10:28:02 +0300 Subject: [PATCH 1/3] search for shortest path algorithm --- .../kscience/kmath/trajectory/DubinsTest.kt | 18 ++++-------------- .../kscience/kmath/trajectory/TangentTest.kt | 15 +-------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt index a78a5317d..fdc3bd3c7 100644 --- a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt +++ b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt @@ -7,7 +7,9 @@ package space.kscience.kmath.trajectory import space.kscience.kmath.geometry.Circle2D import space.kscience.kmath.geometry.Euclidean2DSpace.vector +import space.kscience.kmath.geometry.equalsFloat import kotlin.test.Test +import kotlin.test.assertTrue class DubinsTest { @Test @@ -31,7 +33,7 @@ class DubinsTest { finalRadius, obstacles) val length = pathLength(shortestPath(outputTangents)) - println(length) + assertTrue(length.equalsFloat(27.2113183)) } @Test @@ -65,19 +67,7 @@ class DubinsTest { finalRadius, obstacles) val length = pathLength(shortestPath(paths)) - println(length) - for (path in paths) { - println(pathLength(path)) - println(path.size) - for (tangent in path) { -// println(tangent.route) -// println(tangent.startCircle) -// println(tangent.endCircle) -// println(Euclidean2DSpace.norm(tangent.lineSegment.end - tangent.lineSegment.begin)) - } - println() - println() - } + assertTrue(length.equalsFloat(28.9678224)) } @Test fun equalCircles() { diff --git a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/TangentTest.kt b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/TangentTest.kt index 6d4493124..2ae89038c 100644 --- a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/TangentTest.kt +++ b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/TangentTest.kt @@ -12,6 +12,7 @@ import space.kscience.kmath.geometry.LineSegment import space.kscience.kmath.geometry.equalsLine import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertTrue class TangentTest { @@ -60,18 +61,4 @@ class TangentTest { val c2 = Circle2D(vector(0.0, 0.0), 1.0) assertEquals(emptyMap(), c1.tangentsToCircle(c2)) } -// -// @Test -// fun nonExistingTangents() { -// assertFailsWith { -// val c1 = Circle2D(vector(0.0, 0.0), 1.0) -// val c2 = Circle2D(vector(2.0, 0.0), 1.0) -// c1.tangentsToCircle(c2) -// } -// assertFailsWith { -// val c1 = Circle2D(vector(0.0, 0.0), 1.0) -// val c2 = Circle2D(vector(0.5, 0.0), 1.0) -// c1.tangentsToCircle(c2) -// } -// } } \ No newline at end of file From 24c39c97cd4b9186a8445dedffff4c7fcc3e5ca1 Mon Sep 17 00:00:00 2001 From: Artyom Degtyarev Date: Fri, 24 Mar 2023 10:30:13 +0300 Subject: [PATCH 2/3] search for shortest path algorithm --- .../kotlin/space/kscience/kmath/trajectory/DubinsObstacle.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/kmath-trajectory/src/commonMain/kotlin/space/kscience/kmath/trajectory/DubinsObstacle.kt b/kmath-trajectory/src/commonMain/kotlin/space/kscience/kmath/trajectory/DubinsObstacle.kt index 896803fba..ee0b58a15 100644 --- a/kmath-trajectory/src/commonMain/kotlin/space/kscience/kmath/trajectory/DubinsObstacle.kt +++ b/kmath-trajectory/src/commonMain/kotlin/space/kscience/kmath/trajectory/DubinsObstacle.kt @@ -255,7 +255,6 @@ private fun constructTangentCircles(point: DoubleVector2D, val center1 = point + normalVectors(direction, r).first val center2 = point + normalVectors(direction, r).second val p1 = center1 - point - val p2 = center2 - point return if (atan2(p1.y, p1.x) - atan2(direction.y, direction.x) in listOf(PI/2, -3*PI/2)) { mapOf(DubinsPath.SimpleType.L to Circle2D(center1, r), DubinsPath.SimpleType.R to Circle2D(center2, r)) From 11dd4088d977f5c2ecacfe264e77bf432a44a8e3 Mon Sep 17 00:00:00 2001 From: Artyom Degtyarev Date: Fri, 24 Mar 2023 10:39:51 +0300 Subject: [PATCH 3/3] search for shortest path algorithm --- .../kotlin/space/kscience/kmath/trajectory/DubinsTest.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt index fdc3bd3c7..07e9861c7 100644 --- a/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt +++ b/kmath-trajectory/src/commonTest/kotlin/space/kscience/kmath/trajectory/DubinsTest.kt @@ -9,6 +9,7 @@ import space.kscience.kmath.geometry.Circle2D import space.kscience.kmath.geometry.Euclidean2DSpace.vector import space.kscience.kmath.geometry.equalsFloat import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue class DubinsTest { @@ -33,7 +34,7 @@ class DubinsTest { finalRadius, obstacles) val length = pathLength(shortestPath(outputTangents)) - assertTrue(length.equalsFloat(27.2113183)) + assertEquals(length, 27.2113183, 1e-6) } @Test @@ -67,7 +68,7 @@ class DubinsTest { finalRadius, obstacles) val length = pathLength(shortestPath(paths)) - assertTrue(length.equalsFloat(28.9678224)) + assertEquals(length,28.9678224, 1e-6) } @Test fun equalCircles() {