Skip to content

Commit 159794d

Browse files
authored
Add math.lerp, and math.map
1 parent 741b144 commit 159794d

File tree

1 file changed

+82
-0
lines changed
  • content/en-us/reference/engine/libraries

1 file changed

+82
-0
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,42 @@ 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+
When `t` is 0, the function returns `a`, and when `t` is 1, it returns `b`. For
290+
values of `t` between 0 and 1, the function computes a proportional blend between
291+
the two values.
292+
293+
The interpolation is calculated using the formula:
294+
295+
```
296+
a + (b - a) * t
297+
```
298+
parameters:
299+
- name: a
300+
type: number
301+
default:
302+
summary: |
303+
The starting value.
304+
- name: b
305+
type: number
306+
default:
307+
summary: |
308+
The ending value.
309+
- name: t
310+
type: number
311+
default:
312+
summary: |
313+
The interpolation factor, typically between 0 and 1.
314+
returns:
315+
- type: number
316+
summary: |
317+
The interpolated value between `a` and `b`.
318+
tags:
319+
code_samples:
284320
- name: math.log
285321
summary: |
286322
Returns the logarithm of `x` using the given base.
@@ -317,6 +353,52 @@ functions:
317353
summary: ''
318354
tags:
319355
code_samples:
356+
- name: math.map
357+
summary: |
358+
Returns the value of `x` mapped from one range to another.
359+
description: |
360+
Returns a value that represents `x` mapped linearly from the input range
361+
[`inmin`, `inmax`] to the output range [`outmin`, `outmax`]. This is achieved
362+
by determining the relative position of `x` within the input range and applying
363+
that ratio to the output range.
364+
365+
The mapping is calculated using the formula:
366+
367+
```
368+
outmin + ((x - inmin) / (inmax - inmin)) * (outmax - outmin)
369+
```
370+
parameters:
371+
- name: x
372+
type: number
373+
default:
374+
summary: |
375+
The number to be mapped.
376+
- name: inmin
377+
type: number
378+
default:
379+
summary: |
380+
The lower bound of the input range.
381+
- name: inmax
382+
type: number
383+
default:
384+
summary: |
385+
The upper bound of the input range.
386+
- name: outmin
387+
type: number
388+
default:
389+
summary: |
390+
The lower bound of the output range.
391+
- name: outmax
392+
type: number
393+
default:
394+
summary: |
395+
The upper bound of the output range.
396+
returns:
397+
- type: number
398+
summary: |
399+
The value of `x` mapped to the output range.
400+
tags:
401+
code_samples:
320402
- name: math.max
321403
summary: |
322404
Returns the maximum value among the numbers passed to the function.

0 commit comments

Comments
 (0)