Skip to content

Commit

Permalink
Add some lerp helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Nov 15, 2024
1 parent 3b190db commit ebd1436
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ungerik/go3d/float64/bezier2"
"github.com/ungerik/go3d/float64/vec2"
"github.com/unitoftime/flow/glm"
"golang.org/x/exp/constraints"
)

// TODO: use https://easings.net/
Expand Down Expand Up @@ -193,6 +194,16 @@ func (i Lerp) Vec2(a, b glm.Vec2, t float64) glm.Vec2 {
return ret
}

// Linearly interpolates integers, rounding them to the nearest
func Int[T constraints.Integer](a, b T, t float64) T {
return T(math.Round(Linear.Float64(float64(a), float64(b), t)))
}

// Linearly interpolates floats
func Float[T constraints.Float](a, b T, t float64) T {
return T(Linear.Float64(float64(a), float64(b), t))
}

type Bezier struct {
bezier2.T
}
Expand Down

0 comments on commit ebd1436

Please sign in to comment.