From a03af27821759b4cab166391d13300d1c30a6744 Mon Sep 17 00:00:00 2001 From: Yilin Wei Date: Tue, 6 Aug 2024 00:57:25 +0100 Subject: [PATCH 1/2] Add helper functions to Radians. Adds 'min', 'max' and 'unary_-' to Radians. --- .../src/main/scala/indigo/shared/datatypes/Radians.scala | 8 ++++++++ .../test/scala/indigo/shared/datatypes/RadiansTests.scala | 8 ++++++++ 2 files changed, 16 insertions(+) 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..e7a363c1c 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 From 0db8370bb28fcd98ddc809c0ae6ea0ea5549c4f1 Mon Sep 17 00:00:00 2001 From: Yilin Wei Date: Tue, 13 Aug 2024 23:16:44 +0100 Subject: [PATCH 2/2] Run 'scalafmt'. --- .../indigo/src/main/scala/indigo/shared/datatypes/Radians.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e7a363c1c..6132550a9 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/datatypes/Radians.scala @@ -76,7 +76,7 @@ object Radians: def invert: Radians = negative - def `unary_-`: Radians = negative + def `unary_-` : Radians = negative def ~==(other: Radians): Boolean = Math.abs(r.toDouble - other.toDouble) < 0.001