diff --git a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Projections.kt b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Projections.kt index d13ef03a1..205bc17e7 100644 --- a/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Projections.kt +++ b/kmath-geometry/src/commonMain/kotlin/space/kscience/kmath/geometry/Projections.kt @@ -1,7 +1,7 @@ package space.kscience.kmath.geometry /** - * Project vector to a line + * Project vector onto a line. * @param vector to project * @param line line to which vector should be projected */ @@ -10,8 +10,8 @@ public fun GeometrySpace.projectToLine(vector: V, line: Line) } /** - * Project vector to a hyper-plane, which is defined by a normal and base - * In 2d case it is projection to a line, in 3d case it is projection to a plane + * Project vector onto a hyperplane, which is defined by a normal and base. + * In 2D case it is the projection to a line, in 3d case it is the one to a plane. * @param vector to project * @param normal normal (perpendicular) vector to a hyper-plane to which vector should be projected * @param base point belonging to a hyper-plane to which vector should be projected diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt index 6d5ae9948..5913b2fa9 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean2DSpaceTest.kt @@ -6,7 +6,7 @@ import kotlin.test.assertEquals internal class Euclidean2DSpaceTest { @Test - fun getZero() { + fun zero() { assertVectorEquals(Vector2D(0.0, 0.0), Euclidean2DSpace.zero) } @@ -59,4 +59,4 @@ internal class Euclidean2DSpaceTest { assertVectorEquals(Vector2D(300.0, 0.0003), Vector2D(100.0, 0.0001) * 3) } } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt index 9cce44c65..2c74cbd27 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Euclidean3DSpaceTest.kt @@ -5,7 +5,7 @@ import kotlin.test.assertEquals internal class Euclidean3DSpaceTest { @Test - fun getZero() { + fun zero() { assertVectorEquals(Vector3D(0.0, 0.0, 0.0), Euclidean3DSpace.zero) } @@ -71,4 +71,4 @@ internal class Euclidean3DSpaceTest { assertVectorEquals(Vector3D(2.0, -4.0, 0.0), Vector3D(1.0, -2.0, 0.0) * 2) } } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt index 78ce98dc4..65291ee4e 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionAlongTest.kt @@ -58,4 +58,4 @@ internal class ProjectionAlongTest { } } } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt index ec74ff59b..0f74e1efb 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/ProjectionOntoLineTest.kt @@ -80,4 +80,4 @@ internal class ProjectionOntoLineTest { } } } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt index 647004f43..84b1f4fd6 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector2DTest.kt @@ -9,7 +9,7 @@ internal class Vector2DTest { private val vector = Vector2D(1.0, -7.999) @Test - fun getSize() { + fun size() { assertEquals(2, vector.size) } @@ -20,17 +20,17 @@ internal class Vector2DTest { } @Test - operator fun iterator() { + fun iterator() { assertEquals(listOf(1.0, -7.999), vector.toList()) } @Test - fun getX() { + fun x() { assertEquals(1.0, vector.x) } @Test - fun getY() { + fun y() { assertEquals(-7.999, vector.y) } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt index 83271160f..717e78871 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/Vector3DTest.kt @@ -8,7 +8,7 @@ internal class Vector3DTest { private val vector = Vector3D(1.0, -7.999, 0.001) @Test - fun getSize() { + fun size() { assertEquals(3, vector.size) } @@ -20,22 +20,22 @@ internal class Vector3DTest { } @Test - operator fun iterator() { + fun iterator() { assertEquals(listOf(1.0, -7.999, 0.001), vector.toList()) } @Test - fun getX() { + fun x() { assertEquals(1.0, vector.x) } @Test - fun getY() { + fun y() { assertEquals(-7.999, vector.y) } @Test - fun getZ() { + fun z() { assertEquals(0.001, vector.z) } -} \ No newline at end of file +} diff --git a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt index 773d6d90c..1277c0130 100644 --- a/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt +++ b/kmath-geometry/src/commonTest/kotlin/space/kscience/kmath/geometry/testUtils.kt @@ -20,22 +20,22 @@ fun grid( return xs.flatMap { x -> ys.map { y -> x to y } } } -fun assertVectorEquals(expected: Vector2D, actual: Vector2D, eps: Double = 1e-6) { - assertEquals(expected.x, actual.x, eps) - assertEquals(expected.y, actual.y, eps) +fun assertVectorEquals(expected: Vector2D, actual: Vector2D, absoluteTolerance: Double = 1e-6) { + assertEquals(expected.x, actual.x, absoluteTolerance) + assertEquals(expected.y, actual.y, absoluteTolerance) } -fun assertVectorEquals(expected: Vector3D, actual: Vector3D, eps: Double = 1e-6) { - assertEquals(expected.x, actual.x, eps) - assertEquals(expected.y, actual.y, eps) - assertEquals(expected.z, actual.z, eps) +fun assertVectorEquals(expected: Vector3D, actual: Vector3D, absoluteTolerance: Double = 1e-6) { + assertEquals(expected.x, actual.x, absoluteTolerance) + assertEquals(expected.y, actual.y, absoluteTolerance) + assertEquals(expected.z, actual.z, absoluteTolerance) } -fun GeometrySpace.isCollinear(a: V, b: V, eps: Double = 1e-6): Boolean { +fun GeometrySpace.isCollinear(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean { val aDist = a.distanceTo(zero) val bDist = b.distanceTo(zero) - return abs(aDist) < eps || abs(bDist) < eps || abs(abs((a dot b) / (aDist * bDist)) - 1) < eps + return abs(aDist) < absoluteTolerance || abs(bDist) < absoluteTolerance || abs(abs((a dot b) / (aDist * bDist)) - 1) < absoluteTolerance } -fun GeometrySpace.isOrthogonal(a: V, b: V, eps: Double = 1e-6): Boolean = - abs(a dot b) < eps +fun GeometrySpace.isOrthogonal(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean = + abs(a dot b) < absoluteTolerance