forked from kscience/kmath
Apply suggestions from code review
Co-authored-by: Iaroslav Postovalov <38042667+CommanderTvis@users.noreply.github.com>
This commit is contained in:
parent
603db46eb8
commit
f271ded526
@ -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 <V : Vector> GeometrySpace<V>.projectToLine(vector: V, line: Line<V>)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -6,7 +6,7 @@ import kotlin.test.assertEquals
|
||||
|
||||
internal class Euclidean2DSpaceTest {
|
||||
@Test
|
||||
fun getZero() {
|
||||
fun zero() {
|
||||
assertVectorEquals(Vector2D(0.0, 0.0), Euclidean2DSpace.zero)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -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 <V : Vector> GeometrySpace<V>.isCollinear(a: V, b: V, eps: Double = 1e-6): Boolean {
|
||||
fun <V : Vector> GeometrySpace<V>.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 <V : Vector> GeometrySpace<V>.isOrthogonal(a: V, b: V, eps: Double = 1e-6): Boolean =
|
||||
abs(a dot b) < eps
|
||||
fun <V : Vector> GeometrySpace<V>.isOrthogonal(a: V, b: V, absoluteTolerance: Double = 1e-6): Boolean =
|
||||
abs(a dot b) < absoluteTolerance
|
||||
|
Loading…
Reference in New Issue
Block a user