Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions to Radians. #758

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading