Fix Angle inversion

This commit is contained in:
Alexander Nozik 2022-09-11 21:16:48 +03:00
parent 8429577fd8
commit 8e143eb81c
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
2 changed files with 14 additions and 2 deletions

View File

@ -85,8 +85,8 @@ public val Number.degrees: Degrees get() = Degrees(toDouble())
* Normalized angle to (0, 2PI) for radians or (0, 360) for degrees.
*/
public fun Angle.normalized(): Angle = when (this) {
is Degrees -> (value + 180.0).rem(360.0).degrees
is Radians -> (value + PI).rem(PI * 2).radians
is Degrees -> value.mod(360.0).degrees
is Radians -> value.mod(PI * 2).radians
}
public fun abs(angle: Angle): Angle = if (angle < Angle.zero) -angle else angle

View File

@ -0,0 +1,12 @@
package center.sciprog.maps.coordinates
import kotlin.test.Test
import kotlin.test.assertEquals
class AngleTest {
@Test
fun normalization(){
assertEquals(30.degrees, 390.degrees.normalized())
assertEquals(30.degrees, (-330).degrees.normalized())
}
}