0.3.1-dev-11 #510

Merged
altavir merged 80 commits from dev into master 2023-04-05 18:46:36 +03:00
Showing only changes of commit 6deeaf057e - Show all commits

View File

@ -5,10 +5,17 @@
package space.kscience.kmath.geometry package space.kscience.kmath.geometry
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlin.jvm.JvmInline import kotlin.jvm.JvmInline
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.floor import kotlin.math.floor
@Serializable(AngleSerializer::class)
public sealed interface Angle : Comparable<Angle> { public sealed interface Angle : Comparable<Angle> {
public fun toRadians(): Radians public fun toRadians(): Radians
public fun toDegrees(): Degrees public fun toDegrees(): Degrees
@ -29,9 +36,21 @@ public sealed interface Angle : Comparable<Angle> {
} }
} }
public object AngleSerializer : KSerializer<Angle> {
override val descriptor: SerialDescriptor get() = Double.serializer().descriptor
override fun deserialize(decoder: Decoder): Angle = decoder.decodeDouble().degrees
override fun serialize(encoder: Encoder, value: Angle) {
encoder.encodeDouble(value.degrees)
}
}
/** /**
* Type safe radians * Type safe radians
*/ */
@Serializable
@JvmInline @JvmInline
public value class Radians(public val value: Double) : Angle { public value class Radians(public val value: Double) : Angle {
override fun toRadians(): Radians = this override fun toRadians(): Radians = this