Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clamp ¶
Clamp returns x clamped to the interval [min, max].
If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is returned.
Example ¶
package main
import (
"fmt"
doodlekitMath "github.com/lucasepe/doodlekit/internal/math"
)
func main() {
fmt.Println(doodlekitMath.Clamp(-5, 10, 10))
fmt.Println(doodlekitMath.Clamp(15, 10, 15))
fmt.Println(doodlekitMath.Clamp(25, 10, 20))
}
Output: 10 15 20
func Lerp ¶
Lerp does linear interpolation between two values.
Example ¶
package main
import (
"fmt"
doodlekitMath "github.com/lucasepe/doodlekit/internal/math"
)
func main() {
fmt.Println(doodlekitMath.Lerp(0, 2, 0.1))
fmt.Println(doodlekitMath.Lerp(1, 10, 0.5))
fmt.Println(doodlekitMath.Lerp(2, 4, 0.5))
}
Output: 0.2 5.5 3
func Sign ¶
Sign returns -1 for values < 0, 0 for 0, and 1 for values > 0.
Example ¶
package main
import (
"fmt"
doodlekitMath "github.com/lucasepe/doodlekit/internal/math"
)
func main() {
fmt.Println(doodlekitMath.Sign(-2))
fmt.Println(doodlekitMath.Sign(0))
fmt.Println(doodlekitMath.Sign(2))
}
Output: -1 0 1
func Trunc ¶
Trunc throws away the fraction digits
in := 1567.23456 out := Trunc(in, 1) fmt.Printf("%.6f\n", out) -> 1567.000000
in = 1.234567 out = Trunc(in, 0.01) fmt.Printf("%.6f\n", out) -> 1.230000
Example ¶
package main
import (
"fmt"
doodlekitMath "github.com/lucasepe/doodlekit/internal/math"
)
func main() {
fmt.Println(doodlekitMath.Trunc(1567.23456, 1))
fmt.Println(doodlekitMath.Trunc(1567.23456, 0.1))
fmt.Println(doodlekitMath.Trunc(1567.23456, 0.01))
fmt.Println(doodlekitMath.Trunc(1567.23456, 3))
}
Output: 1567 1567.2 1567.23 1566
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.