Compare commits
No commits in common. "dba001eff345c0dafe0c38a80278fa81ec369291" and "ad66a63ac21fbaabb4b1440c122ede713c363195" have entirely different histories.
dba001eff3
...
ad66a63ac2
@ -52,7 +52,6 @@
|
||||
- Median statistics
|
||||
- Complex power of negative real numbers
|
||||
- Add proper mutability for MutableBufferND rows and columns
|
||||
- Generic Float32 and Float64 vectors are used in geometry algebras.
|
||||
|
||||
## 0.3.1 - 2023-04-09
|
||||
|
||||
|
@ -52,7 +52,7 @@ dependencies {
|
||||
|
||||
implementation("org.slf4j:slf4j-simple:1.7.32")
|
||||
// plotting
|
||||
implementation("space.kscience:plotlykt-server:0.7.0")
|
||||
implementation("space.kscience:plotlykt-server:0.5.3-dev-1")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
@ -116,7 +116,7 @@ public object CMOptimizer : Optimizer<Double, FunctionOptimization<Double>> {
|
||||
}
|
||||
addOptimizationData(gradientFunction)
|
||||
|
||||
// val logger = problem.attributes[OptimizationLog]
|
||||
val logger = problem.attributes[OptimizationLog]
|
||||
|
||||
problem.attributes[CMOptimizerData]?.let { builders: Set<SymbolIndexer.() -> OptimizationData> ->
|
||||
builders.forEach { dataBuilder ->
|
||||
|
@ -7,7 +7,8 @@ package space.kscience.kmath.geometry
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D
|
||||
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,
|
||||
@ -24,8 +25,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 typealias Line2D = Line<Vector2D<Float64>>
|
||||
public typealias Line3D = Line<Vector3D<Float64>>
|
||||
public typealias Line2D = Line<Float64Vector2D>
|
||||
public typealias Line3D = Line<Float64Vector3D>
|
||||
|
||||
/**
|
||||
* A directed line segment between [begin] and [end]
|
||||
@ -48,5 +49,5 @@ public fun <V : Any> LineSegment<V>.line(algebra: GeometrySpace<V, *>): Line<V>
|
||||
Line(begin, end - begin)
|
||||
}
|
||||
|
||||
public typealias LineSegment2D = LineSegment<Vector2D<Float64>>
|
||||
public typealias LineSegment3D = LineSegment<Vector3D<Float64>>
|
||||
public typealias LineSegment2D = LineSegment<Float64Vector2D>
|
||||
public typealias LineSegment3D = LineSegment<Float64Vector3D>
|
||||
|
@ -7,11 +7,10 @@ package space.kscience.kmath.geometry.euclidean2d
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.kscience.kmath.geometry.Vector2D
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import kotlin.math.PI
|
||||
|
||||
|
||||
public interface Circle2D<T> {
|
||||
public interface Circle2D<T>{
|
||||
public val center: Vector2D<T>
|
||||
public val radius: Double
|
||||
}
|
||||
@ -24,12 +23,9 @@ public val Circle2D<*>.circumference: Double get() = radius * 2 * PI
|
||||
@Serializable
|
||||
public data class Float64Circle2D(
|
||||
@Serializable(Float64Space2D.VectorSerializer::class) override val center: Float64Vector2D,
|
||||
override val radius: Float64,
|
||||
) : Circle2D<Double>
|
||||
override val radius: Double
|
||||
): Circle2D<Double>
|
||||
|
||||
public fun Circle2D(center: Vector2D<Float64>, radius: Double): Circle2D<Double> = Float64Circle2D(
|
||||
center as? Float64Vector2D ?: Float64Vector2D(center.x, center.y),
|
||||
radius
|
||||
)
|
||||
public fun Circle2D(center: Float64Vector2D, radius: Double): Circle2D<Double> = Float64Circle2D(center, radius)
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public interface Float32Vector2D : Vector2D<Float32>{
|
||||
}
|
||||
|
||||
|
||||
public object Float32Space2D : GeometrySpace<Vector2D<Float32>, Float32> {
|
||||
public object Float32Space2D : GeometrySpace<Float32Vector2D, Float32> {
|
||||
@Serializable
|
||||
@SerialName("Float32Vector2D")
|
||||
private data class Vector2DImpl(
|
||||
@ -54,21 +54,21 @@ public object Float32Space2D : GeometrySpace<Vector2D<Float32>, Float32> {
|
||||
|
||||
override val zero: Float32Vector2D by lazy { vector(0f, 0f) }
|
||||
|
||||
override fun norm(arg: Vector2D<Float32>): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2))
|
||||
override fun norm(arg: Float32Vector2D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2))
|
||||
|
||||
public fun Vector2D<Float32>.norm(): Float32 = norm(this)
|
||||
public fun Float32Vector2D.norm(): Float32 = norm(this)
|
||||
|
||||
override fun Vector2D<Float32>.unaryMinus(): Float32Vector2D = vector(-x, -y)
|
||||
override fun Float32Vector2D.unaryMinus(): Float32Vector2D = vector(-x, -y)
|
||||
|
||||
override fun Vector2D<Float32>.distanceTo(other: Vector2D<Float32>): Float32 = (this - other).norm()
|
||||
override fun Float32Vector2D.distanceTo(other: Float32Vector2D): Float32 = (this - other).norm()
|
||||
|
||||
override fun add(left: Vector2D<Float32>, right: Vector2D<Float32>): Float32Vector2D =
|
||||
override fun add(left: Float32Vector2D, right: Float32Vector2D): Float32Vector2D =
|
||||
vector(left.x + right.x, left.y + right.y)
|
||||
|
||||
override fun scale(a: Vector2D<Float32>, value: Double): Float32Vector2D =
|
||||
override fun scale(a: Float32Vector2D, value: Double): Float32Vector2D =
|
||||
vector(a.x * value, a.y * value)
|
||||
|
||||
override fun Vector2D<Float32>.dot(other: Vector2D<Float32>): Double =
|
||||
override fun Float32Vector2D.dot(other: Float32Vector2D): Double =
|
||||
(x * other.x + y * other.y).toDouble()
|
||||
|
||||
public val xAxis: Float32Vector2D = vector(1.0, 0.0)
|
||||
@ -76,7 +76,7 @@ public object Float32Space2D : GeometrySpace<Vector2D<Float32>, Float32> {
|
||||
|
||||
override val defaultPrecision: Float32 = 1e-3f
|
||||
|
||||
override val bufferFactory: MutableBufferFactory<Vector2D<Float32>> = MutableBufferFactory()
|
||||
override val bufferFactory: MutableBufferFactory<Float32Vector2D> = MutableBufferFactory()
|
||||
}
|
||||
|
||||
public fun Float32Vector2D(x: Number, y: Number): Float32Vector2D = Float32Space2D.vector(x, y)
|
||||
|
@ -35,7 +35,7 @@ public typealias DoubleVector2D = Float64Vector2D
|
||||
/**
|
||||
* 2D Euclidean space
|
||||
*/
|
||||
public object Float64Space2D : GeometrySpace<Vector2D<Float64>, Float64>, ScaleOperations<Vector2D<Float64>> {
|
||||
public object Float64Space2D : GeometrySpace<Float64Vector2D, Float64>, ScaleOperations<Float64Vector2D> {
|
||||
|
||||
|
||||
@Serializable
|
||||
@ -61,23 +61,23 @@ public object Float64Space2D : GeometrySpace<Vector2D<Float64>, Float64>, ScaleO
|
||||
|
||||
override val zero: Float64Vector2D by lazy { vector(0.0, 0.0) }
|
||||
|
||||
override fun norm(arg: Vector2D<Float64>): Double = sqrt(arg.x.pow(2) + arg.y.pow(2))
|
||||
override fun norm(arg: Float64Vector2D): Double = sqrt(arg.x.pow(2) + arg.y.pow(2))
|
||||
|
||||
override fun Vector2D<Float64>.unaryMinus(): Float64Vector2D = vector(-x, -y)
|
||||
override fun Float64Vector2D.unaryMinus(): Float64Vector2D = vector(-x, -y)
|
||||
|
||||
override fun Vector2D<Float64>.distanceTo(other: Vector2D<Float64>): Double = norm(this - other)
|
||||
override fun add(left: Vector2D<Float64>, right: Vector2D<Float64>): Float64Vector2D =
|
||||
override fun Float64Vector2D.distanceTo(other: Float64Vector2D): Double = norm(this - other)
|
||||
override fun add(left: Float64Vector2D, right: Float64Vector2D): Float64Vector2D =
|
||||
vector(left.x + right.x, left.y + right.y)
|
||||
|
||||
override fun scale(a: Vector2D<Float64>, value: Double): Float64Vector2D = vector(a.x * value, a.y * value)
|
||||
override fun Vector2D<Float64>.dot(other: Vector2D<Float64>): Double = x * other.x + y * other.y
|
||||
override fun scale(a: Float64Vector2D, value: Double): Float64Vector2D = vector(a.x * value, a.y * value)
|
||||
override fun Float64Vector2D.dot(other: Float64Vector2D): Double = x * other.x + y * other.y
|
||||
|
||||
public val xAxis: Float64Vector2D = vector(1.0, 0.0)
|
||||
public val yAxis: Float64Vector2D = vector(0.0, 1.0)
|
||||
|
||||
override val defaultPrecision: Double = 1e-6
|
||||
|
||||
override val bufferFactory: MutableBufferFactory<Vector2D<Float64>> = MutableBufferFactory()
|
||||
override val bufferFactory: MutableBufferFactory<Float64Vector2D> = MutableBufferFactory()
|
||||
}
|
||||
|
||||
public fun Float64Vector2D(x: Number, y: Number): Float64Vector2D = Float64Space2D.vector(x, y)
|
||||
|
@ -3,7 +3,9 @@
|
||||
* 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
|
||||
package space.kscience.kmath.geometry.euclidean2d
|
||||
|
||||
import space.kscience.kmath.geometry.Vector2D
|
||||
|
||||
|
||||
/**
|
@ -26,7 +26,7 @@ public interface Float32Vector3D : Vector3D<Float>{
|
||||
}
|
||||
|
||||
|
||||
public object Float32Space3D : GeometrySpace<Vector3D<Float32>, Float32> {
|
||||
public object Float32Space3D : GeometrySpace<Float32Vector3D, Float32> {
|
||||
|
||||
@Serializable
|
||||
@SerialName("Float32Vector3D")
|
||||
@ -56,21 +56,21 @@ public object Float32Space3D : GeometrySpace<Vector3D<Float32>, Float32> {
|
||||
|
||||
override val zero: Float32Vector3D by lazy { vector(0.0, 0.0, 0.0) }
|
||||
|
||||
override fun norm(arg: Vector3D<Float32>): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2))
|
||||
override fun norm(arg: Float32Vector3D): Float32 = sqrt(arg.x.pow(2) + arg.y.pow(2) + arg.z.pow(2))
|
||||
|
||||
public fun Vector3D<Float32>.norm(): Float32 = norm(this)
|
||||
public fun Float32Vector3D.norm(): Float32 = norm(this)
|
||||
|
||||
override fun Vector3D<Float32>.unaryMinus(): Float32Vector3D = vector(-x, -y, -z)
|
||||
override fun Float32Vector3D.unaryMinus(): Float32Vector3D = vector(-x, -y, -z)
|
||||
|
||||
override fun Vector3D<Float32>.distanceTo(other: Vector3D<Float32>): Float32 = (this - other).norm()
|
||||
override fun Float32Vector3D.distanceTo(other: Float32Vector3D): Float32 = (this - other).norm()
|
||||
|
||||
override fun add(left: Vector3D<Float32>, right: Vector3D<Float32>): Float32Vector3D =
|
||||
override fun add(left: Float32Vector3D, right: Float32Vector3D): Float32Vector3D =
|
||||
vector(left.x + right.x, left.y + right.y, left.z + right.z)
|
||||
|
||||
override fun scale(a: Vector3D<Float32>, value: Double): Float32Vector3D =
|
||||
override fun scale(a: Float32Vector3D, value: Double): Float32Vector3D =
|
||||
vector(a.x * value, a.y * value, a.z * value)
|
||||
|
||||
override fun Vector3D<Float32>.dot(other: Vector3D<Float32>): Double =
|
||||
override fun Float32Vector3D.dot(other: Float32Vector3D): Double =
|
||||
(x * other.x + y * other.y + z * other.z).toDouble()
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ public object Float32Space3D : GeometrySpace<Vector3D<Float32>, Float32> {
|
||||
|
||||
override val defaultPrecision: Float32 = 1e-3f
|
||||
|
||||
override val bufferFactory: MutableBufferFactory<Vector3D<Float32>> = MutableBufferFactory()
|
||||
override val bufferFactory: MutableBufferFactory<Float32Vector3D> = MutableBufferFactory()
|
||||
}
|
||||
|
||||
public fun Float32Vector3D(x: Number, y: Number, z: Number): Float32Vector3D = Float32Space3D.vector(x, y, z)
|
||||
|
@ -128,8 +128,7 @@ public object Float64Space3D : GeometrySpace<Vector3D<Float64>, Double> {
|
||||
override val bufferFactory: MutableBufferFactory<Vector3D<Float64>> = MutableBufferFactory()
|
||||
}
|
||||
|
||||
@Suppress("UnusedReceiverParameter")
|
||||
public val Float64Field.euclidean3D: Float64Space3D get() = Float64Space3D
|
||||
|
||||
|
||||
public val Vector3D<Float64>.r: Double get() = Float64Space3D.norm(this)
|
||||
public val Float64Vector3D.r: Double get() = Float64Space3D.norm(this)
|
||||
|
@ -37,8 +37,7 @@ public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * o
|
||||
/**
|
||||
* Represent a vector as quaternion with zero a rotation angle.
|
||||
*/
|
||||
internal fun Vector3D<Float64>.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z)
|
||||
|
||||
internal fun Float64Vector3D.asQuaternion(): Quaternion = Quaternion(0.0, x, y, z)
|
||||
|
||||
/**
|
||||
* Angle in radians denoted by this quaternion rotation
|
||||
@ -72,7 +71,7 @@ public val Quaternion.vector: Float64Vector3D
|
||||
/**
|
||||
* Rotate a vector in a [Float64Space3D] with [quaternion]
|
||||
*/
|
||||
public fun Float64Space3D.rotate(vector: Vector3D<Float64>, quaternion: Quaternion): Float64Vector3D =
|
||||
public fun Float64Space3D.rotate(vector: Float64Vector3D, quaternion: Quaternion): Float64Vector3D =
|
||||
with(QuaternionAlgebra) {
|
||||
val p = vector.asQuaternion()
|
||||
(quaternion * p * quaternion.reciprocal).vector
|
||||
|
@ -9,7 +9,6 @@ import space.kscience.kmath.geometry.euclidean2d.Float64Space2D
|
||||
import space.kscience.kmath.geometry.euclidean2d.Float64Vector2D
|
||||
import space.kscience.kmath.geometry.euclidean3d.Float64Space3D
|
||||
import space.kscience.kmath.geometry.euclidean3d.Float64Vector3D
|
||||
import space.kscience.kmath.structures.Float64
|
||||
|
||||
|
||||
/**
|
||||
@ -26,7 +25,7 @@ public fun <V : Any, D : Comparable<D>> V.equalsVector(
|
||||
/**
|
||||
* Vector equality using Euclidian L2 norm and given [precision]
|
||||
*/
|
||||
public fun Vector2D<Float64>.equalsVector(
|
||||
public fun Float64Vector2D.equalsVector(
|
||||
other: Float64Vector2D,
|
||||
precision: Double = Float64Space2D.defaultPrecision,
|
||||
): Boolean = equalsVector(Float64Space2D, other, precision)
|
||||
@ -34,7 +33,7 @@ public fun Vector2D<Float64>.equalsVector(
|
||||
/**
|
||||
* Vector equality using Euclidean L2 norm and given [precision]
|
||||
*/
|
||||
public fun Vector3D<Float64>.equalsVector(
|
||||
public fun Float64Vector3D.equalsVector(
|
||||
other: Float64Vector3D,
|
||||
precision: Double = Float64Space3D.defaultPrecision,
|
||||
): Boolean = equalsVector(Float64Space3D, other, precision)
|
||||
|
Loading…
Reference in New Issue
Block a user