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

Updated the math library to use inbuilt functions #204

Merged
merged 4 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ We'd like to thank the following people for their contributions.
* Chayim Refael Friedman [https://github.com/ChayimFriedman2]
* Benjamin Stigsen [https://github.com/benstigsen]
* Alexandru Badiu, aka voidberg [https://github.com/voidberg]
* Aayush Kashyap [https://github.com/TheKing0x9]
3 changes: 3 additions & 0 deletions docs/modules/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Returns the arctan of `n`.
#### `ceil(n: Number): Number`
Rounds `n` up to the next largest integer value.

#### `clamp(number : Number, min : Number, max : Number) : Number`
Clamps `number` between `min` and `max`.

#### `cos(n: Number): Number`
Returns the cosine of `n`.

Expand Down
25 changes: 10 additions & 15 deletions src/modules/math.wren
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,13 @@ class Math {
static max(a, b) {
assertNum(a)
assertNum(b)
if (a > b) {
return a
} else {
return b
}
return a.max(b)
}

static min(a, b) {
assertNum(a)
assertNum(b)
if (a < b) {
return a
} else {
return b
}
return a.min(b)
}

static sign(a) {
Expand All @@ -97,11 +89,14 @@ class Math {
a = b
b = swap
}
if (b < c) {
return b
} else {
return c
}
return b.min(c)
}

static clamp(number, min, max) {
assertNum(number)
assertNum(min)
assertNum(max)
return number.clamp(min, max)
}

static lerp(low, value, high) {
Expand Down