forked from kscience/kmath
Fix types in geometry algebras
This commit is contained in:
parent
49f0d1fe7d
commit
dba001eff3
@ -7,8 +7,7 @@ package space.kscience.kmath.geometry
|
|||||||
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D
|
import space.kscience.kmath.structures.Float64
|
||||||
import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A line formed by [start] vector of start and a [direction] vector. Direction vector is not necessarily normalized,
|
* A line formed by [start] vector of start and a [direction] vector. Direction vector is not necessarily normalized,
|
||||||
@ -25,8 +24,8 @@ private data class LineImpl<out V : Any>(override val start: V, override val dir
|
|||||||
|
|
||||||
public fun <V : Any> Line(base: V, direction: V): Line<V> = LineImpl(base, direction)
|
public fun <V : Any> Line(base: V, direction: V): Line<V> = LineImpl(base, direction)
|
||||||
|
|
||||||
public typealias Line2D = Line<Float64Vector2D>
|
public typealias Line2D = Line<Vector2D<Float64>>
|
||||||
public typealias Line3D = Line<Float64Vector3D>
|
public typealias Line3D = Line<Vector3D<Float64>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A directed line segment between [begin] and [end]
|
* A directed line segment between [begin] and [end]
|
||||||
@ -49,5 +48,5 @@ public fun <V : Any> LineSegment<V>.line(algebra: GeometrySpace<V, *>): Line<V>
|
|||||||
Line(begin, end - begin)
|
Line(begin, end - begin)
|
||||||
}
|
}
|
||||||
|
|
||||||
public typealias LineSegment2D = LineSegment<Float64Vector2D>
|
public typealias LineSegment2D = LineSegment<Vector2D<Float64>>
|
||||||
public typealias LineSegment3D = LineSegment<Float64Vector3D>
|
public typealias LineSegment3D = LineSegment<Vector3D<Float64>>
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package space.kscience.kmath.geometry.euclidean2d
|
package space.kscience.kmath.geometry
|
||||||
|
|
||||||
import space.kscience.kmath.geometry.Vector2D
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
@ -7,10 +7,11 @@ package space.kscience.kmath.geometry.euclidean2d
|
|||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import space.kscience.kmath.geometry.Vector2D
|
import space.kscience.kmath.geometry.Vector2D
|
||||||
|
import space.kscience.kmath.structures.Float64
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
|
|
||||||
|
|
||||||
public interface Circle2D<T>{
|
public interface Circle2D<T> {
|
||||||
public val center: Vector2D<T>
|
public val center: Vector2D<T>
|
||||||
public val radius: Double
|
public val radius: Double
|
||||||
}
|
}
|
||||||
@ -23,9 +24,12 @@ public val Circle2D<*>.circumference: Double get() = radius * 2 * PI
|
|||||||
@Serializable
|
@Serializable
|
||||||
public data class Float64Circle2D(
|
public data class Float64Circle2D(
|
||||||
@Serializable(Float64Space2D.VectorSerializer::class) override val center: Float64Vector2D,
|
@Serializable(Float64Space2D.VectorSerializer::class) override val center: Float64Vector2D,
|
||||||
override val radius: Double
|
override val radius: Float64,
|
||||||
): Circle2D<Double>
|
) : Circle2D<Double>
|
||||||
|
|
||||||
public fun Circle2D(center: Float64Vector2D, radius: Double): Circle2D<Double> = Float64Circle2D(center, radius)
|
public fun Circle2D(center: Vector2D<Float64>, radius: Double): Circle2D<Double> = Float64Circle2D(
|
||||||
|
center as? Float64Vector2D ?: Float64Vector2D(center.x, center.y),
|
||||||
|
radius
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +128,8 @@ public object Float64Space3D : GeometrySpace<Vector3D<Float64>, Double> {
|
|||||||
override val bufferFactory: MutableBufferFactory<Vector3D<Float64>> = MutableBufferFactory()
|
override val bufferFactory: MutableBufferFactory<Vector3D<Float64>> = MutableBufferFactory()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UnusedReceiverParameter")
|
||||||
public val Float64Field.euclidean3D: Float64Space3D get() = Float64Space3D
|
public val Float64Field.euclidean3D: Float64Space3D get() = Float64Space3D
|
||||||
|
|
||||||
|
|
||||||
public val Float64Vector3D.r: Double get() = Float64Space3D.norm(this)
|
public val Vector3D<Float64>.r: Double get() = Float64Space3D.norm(this)
|
||||||
|
@ -37,7 +37,8 @@ public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * o
|
|||||||
/**
|
/**
|
||||||
* Represent a vector as quaternion with zero a rotation angle.
|
* Represent a vector as quaternion with zero a rotation angle.
|
||||||
*/
|
*/
|
||||||
internal fun Float64Vector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z)
|
internal fun Vector3D<Float64>.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Angle in radians denoted by this quaternion rotation
|
* Angle in radians denoted by this quaternion rotation
|
||||||
@ -71,7 +72,7 @@ public val Quaternion.vector: Float64Vector3D
|
|||||||
/**
|
/**
|
||||||
* Rotate a vector in a [Float64Space3D] with [quaternion]
|
* Rotate a vector in a [Float64Space3D] with [quaternion]
|
||||||
*/
|
*/
|
||||||
public fun Float64Space3D.rotate(vector: Float64Vector3D, quaternion: Quaternion): Float64Vector3D =
|
public fun Float64Space3D.rotate(vector: Vector3D<Float64>, quaternion: Quaternion): Float64Vector3D =
|
||||||
with(QuaternionAlgebra) {
|
with(QuaternionAlgebra) {
|
||||||
val p = vector.asQuaternion()
|
val p = vector.asQuaternion()
|
||||||
(quaternion * p * quaternion.reciprocal).vector
|
(quaternion * p * quaternion.reciprocal).vector
|
||||||
|
@ -9,6 +9,7 @@ import space.kscience.kmath.geometry.euclidean2d.Float64Space2D
|
|||||||
import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D
|
import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D
|
||||||
import space.kscience.kmath.geometry.euclidean3d.Float64Space3D
|
import space.kscience.kmath.geometry.euclidean3d.Float64Space3D
|
||||||
import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D
|
import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D
|
||||||
|
import space.kscience.kmath.structures.Float64
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,7 +26,7 @@ public fun <V : Any, D : Comparable<D>> V.equalsVector(
|
|||||||
/**
|
/**
|
||||||
* Vector equality using Euclidian L2 norm and given [precision]
|
* Vector equality using Euclidian L2 norm and given [precision]
|
||||||
*/
|
*/
|
||||||
public fun Float64Vector2D.equalsVector(
|
public fun Vector2D<Float64>.equalsVector(
|
||||||
other: Float64Vector2D,
|
other: Float64Vector2D,
|
||||||
precision: Double = Float64Space2D.defaultPrecision,
|
precision: Double = Float64Space2D.defaultPrecision,
|
||||||
): Boolean = equalsVector(Float64Space2D, other, precision)
|
): Boolean = equalsVector(Float64Space2D, other, precision)
|
||||||
@ -33,7 +34,7 @@ public fun Float64Vector2D.equalsVector(
|
|||||||
/**
|
/**
|
||||||
* Vector equality using Euclidean L2 norm and given [precision]
|
* Vector equality using Euclidean L2 norm and given [precision]
|
||||||
*/
|
*/
|
||||||
public fun Float64Vector3D.equalsVector(
|
public fun Vector3D<Float64>.equalsVector(
|
||||||
other: Float64Vector3D,
|
other: Float64Vector3D,
|
||||||
precision: Double = Float64Space3D.defaultPrecision,
|
precision: Double = Float64Space3D.defaultPrecision,
|
||||||
): Boolean = equalsVector(Float64Space3D, other, precision)
|
): Boolean = equalsVector(Float64Space3D, other, precision)
|
||||||
|
Loading…
Reference in New Issue
Block a user