diff --git a/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala b/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala index 1c4221bfc..6132550a9 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala @@ -3,6 +3,8 @@ package indigo.shared.datatypes import indigo.shared.dice.Dice import indigo.shared.time.Seconds +import scala.math + import annotation.targetName opaque type Radians = Double @@ -74,12 +76,18 @@ object Radians: def invert: Radians = negative + def `unary_-` : Radians = negative + def ~==(other: Radians): Boolean = Math.abs(r.toDouble - other.toDouble) < 0.001 def toDouble: Double = r + def max(other: Radians): Radians = math.max(r, other) + + def min(other: Radians): Radians = math.min(r, other) + def toFloat: Float = r.toFloat diff --git a/indigo/indigo/src/test/scala/indigo/shared/datatypes/RadiansTests.scala b/indigo/indigo/src/test/scala/indigo/shared/datatypes/RadiansTests.scala index 62ca73bf8..36c5a012b 100644 --- a/indigo/indigo/src/test/scala/indigo/shared/datatypes/RadiansTests.scala +++ b/indigo/indigo/src/test/scala/indigo/shared/datatypes/RadiansTests.scala @@ -52,6 +52,14 @@ class RadiansTests extends munit.FunSuite { assert(clue(Radians.mod(Radians(-11), Radians(-10))) ~== clue(Radians(-1))) } + test("max") { + assert(clue(Radians.PI.max(Radians.zero)) ~== Radians.PI) + } + + test("min") { + assert(clue(Radians.PI.min(Radians.zero)) ~== -Radians.zero) + } + def doubleCloseEnough(r1: Double, r2: Double): Boolean = r1 - 0.01 < r2 && r1 + 0.01 > r2