Minor refactoring of tangents
This commit is contained in:
parent
67316c4a70
commit
ed4aa47913
@ -100,9 +100,7 @@ public data class CircleTrajectory2D(
|
||||
val pose1 = calculatePose(start, s1.bearing, direction)
|
||||
val pose2 = calculatePose(end, s2.bearing, direction)
|
||||
val trajectory = CircleTrajectory2D(Circle2D(center, s1.length), pose1, pose2)
|
||||
if (trajectory.direction != direction) {
|
||||
error("Trajectory direction mismatch")
|
||||
}
|
||||
if (trajectory.direction != direction) error("Trajectory direction mismatch")
|
||||
return trajectory
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import kotlin.test.assertTrue
|
||||
|
||||
class TangentTest {
|
||||
@Test
|
||||
fun tangent() {
|
||||
fun tangents() {
|
||||
val c1 = Circle2D(vector(0.0, 0.0), 1.0)
|
||||
val c2 = Circle2D(vector(4.0, 0.0), 1.0)
|
||||
val routes = listOf(
|
||||
|
@ -6,6 +6,7 @@
|
||||
package space.kscience.kmath.trajectory.dubins
|
||||
|
||||
import space.kscience.kmath.geometry.Euclidean2DSpace
|
||||
import space.kscience.kmath.geometry.equalsFloat
|
||||
import space.kscience.kmath.trajectory.*
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertNotNull
|
||||
@ -39,7 +40,7 @@ class DubinsTests {
|
||||
val path = dubins.find { p -> DubinsPath.trajectoryTypeOf(p) === it.key }
|
||||
assertNotNull(path, "Path ${it.key} not found")
|
||||
println("${it.key}: ${path.length}")
|
||||
assertTrue(it.value.equalFloat(path.length))
|
||||
assertTrue(it.value.equalsFloat(path.length))
|
||||
|
||||
val a = path.segments[0] as CircleTrajectory2D
|
||||
val b = path.segments[1]
|
||||
|
@ -6,20 +6,16 @@
|
||||
package space.kscience.kmath.trajectory
|
||||
|
||||
import space.kscience.kmath.geometry.Euclidean2DSpace
|
||||
import space.kscience.kmath.geometry.equalsFloat
|
||||
import space.kscience.kmath.geometry.radians
|
||||
import space.kscience.kmath.geometry.sin
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.abs
|
||||
|
||||
const val maxFloatDelta = 0.000001
|
||||
|
||||
fun Double.radiansToDegrees() = this * 180 / PI
|
||||
|
||||
fun Double.equalFloat(other: Double) = abs(this - other) < maxFloatDelta
|
||||
fun DubinsPose2D.equalsFloat(other: DubinsPose2D) =
|
||||
x.equalFloat(other.x) && y.equalFloat(other.y) && bearing.radians.equalFloat(other.bearing.radians)
|
||||
x.equalsFloat(other.x) && y.equalsFloat(other.y) && bearing.radians.equalsFloat(other.bearing.radians)
|
||||
|
||||
fun StraightTrajectory2D.inverse() = StraightTrajectory2D(end, start)
|
||||
|
||||
fun StraightTrajectory2D.shift(shift: Int, width: Double): StraightTrajectory2D = with(Euclidean2DSpace) {
|
||||
val dX = width * sin(inverse().bearing)
|
||||
val dY = width * sin(bearing)
|
||||
|
@ -18,7 +18,12 @@ class ArcTests {
|
||||
@Test
|
||||
fun arcTest() = with(Euclidean2DSpace){
|
||||
val circle = Circle2D(vector(0.0, 0.0), 2.0)
|
||||
val arc = CircleTrajectory2D.of(circle.center, vector(-2.0, 0.0), vector(0.0, 2.0), CircleTrajectory2D.Direction.RIGHT)
|
||||
val arc = CircleTrajectory2D.of(
|
||||
circle.center,
|
||||
vector(-2.0, 0.0),
|
||||
vector(0.0, 2.0),
|
||||
CircleTrajectory2D.Direction.RIGHT
|
||||
)
|
||||
assertEquals(circle.circumference / 4, arc.length, 1.0)
|
||||
assertEquals(0.0, arc.start.bearing.degrees)
|
||||
assertEquals(90.0, arc.end.bearing.degrees)
|
||||
|
@ -8,7 +8,6 @@ package space.kscience.kmath.trajectory.segments
|
||||
import space.kscience.kmath.geometry.Circle2D
|
||||
import space.kscience.kmath.geometry.Euclidean2DSpace
|
||||
import space.kscience.kmath.geometry.circumference
|
||||
import space.kscience.kmath.trajectory.maxFloatDelta
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -20,6 +19,6 @@ class CircleTests {
|
||||
val radius = 2.0
|
||||
val expectedCircumference = 12.56637
|
||||
val circle = Circle2D(center, radius)
|
||||
assertEquals(expectedCircumference, circle.circumference, maxFloatDelta)
|
||||
assertEquals(expectedCircumference, circle.circumference)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user