math

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2024 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(x, min, max float64) float64

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 Deg

func Deg(rad float64) float64

func Lerp

func Lerp(a, b, t float64) float64

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 Rad

func Rad(deg float64) float64

func Sign

func Sign(x float64) float64

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

func Trunc(f float64, unit float64) float64

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

func Turn

func Turn(rad float64) float64

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL