Skip to content

Commit

Permalink
Merge pull request #204 from TheKing0x9/num-update
Browse files Browse the repository at this point in the history
Updated the math library to use inbuilt functions
  • Loading branch information
avivbeeri committed Jul 13, 2021
2 parents d8a4ec7 + 3f5129f commit aad7119
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
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

0 comments on commit aad7119

Please sign in to comment.