math

package
v0.0.0-...-9a4be88 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Math

Math types and utility functions.

V2

Basic Vector2 type with Scalar components. Methods never modify their caller.

V3

Same as V2, with the addition of a Z component.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp[T numeric](v, min, max T) T

func Max

func Max[T numeric](v, max T) T

func Min

func Min[T numeric](v, min T) T

@note: temporary until Go's builtin versions are released

Types

type Scalar

type Scalar = float64

Underlying type for all math data structures. Allows this package to use float32 or integer types if wanted.

const (
	Epsilon Scalar = 0.000001
)

type V2

type V2 struct {
	X Scalar
	Y Scalar
}

func V2Down

func V2Down() V2

Returns a Vector of [0, 1]

func V2Left

func V2Left() V2

Returns a Vector of [-1, 0]

func V2One

func V2One() V2

Returns a Vector of [1, 1]

func V2Right

func V2Right() V2

Returns a Vector of [1, 0]

func V2Up

func V2Up() V2

Returns a Vector of [0, -1]

func V2Zero

func V2Zero() V2

Returns a Vector of [0, 0]

Equivalent to

zero := V2{}

func (V2) Add

func (a V2) Add(b V2) V2

Adds 'b' to 'a'

func (V2) AngleTo

func (a V2) AngleTo(b V2) Scalar

Calculate angle from 'a' to 'b'

func (V2) Clamp

func (a V2) Clamp(min V2, max V2) V2

Clamp components of 'a' to be >= 'min' and <= 'max'.

func (V2) DistanceTo

func (a V2) DistanceTo(b V2) Scalar

Calculate the distance between 'a' and 'b'

func (V2) Div

func (a V2) Div(b V2) (c V2)

Divides 'a' by 'b'.

func (V2) Dot

func (a V2) Dot(b V2) Scalar

Calculate dot product of 'a' and 'b'

func (V2) Equals

func (a V2) Equals(b V2) bool

Check loose equality between 'a' and 'b'.

func (V2) Length

func (a V2) Length() Scalar

Calculate length (or magnitude) of 'a'

func (V2) Lerp

func (a V2) Lerp(b V2, t Scalar) (c V2)

Linear interpolate 'a' to 'b' via 't'.

func (V2) Mul

func (a V2) Mul(b V2) V2

Multiplies 'a' by 'b'

func (V2) Normalize

func (a V2) Normalize() (res V2)

Normalize 'a'

func (V2) Scale

func (a V2) Scale(amt Scalar) V2

Scale each component of 'a' by 'amt'

func (V2) Sub

func (a V2) Sub(b V2) V2

Subtracts 'b' from 'a'

func (V2) Trunc

func (a V2) Trunc() V2

Truncate each component of 'a'.

type V3

type V3 struct {
	X Scalar
	Y Scalar
	Z Scalar
}

func V3Down

func V3Down() V3

func V3Left

func V3Left() V3

func V3One

func V3One() V3

func V3Right

func V3Right() V3

func V3Up

func V3Up() V3

func V3Zero

func V3Zero() V3

func (V3) Add

func (a V3) Add(b V3) V3

func (V3) AngleTo

func (a V3) AngleTo(b V3) Scalar

func (V3) Clamp

func (a V3) Clamp(min V3, max V3) V3

func (V3) DistanceTo

func (a V3) DistanceTo(b V3) Scalar

func (V3) Div

func (a V3) Div(b V3) (c V3)

func (V3) Dot

func (a V3) Dot(b V3) Scalar

func (V3) Equals

func (a V3) Equals(b V3) bool

func (V3) Length

func (a V3) Length() Scalar

func (V3) Lerp

func (a V3) Lerp(b V3, t Scalar) (c V3)

func (V3) Mul

func (a V3) Mul(b V3) V3

func (V3) Normalize

func (a V3) Normalize() (res V3)

func (V3) Scale

func (a V3) Scale(amt Scalar) V3

func (V3) Sub

func (a V3) Sub(b V3) V3

func (V3) Trunc

func (a V3) Trunc() V3

Jump to

Keyboard shortcuts

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