gwg/vec
2
3
Fork
You've already forked vec
4

Add linear_interpolation and other math functions #1

Open
opened 2025年10月07日 12:51:30 +02:00 by renatillas · 6 comments

Working on the tiramisu game framwork I miss a function for lerping a vector like this:

pubfnlerp(a:Vec3,b:Vec3,t:Float)->Vec3{Vec3(a.x+.{b.x-.a.x}*.t,a.y+.{b.y-.a.y}*.t,a.z+.{b.z-.a.z}*.t,)}

Do you think it's sensible to add it to the library?

Working on the tiramisu game framwork I miss a function for lerping a vector like this: ```gleam pub fn lerp(a: Vec3, b: Vec3, t: Float) -> Vec3 { Vec3( a.x +. { b.x -. a.x } *. t, a.y +. { b.y -. a.y } *. t, a.z +. { b.z -. a.z } *. t, ) } ``` Do you think it's sensible to add it to the library?
Owner
Copy link

Ah yes, I was considered adding this function along with move_toward and sign but I'm not sure how...

Because all of these functions are all also useful to standard Float and Int type but none of them are in the stdlib (yet, maybe...).

If they are in the stdlib, it would be easy. We just need to add them like other functions in gleam/float and gleam/int to vec.

The sign function is in the gleam_comunity/maths lib, perhap we could make a PR to add lerp and move_toward to it, then make a subfoder vec/maths or a new lib vec_maths to house those functions and more.

Ah yes, I was considered adding this function along with [`move_toward`](https://docs.godotengine.org/en/stable/classes/class_vector3.html#class-vector3-method-move-toward) and [`sign`](https://docs.godotengine.org/en/stable/classes/class_vector3.html#class-vector3-method-sign) but I'm not sure how... Because all of these functions are all also useful to standard Float and Int type but none of them are in the `stdlib` (yet, maybe...). If they are in the `stdlib`, it would be easy. We just need to add them like other functions in `gleam/float` and `gleam/int` to `vec`. The `sign` function is in the `gleam_comunity/maths` lib, perhap we could make a PR to add `lerp` and `move_toward` to it, then make a subfoder `vec/maths` or a new lib `vec_maths` to house those functions and more.
Owner
Copy link

https://github.com/gleam-community/maths/issues/48

This will be added in the (削除) very near (削除ここまで) future.

https://github.com/gleam-community/maths/issues/48 This will be added in the ~~very near~~ future.
NNB changed title from (削除) Add lerp function (削除ここまで) to Add gleam_comunity/maths related functions 2025年10月14日 17:50:02 +02:00
NNB changed title from (削除) Add gleam_comunity/maths related functions (削除ここまで) to Add lerp function 2026年01月29日 18:56:59 +01:00
Owner
Copy link

I take it back, the gleam_comunity/maths is way too much T_T.

I take it back, the `gleam_comunity/maths` is way too much T_T.
Owner
Copy link

I'm thinking about adding map3 instead:

pubfnmap3(a:Vec3(a),b:Vec3(b),c:Vec3(c),withfun:fn(a,b,c)->d,)->Vec3(d){Vec3(fun(a.x,b.x,c.x),fun(a.y,b.y,c.y),fun(a.z,b.z,c.z))}

This will not only make using linear_interpolation easier but also other function that take 2 vectors and a weight/delta (with splash to turn a Float into a Vec(Float)). Like clamp, move_toward, inverse_linear_interpolation, ...

I'm thinking about adding `map3` instead: ```gleam pub fn map3( a: Vec3(a), b: Vec3(b), c: Vec3(c), with fun: fn(a, b, c) -> d, ) -> Vec3(d) { Vec3(fun(a.x, b.x, c.x), fun(a.y, b.y, c.y), fun(a.z, b.z, c.z)) } ``` This will not only make using `linear_interpolation` easier but also other function that take 2 vectors and a weight/delta (with `splash` to turn a Float into a `Vec(Float)`). Like `clamp`, `move_toward`, `inverse_linear_interpolation`, ...
NNB changed title from (削除) Add lerp function (削除ここまで) to Add linear_interpolation functions 2026年01月30日 15:46:07 +01:00
Owner
Copy link

Year I'm in favor of map3 over making functions from or could be from maths lib to Vec. Since I find linear_interpolation is quite rare to use, not "never", just rare. So if someone want to use it 1 or 2 time in a project, using map3 is fine.

If anyone feel different, please reopen this issue, and add the reason.

Year I'm in favor of `map3` over making functions from or could be from `maths` lib to Vec. Since I find `linear_interpolation` is quite rare to use, not "never", just rare. So if someone want to use it 1 or 2 time in a project, using `map3` is fine. If anyone feel different, please reopen this issue, and add the reason.
Owner
Copy link

This is back on the table now!

This is back on the table now!
NNB changed title from (削除) Add linear_interpolation functions (削除ここまで) to Add linear_interpolation and other math functions 2026年02月16日 17:03:55 +01:00
Sign in to join this conversation.
No Branch/Tag specified
main
v4.1.0
v4.0.0
v3.5.1
v3.5.0
v3.4.0
v3.3.0
v3.2.1
v3.2.0
v3.1.0
v3.0.3
v3.0.2
v3.0.1
v3.0.0
v2.0.0
v1.4.0
v1.3.5
v1.3.4
v1.3.3
v1.3.2
v1.3.1
v1.3.0
v1.2.0
v1.1.0
v1.0.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
gwg/vec#1
Reference in a new issue
gwg/vec
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?