Skip to content

Commit

Permalink
Add helper functions to Radians.
Browse files Browse the repository at this point in the history
Adds 'min', 'max' and 'unary_-' to Radians.
  • Loading branch information
yilinwei authored and davesmith00000 committed Aug 17, 2024
1 parent b7180ca commit 588755f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 588755f

Please sign in to comment.