Skip to content

Commit 136e683

Browse files
OutOfBearsIgnisRBX
andauthored
Implement definitions for math.lerp and math.map (#1020)
## Changes This PR updates the math documentation to include the definitions for the newly added `math.lerp` and `math.map` ## Checks By submitting your pull request for review, you agree to the following: - [x] This contribution was created in whole or in part by me, and I have the right to submit it under the terms of this repository's open source licenses. - [x] I understand and agree that this contribution and a record of it are public, maintained indefinitely, and may be redistributed under the terms of this repository's open source licenses. - [x] To the best of my knowledge, all proposed changes are accurate. --------- Co-authored-by: IgnisRBX <[email protected]>
1 parent db8cfb1 commit 136e683

File tree

1 file changed

+85
-15
lines changed
  • content/en-us/reference/engine/libraries

1 file changed

+85
-15
lines changed

content/en-us/reference/engine/libraries/math.yaml

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ functions:
248248
Returns `m` and `e` such that `x` = `m`\*`2`^`e`.
249249
description: |
250250
Returns `m` and `e` such that `x` = `m`\*`2`^`e`. `e` is an integer and
251-
the absolute value of `m` is in the range of 0.5 to 1 (inclusive of 0.5
252-
but exclusive of 1), or zero when `x` is zero.
251+
the absolute value of `m` is in the range of `0.5` to `1` (inclusive of `0.5`
252+
but exclusive of `1`), or zero when `x` is zero.
253253
parameters:
254254
- name: x
255255
type: number
@@ -281,6 +281,36 @@ functions:
281281
summary: ''
282282
tags:
283283
code_samples:
284+
- name: math.lerp
285+
summary: |
286+
Returns the linear interpolation between `a` and `b`.
287+
description: |
288+
Returns the linear interpolation between `a` and `b` based on the factor `t`.
289+
290+
This function uses the formula `a`+`(b-a)`\*`t`. `t` is typically
291+
between `0` and `1` but values outside this range are acceptable.
292+
parameters:
293+
- name: a
294+
type: number
295+
default:
296+
summary: |
297+
The starting value.
298+
- name: b
299+
type: number
300+
default:
301+
summary: |
302+
The ending value.
303+
- name: t
304+
type: number
305+
default:
306+
summary: |
307+
The interpolation factor, typically between `0` and `1`.
308+
returns:
309+
- type: number
310+
summary: |
311+
The interpolated value between `a` and `b`.
312+
tags:
313+
code_samples:
284314
- name: math.log
285315
summary: |
286316
Returns the logarithm of `x` using the given base.
@@ -317,6 +347,46 @@ functions:
317347
summary: ''
318348
tags:
319349
code_samples:
350+
- name: math.map
351+
summary: |
352+
Returns the value of `x` mapped from one range to another.
353+
description: |
354+
Returns a value that represents `x` mapped linearly from the input range
355+
(`inmin` to `inmax`) to the output range (`outmin` to `outmax`). This is
356+
achieved by determining the relative position of `x` within the input
357+
range and applying that ratio to the output range.
358+
parameters:
359+
- name: x
360+
type: number
361+
default:
362+
summary: |
363+
The number to be mapped.
364+
- name: inmin
365+
type: number
366+
default:
367+
summary: |
368+
The lower bound of the input range.
369+
- name: inmax
370+
type: number
371+
default:
372+
summary: |
373+
The upper bound of the input range.
374+
- name: outmin
375+
type: number
376+
default:
377+
summary: |
378+
The lower bound of the output range.
379+
- name: outmax
380+
type: number
381+
default:
382+
summary: |
383+
The upper bound of the output range.
384+
returns:
385+
- type: number
386+
summary: |
387+
The value of `x` mapped to the output range.
388+
tags:
389+
code_samples:
320390
- name: math.max
321391
summary: |
322392
Returns the maximum value among the numbers passed to the function.
@@ -379,7 +449,7 @@ functions:
379449
Returns a Perlin noise value.
380450
description: |
381451
Returns a Perlin noise value. The returned value is most often between the
382-
range of -1 to 1 (inclusive) but sometimes may be outside that range; if
452+
range of `-1` to `1` (inclusive) but sometimes may be outside that range; if
383453
the interval is critical to you, use `Library.math.clamp(noise, -1, 1)` on
384454
the output.
385455
@@ -393,9 +463,9 @@ functions:
393463
will always return `0.48397532105446` and `Library.math.noise(1.158, 6)`
394464
will always return `0.15315161645412`.
395465
396-
If `x`, `y`, and `z` are all integers, the return value will be 0. For
466+
If `x`, `y`, and `z` are all integers, the return value will be `0`. For
397467
fractional values of `x`, `y`, and `z`, the return value will gradually
398-
fluctuate between -0.5 and 0.5. For coordinates that are close to each
468+
fluctuate between `-0.5` and `0.5`. For coordinates that are close to each
399469
other, the return values will also be close to each other.
400470
parameters:
401471
- name: x
@@ -455,10 +525,10 @@ functions:
455525
Returns a random number within the range provided.
456526
description: |
457527
When called without arguments, returns a uniform pseudo-random real number
458-
in the range of 0 to 1 (inclusive of 0 but exclusive of 1).
528+
in the range of `0` to `1` (inclusive of `0` but exclusive of `1`).
459529
460530
When called with an integer number `m`, returns a uniform pseudo-random
461-
integer in the range of 1 to `m`, inclusive.
531+
integer in the range of `1` to `m`, inclusive.
462532
463533
When called with two integer numbers `m` and `n`, returns a uniform
464534
pseudo-random integer in the range of `m` to `n`, inclusive.
@@ -502,12 +572,12 @@ functions:
502572
number.
503573
description: |
504574
Returns the integer with the smallest difference between it and the given
505-
number. For example, the value 5.8 returns 6.
575+
number. For example, the value `5.8` returns `6`.
506576
507-
For values like 0.5 that are equidistant to two integers, the value with
577+
For values like `0.5` that are equidistant to two integers, the value with
508578
the greater difference between it and zero is chosen. In other words, the
509-
function "rounds away from zero" such that 0.5 rounds to 1 and -0.5 rounds
510-
to -1.
579+
function "rounds away from zero" such that `0.5` rounds to `1` and `-0.5`
580+
rounds to `-1`.
511581
parameters:
512582
- name: x
513583
type: number
@@ -521,11 +591,11 @@ functions:
521591
code_samples:
522592
- name: math.sign
523593
summary: |
524-
Returns -1 if `x` is less than 0, 0 if `x` equals 0, or 1 if `x` is
525-
greater than 0.
594+
Returns `-1` if `x` is less than `0`, `0` if `x` equals `0`, or `1` if `x` is
595+
greater than `0`.
526596
description: |
527-
Returns -1 if `x` is less than 0, 0 if `x` equals 0, or 1 if `x` is
528-
greater than 0.
597+
Returns `-1` if `x` is less than `0`, `0` if `x` equals `0`, or `1` if `x` is
598+
greater than `0`.
529599
parameters:
530600
- name: x
531601
type: number

0 commit comments

Comments
 (0)