mathf

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Apache-2.0 Imports: 7 Imported by: 2

README

Mathf - Mathematical Utilities for Go

Language GoDoc

A comprehensive mathematical utility library for Go, providing implementations of common geometric types and operations. This library is designed to be efficient, easy to use, and suitable for game development and graphics applications.

Features

  • Vector Types

    • Vector2, Vector2i - 2D vectors (float and integer)
    • Vector3, Vector3i - 3D vectors (float and integer)
    • Vector4, Vector4i - 4D vectors (float and integer)
  • Rectangle Types

    • Rect2, Rect2i - 2D rectangles (float and integer)
    • AABB - Axis-Aligned Bounding Box
  • Quaternion

    • Full quaternion implementation for 3D rotations

Installation

go get github.com/goplus/spbase/mathf

Usage

Vectors
import "github.com/goplus/spbase/mathf"

// Create vectors
v1 := mathf.NewVector2(1.0, 2.0)
v2 := mathf.NewVector2i(1, 2)

// Basic operations
sum := v1.Add(v2)
diff := v1.Sub(v2)
scaled := v1.Mul(2.0)

// Vector operations
dot := v1.Dot(v2)
length := v1.Length()
normalized := v1.Normalized()
Rectangles
import "github.com/goplus/spbase/mathf"

// Create rectangles
rect := mathf.NewRect2(0, 0, 100, 100)  // x, y, width, height
rect2 := mathf.NewRect2i(0, 0, 100, 100)

// Check if point is inside
point := mathf.NewVector2(50, 50)
isInside := rect.HasPoint(point)

// Rectangle operations
intersection := rect.Intersection(rect2)
merged := rect.Merge(rect2)
grown := rect.Grow(10)
Quaternions
import "github.com/goplus/spbase/mathf"

// Create quaternion
q := mathf.NewQuaternion(x, y, z, w)

// Operations
rotated := q.Rotate(vector)
inverse := q.Inverse()

Testing

The library includes comprehensive test coverage. Run the tests using:

go test ./...

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Apache License 2.0

Acknowledgments

This library is inspired by Godot Engine's math utilities and the awesome library: xy, and designed to provide similar functionality in Go.

Documentation

Index

Constants

View Source
const (
	Pi  = math.Pi
	Tau = math.Pi * 2
)

Variables

This section is empty.

Functions

func Absf

func Absf[T ~float32 | ~float64](x T) T

Absf returns the absolute value of the float parameter x (i.e. non-negative value).

func Absi

func Absi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Absi returns the absolute value of the integer parameter x (i.e. non-negative value).

func Acos

func Acos[T ~float32 | ~float64](x T) float64

Acos returns the arc cosine of x in float64. Use to get the angle of cosine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent acos from returning NaN.

func Acosh

func Acosh[T ~float32 | ~float64](x T) float64

Acosh returns the hyperbolic arc (also called inverse) cosine of x, returning a value in float64. Use it to get the angle from an angle's cosine in hyperbolic space if x is larger or equal to 1. For values of x lower than 1, it will return 0, in order to prevent acosh from returning NaN.

func AngleDifference

func AngleDifference[T ~float32 | ~float64](from, to T) T

AngleDifference returns the difference between the two angles, in the range of [-Pi, +Pi]. When from and to are opposite, returns -Pi if from is smaller than to, or Pi otherwise.

func Asin

func Asin[T ~float32 | ~float64](x T) float64

Asin returns the arc sine of x in float64. Use to get the angle of sine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent asin from returning NaN.

func Asinh

func Asinh[T ~float32 | ~float64](x T) float64

Asinh returns the hyperbolic arc (also called inverse) sine of x, returning a value in float64. Use it to get the angle from an angle's sine in hyperbolic space.

func Atan

func Atan[T ~float32 | ~float64](x T) float64

Atan returns the arc tangent of x in float64. Use it to get the angle from an angle's tangent in trigonometry. The method cannot know in which quadrant the angle should fall. See atan2 if you have both y and x.

func Atan2

func Atan2[T ~float32 | ~float64](y, x T) float64

Atan2 returns the arc tangent of y/x in float64. Use to get the angle of tangent y/x. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.

Important note: The Y coordinate comes first, by convention.

func Atanh

func Atanh[T ~float32 | ~float64](x T) float64

Atanh returns the hyperbolic arc (also called inverse) tangent of x, returning a value in float64. Use it to get the angle from an angle's tangent in hyperbolic space if x is between -1 and 1 (non-inclusive).

In mathematics, the inverse hyperbolic tangent is only defined for -1 < x < 1 in the real set, so values equal or lower to -1 for x return -INF and values equal or higher than 1 return +INF in order to prevent atanh from returning NaN.

func BezierDerivative

func BezierDerivative[T ~float32 | ~float64](start, control_1, control_2, end, t T) T

BezierDerivative returns the derivative at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

func BezierInterpolate

func BezierInterpolate[T ~float32 | ~float64](start, control_1, control_2, end, t T) T

BezierInterpolate returns the point at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.

func Ceilf

func Ceilf[T ~float32 | ~float64](x T) T

Ceilf rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.

func Ceili

func Ceili[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Ceili rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.

func Clamp

func Clamp[T ordered](value, min, max T) T

Clamp clamps the value, returning a Variant not less than min and not more than max. Any values that can be compared with the less than and greater than operators will work.

func Clamp01f

func Clamp01f[T ~float32 | ~float64](value T) T

func Clamp01i

func Clamp01i[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value T) T

func Clampf

func Clampf[T ~float32 | ~float64](value, min, max T) T

Clampf clamps the value, returning a float not less than min and not more than max.

func Clampi

func Clampi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T

Clampi clamps the value, returning an integer not less than min and not more than max.

func Cos

func Cos[T ~float32 | ~float64](x T) T

Cos returns the cosine of angle x in float64.

func Cosh

func Cosh[T ~float32 | ~float64](x T) T

Cosh returns the hyperbolic cosine of x in float64.

func CubicInterpolate

func CubicInterpolate[T ~float32 | ~float64](from, to, pre, post, weight T) T

CubicInterpolate cubic interpolates between two values by the factor defined in weightSee also with pre and post values.

func CubicInterpolateAngle

func CubicInterpolateAngle[T ~float32 | ~float64](from, to, pre, post, weight T) T

CubicInterpolateAngle cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also LerpAngle.

func DecibelsToLinear

func DecibelsToLinear[T ~float32 | ~float64](db T) T

DecibelsToLinear converts from decibels to linear energy (audio).

func Ease

func Ease[T ~float32 | ~float64](x, curve T) T

Ease returns an "eased" value of x based on an easing function defined with curve. This easing function is based on an exponent. The curve can be any floating-point number, with specific values leading to the following behaviors:

- Lower than -1.0 (exclusive): Ease in-out - 1.0: Linear - Between -1.0 and 0.0 (exclusive): Ease out-in - 0.0: Constant - Between 0.0 to 1.0 (exclusive): Ease out - 1.0: Linear - Greater than 1.0 (exclusive): Ease in

https://raw.githubusercontent.com/godotengine/godot-docs/master/img/ease_cheatsheet.png

See also Smoothstep. If you need to perform more advanced transitions, use [Tween.InterpolateValue].

func Exp

func Exp[T ~float32 | ~float64](x T) T

Exp raises the mathematical constant e to the power of x and returns it. e has an approximate value of 2.71828, and can be obtained with Exp(1).

For exponents to other bases use the method pow.

func Floorf

func Floorf[T ~float32 | ~float64](x T) T

Floorf rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.

func Floori

func Floori[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Floori rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.

func Fmod

func Fmod[T ~float32 | ~float64](x, y T) T

Fmod returns the floating-point remainder of x divided by y, keeping the sign of x.

func Fposmod

func Fposmod[T ~float32 | ~float64](x, y T) T

Fposmod returns the floating-point modulus of x divided by y, wrapping equally in positive and negative.

func InverseLerp

func InverseLerp[T ~float32 | ~float64](from, to, weight T) T

InverseLerp returns an interpolation or extrapolation factor considering the range specified in from and to, and the interpolated value specified in weight. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive). If weight is located outside this range, then an extrapolation factor will be returned (return value lower than 0.0 or greater than 1.0). Use Clamp on the result of InverseLerp if this is not desired.

func IsApproximatelyEqual

func IsApproximatelyEqual[T ~float32 | ~float64](a, b T) bool

IsApproximatelyEqual returns true if a and b are approximately equal to each other.

Here, "approximately equal" means that a and b are within a small internal epsilon of each other, which scales with the magnitude of the numbers.

Infinity values of the same sign are considered equal.

func IsApproximatelyZero

func IsApproximatelyZero[T ~float32 | ~float64](x T) bool

IsApproximatelyZero Returns true if x is zero or almost zero. The comparison is done using a tolerance calculation with a small internal epsilon. This function is faster than using IsApproximatelyEqual with one value as zero.

func IsFinite

func IsFinite[T ~float32 | ~float64](x T) bool

IsFinite returns whether x is a finite value, i.e. it is not NaN, +INF, or -INF.

func IsInfinity

func IsInfinity[T ~float32 | ~float64](x T) bool

IsInfinity returns whether x is an infinite value, i.e. it is +INF or -INF.

func IsNaN

func IsNaN[T ~float32 | ~float64](x T) bool

IsNaN returns whether x is NaN (not a number).

func LerpAngle

func LerpAngle[T ~float32 | ~float64](from, to, weight T) T

LerpAngle linearly interpolates between two angles (in float64) by a weight value between 0.0 and 1.0. Similar to lerp, but interpolates correctly when the angles wrap around Tau. To perform eased interpolation with LerpAngle, combine it with Ease or Smoothstep.

Note: This function lerps through the shortest path between from and to. However, when these two angles are approximately Pi + k * Tau apart for any integer k, it's not obvious which way they lerp due to floating-point precision errors. For example, LerpAngle(0, Pi, weight) lerps counter-clockwise, while LerpAngle(0, Pi + 5 * Tau, weight) lerps clockwise.

func Lerpf

func Lerpf[T ~float32 | ~float64](from, to, weight T) T

Lerpf linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use Clampf on the result of this function.

See also InverseLerp which performs the reverse of this operation. To perform eased interpolation with Lerpf, combine it with ease or smoothstep.

func LinearToDecibels

func LinearToDecibels[T ~float32 | ~float64](energy T) T

LinearToDecibels converts from linear energy (audio) to decibels.

func Log

func Log[T ~float32 | ~float64](x T) T

Log returns the natural logarithm of x (base e, with e being approximately 2.71828). This is the amount of time needed to reach a certain level of continuous growth.

Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm. To use base 10 logarithm, use Log(x) / Log(10).

Note: The logarithm of 0 returns -inf, while negative values return -NaN.

func MoveToward

func MoveToward[T ~float32 | ~float64](from, to, delta T) T

MoveToward moves from toward to by the delta amount. Will not go past to. Use a negative delta value to move away.

func NearestPowerOfTwo

func NearestPowerOfTwo(x int64) int64

NearestPowerOfTwo returns the nearest power of two to the given value.

Warning: Due to its implementation, this method returns 0 rather than 1 for values less than or equal to 0, with an exception for value being the smallest negative 64-bit integer (-9223372036854775808) in which case the value is returned unchanged.

func PingPong

func PingPong[T ~float32 | ~float64](value, length T) T

PingPong wraps value between 0 and the length. If the limit is reached, the next value the function returns is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.

func Posmod

func Posmod[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x, y T) T

Posmod returns the integer modulus of x divided by y that wraps equally in positive and negative.

func Pow

func Pow[T ~float32 | ~float64](base, exp T) T

Pow returns the result of base raised to the power of exp.

func Remap

func Remap[T ~float32 | ~float64](value, istart, istop, ostart, ostop T) T

Remap maps a value from range (istart, istop) to (ostart, ostop). See also [Lerp] and InverseLerp. If value is outside (istart, istop), then the resulting value will also be outside (ostart, ostop). If this is not desired, use Clamp on the result of this function.

func Roundf

func Roundf[T ~float32 | ~float64](x T) T

Roundf rounds x to the nearest whole number, with halfway cases rounded away from 0.

func Roundi

func Roundi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Roundi rounds x to the nearest whole number, with halfway cases rounded away from 0.

func Signf

func Signf[T ~float32 | ~float64](x T) T

Signf returns -1.0 if x is negative, 1.0 if x is positive, and 0.0 if x is zero. For NaN values of x it returns 0.0.

func Signi

func Signi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x T) T

Signi returns -1 if x is negative, 1 if x is positive, and 0 if x is zero. For NaN values of x it returns 0.

func Sin

func Sin[T ~float32 | ~float64](x T) T

Sin returns the sine of angle x in float64.

func Sinh

func Sinh[T ~float32 | ~float64](x T) T

Sinh returns the hyperbolic sine of x in float64.

func Smoothstep

func Smoothstep[T ~float32 | ~float64](from, to, x T) T

Smoothstep returns the result of smoothly interpolating the value of x between 0 and 1, based on the where x lies with respect to the edges from and to.

The return value is 0 if x <= from, and 1 if x >= to. If x lies between from and to, the returned value follows an S-shaped curve that maps x between 0 and 1.

This S-shaped curve is the cubic Hermite interpolator, given by

(y) = 3*y^2 - 2*y^3 where y = (x-from) / (to-from).

func Snappedf

func Snappedf[T ~float32 | ~float64](x, step T) T

Snappedf returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.

func Snappedi

func Snappedi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](x, step T) T

Snappedi returns the multiple of step that is the closest to x. This can also be used to round a floating point number to an arbitrary number of decimals.

func Sqrt

func Sqrt[T ~float32 | ~float64](x T) T

Sqrt returns the square root of x. Where x is negative, the result is NaN.

func StepDecimals

func StepDecimals[T ~float32 | ~float64](x T) int64

StepDecimals returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.

func Tan

func Tan[T ~float32 | ~float64](x T) T

Tan returns the tangent of angle x in float64.

func Tanh

func Tanh[T ~float32 | ~float64](x T) T

Tanh returns the hyperbolic tangent of x in float64.

func Wrapf

func Wrapf[T ~float32 | ~float64](value, min, max T) T

Wrapf value between min and max. Can be used for creating loop-alike behavior or infinite surfaces.

func Wrapi

func Wrapi[T ~int8 | ~int16 | ~int32 | ~int64 | ~int](value, min, max T) T

Wrapi value between min and max. Can be used for creating loop-alike behavior or infinite surfaces.

Types

type AABB

type AABB struct {
	Position Vec3
	Size     Vec3
}

func (AABB) String

func (a AABB) String() string

type Color

type Color struct {
	R, G, B, A float64
}

func ColorBlack

func ColorBlack() Color

func ColorBlue

func ColorBlue() Color

func ColorCyan

func ColorCyan() Color

func ColorGreen

func ColorGreen() Color

func ColorMagenta

func ColorMagenta() Color

func ColorRed

func ColorRed() Color

func ColorTransparent

func ColorTransparent() Color

func ColorWhite

func ColorWhite() Color

func ColorYellow

func ColorYellow() Color

func LerpColor

func LerpColor(from Color, to Color, t float64) Color

func NewColor

func NewColor(r, g, b, a float64) Color

func NewColorAny

func NewColorAny(s interface{}) (Color, error)

New a color, s can be int, float64 or string

func NewColorHSV

func NewColorHSV(h, s, v float64) Color

func NewColorRGB

func NewColorRGB(r, g, b float64) Color

func NewColorRGBA

func NewColorRGBA(r, g, b, a float64) Color

func NewColorRGBAi

func NewColorRGBAi(r, g, b, a uint8) Color

func NewColorRGBi

func NewColorRGBi(r, g, b uint8) Color

func RandomColor

func RandomColor() Color

Random returns a random color.

func (Color) Add

func (c Color) Add(other Color) Color

func (Color) Clamp

func (c Color) Clamp() Color

func (*Color) FromHSV

func (c *Color) FromHSV(h, s, v float64)

HSV2RGB converts hue (0-360), saturation (0-1), and brightness (0-1) to RGB.

func (Color) Invert

func (c Color) Invert() Color

func (Color) Lerp

func (c Color) Lerp(to Color, t float64) Color

func (Color) Mul

func (c Color) Mul(other Color) Color

func (Color) Mulf

func (c Color) Mulf(f float64) Color

func (*Color) ScaleBrightness

func (c *Color) ScaleBrightness(scale float64)

ScaleBrightness changes color brightness.

func (Color) String

func (val Color) String() string

func (Color) Sub

func (c Color) Sub(other Color) Color

func (*Color) ToHSV

func (c *Color) ToHSV() (h, s, v float64)

RGB2HSV converts RGB to an array containing the hue, saturation, and brightness.

type Float

type Float = float64

type Int

type Int = int32

type Matrix3

type Matrix3 [9]Float

func NewMatrix3Indentity

func NewMatrix3Indentity() *Matrix3

func NewMatrix3Zero

func NewMatrix3Zero() *Matrix3

func (*Matrix3) Add

func (pself *Matrix3) Add(otherMat *Matrix3) *Matrix3

func (*Matrix3) Addf

func (pself *Matrix3) Addf(value float64) *Matrix3

func (*Matrix3) Clone

func (pself *Matrix3) Clone() *Matrix3

func (*Matrix3) Div

func (pself *Matrix3) Div(otherMat *Matrix3) *Matrix3

func (*Matrix3) Divf

func (pself *Matrix3) Divf(value float64) *Matrix3

func (*Matrix3) Equals

func (pself *Matrix3) Equals(otherMat *Matrix3) bool

func (*Matrix3) Get

func (pself *Matrix3) Get(row int, col int) float64

func (*Matrix3) Mul

func (pself *Matrix3) Mul(value Matrix3) *Matrix3

func (*Matrix3) Mulv

func (pself *Matrix3) Mulv(value Vec2) Vec2

func (*Matrix3) Scale

func (pself *Matrix3) Scale(otherMat *Matrix3) *Matrix3

func (*Matrix3) Scalef

func (pself *Matrix3) Scalef(value float64) *Matrix3

func (*Matrix3) Set

func (pself *Matrix3) Set(row int, col int, value float64)

func (*Matrix3) String

func (pself *Matrix3) String() string

func (*Matrix3) Sub

func (pself *Matrix3) Sub(otherMat *Matrix3) *Matrix3

func (*Matrix3) Subf

func (pself *Matrix3) Subf(value float64) *Matrix3

type Quaternion

type Quaternion struct {
	X, Y, Z, W Float
}

func NewQuaternion

func NewQuaternion(x, y, z, w float64) Quaternion

func NewQuaternionFromAxisAngle

func NewQuaternionFromAxisAngle(axis Vec3, angle float64) Quaternion

func (Quaternion) Add

func (q Quaternion) Add(other Quaternion) Quaternion

func (Quaternion) Conjugate

func (q Quaternion) Conjugate() Quaternion

func (Quaternion) Dot

func (q Quaternion) Dot(other Quaternion) float64

func (Quaternion) GetEuler

func (q Quaternion) GetEuler() Vec3

func (Quaternion) Inverse

func (q Quaternion) Inverse() Quaternion

func (Quaternion) IsFinite

func (q Quaternion) IsFinite() bool

func (Quaternion) IsNormalized

func (q Quaternion) IsNormalized() bool

func (Quaternion) Length

func (q Quaternion) Length() float64

func (Quaternion) LengthSquared

func (q Quaternion) LengthSquared() float64

func (Quaternion) Lerp

func (q Quaternion) Lerp(to Quaternion, weight float64) Quaternion

func (Quaternion) Lerpf

func (q Quaternion) Lerpf(to Quaternion, weight float64) Quaternion

func (Quaternion) Mul

func (q Quaternion) Mul(other Quaternion) Quaternion

func (Quaternion) Mulf

func (q Quaternion) Mulf(f float64) Quaternion

func (Quaternion) Neg

func (q Quaternion) Neg() Quaternion

func (Quaternion) Normalize

func (q Quaternion) Normalize() Quaternion

func (Quaternion) RotateVec3

func (q Quaternion) RotateVec3(v Vec3) Vec3

func (Quaternion) Slerp

func (q Quaternion) Slerp(to Quaternion, weight float64) Quaternion

func (Quaternion) Slerpf

func (q Quaternion) Slerpf(to Quaternion, weight float64) Quaternion

func (Quaternion) String

func (q Quaternion) String() string

func (Quaternion) Sub

func (q Quaternion) Sub(other Quaternion) Quaternion

type Rect2

type Rect2 struct {
	Position Vec2
	Size     Vec2
}

func NewRect2

func NewRect2(x, y, w, h float64) Rect2

func (Rect2) Abs

func (r Rect2) Abs() Rect2

func (Rect2) Area

func (r Rect2) Area() float64

func (Rect2) Center

func (r Rect2) Center() Vec2

func (Rect2) Encloses

func (r Rect2) Encloses(b Rect2) bool

func (*Rect2) End

func (r *Rect2) End() Vec2

func (Rect2) Expand

func (r Rect2) Expand(to Vec2) Rect2

func (Rect2) Grow

func (r Rect2) Grow(amount float64) Rect2

func (Rect2) GrowIndividual

func (r Rect2) GrowIndividual(left, top, right, bottom float64) Rect2

func (Rect2) GrowSide

func (r Rect2) GrowSide(side Side, amount float64) Rect2

func (Rect2) HasArea

func (r Rect2) HasArea() bool

func (Rect2) HasPoint

func (r Rect2) HasPoint(point Vec2) bool

func (Rect2) Intersection

func (r Rect2) Intersection(b Rect2) Rect2

func (Rect2) Intersects

func (r Rect2) Intersects(b Rect2, includeBorders bool) bool

func (Rect2) Merge

func (r Rect2) Merge(b Rect2) Rect2

func (Rect2) Rect2i

func (r Rect2) Rect2i() Rect2i

func (*Rect2) SetEnd

func (r *Rect2) SetEnd(end Vec2)

func (Rect2) String

func (r Rect2) String() string

type Rect2i

type Rect2i struct {
	Position Vec2i
	Size     Vec2i
}

func NewRect2i

func NewRect2i(x, y, w, h int) Rect2i

func (*Rect2i) Abs

func (r *Rect2i) Abs() Rect2i

func (*Rect2i) Area

func (r *Rect2i) Area() int64

func (*Rect2i) Center

func (r *Rect2i) Center() Vec2i

func (*Rect2i) Encloses

func (r *Rect2i) Encloses(b Rect2i) bool

func (*Rect2i) End

func (r *Rect2i) End() Vec2i

func (*Rect2i) Expand

func (r *Rect2i) Expand(to Vec2i) Rect2i

func (*Rect2i) Grow

func (r *Rect2i) Grow(amount int64) Rect2i

func (*Rect2i) GrowIndividual

func (r *Rect2i) GrowIndividual(left, top, right, bottom int64) Rect2i

func (*Rect2i) GrowSide

func (r *Rect2i) GrowSide(side Side, amount int64) Rect2i

func (*Rect2i) HasArea

func (r *Rect2i) HasArea() bool

func (*Rect2i) HasPoint

func (r *Rect2i) HasPoint(point Vec2i) bool

func (*Rect2i) Intersection

func (r *Rect2i) Intersection(b Rect2i) Rect2i

func (*Rect2i) Intersects

func (r *Rect2i) Intersects(b Rect2i, includeBorders bool) bool

func (*Rect2i) Merge

func (r *Rect2i) Merge(b Rect2i) Rect2i

func (*Rect2i) Rect2

func (r *Rect2i) Rect2() Rect2

func (*Rect2i) SetEnd

func (r *Rect2i) SetEnd(end Vec2i)

func (Rect2i) String

func (r Rect2i) String() string

type Side

type Side = impl.Side
const (
	SideLeft   Side = 0
	SideTop    Side = 1
	SideRight  Side = 2
	SideBottom Side = 3
)

type Vec2

type Vec2 struct {
	X, Y Float
}

func NewVec2

func NewVec2(x, y float64) Vec2

func (Vec2) Abs

func (v Vec2) Abs() Vec2

func (Vec2) Add

func (v Vec2) Add(other Vec2) Vec2

func (Vec2) Addf

func (v Vec2) Addf(f float64) Vec2

func (Vec2) Ceil

func (v Vec2) Ceil() Vec2

func (Vec2) Clamp

func (v Vec2) Clamp(min, max Vec2) Vec2

func (Vec2) Cross

func (v Vec2) Cross(other Vec2) float64

func (Vec2) DistanceSquaredTo

func (v Vec2) DistanceSquaredTo(other Vec2) float64

func (Vec2) DistanceTo

func (v Vec2) DistanceTo(other Vec2) float64

func (Vec2) Div

func (v Vec2) Div(other Vec2) Vec2

func (Vec2) Divf

func (v Vec2) Divf(f float64) Vec2

func (Vec2) Dot

func (v Vec2) Dot(other Vec2) float64

func (Vec2) Floor

func (v Vec2) Floor() Vec2

func (Vec2) IsApproximatelyZero

func (v Vec2) IsApproximatelyZero() bool

func (Vec2) IsFinite

func (v Vec2) IsFinite() bool

func (Vec2) IsNormalized

func (v Vec2) IsNormalized() bool

func (Vec2) Length

func (v Vec2) Length() float64

func (Vec2) LengthSquared

func (v Vec2) LengthSquared() float64

func (Vec2) Lerp

func (v Vec2) Lerp(to Vec2, weight float64) Vec2

func (Vec2) Lerpf

func (v Vec2) Lerpf(to Vec2, weight float64) Vec2

func (Vec2) Mul

func (v Vec2) Mul(other Vec2) Vec2

func (Vec2) Mulf

func (v Vec2) Mulf(f float64) Vec2

func (Vec2) Neg

func (v Vec2) Neg() Vec2

func (Vec2) Normalize

func (v Vec2) Normalize() Vec2

func (Vec2) Round

func (v Vec2) Round() Vec2

func (Vec2) Sign

func (v Vec2) Sign() Vec2

func (Vec2) String

func (v Vec2) String() string

func (Vec2) Sub

func (v Vec2) Sub(other Vec2) Vec2

func (Vec2) Subf

func (v Vec2) Subf(f float64) Vec2

type Vec2i

type Vec2i struct {
	X, Y Int
}

func NewVec2i

func NewVec2i(x, y int) Vec2i

func (Vec2i) Abs

func (v Vec2i) Abs() Vec2i

func (Vec2i) Add

func (v Vec2i) Add(other Vec2i) Vec2i

func (Vec2i) Addi

func (v Vec2i) Addi(i int) Vec2i

func (Vec2i) Clamp

func (v Vec2i) Clamp(min, max Vec2i) Vec2i

func (Vec2i) DistanceSquaredTo

func (v Vec2i) DistanceSquaredTo(other Vec2i) float64

func (Vec2i) DistanceTo

func (v Vec2i) DistanceTo(other Vec2i) float64

func (Vec2i) Div

func (v Vec2i) Div(other Vec2i) Vec2i

func (Vec2i) Divi

func (v Vec2i) Divi(i int) Vec2i

func (Vec2i) Dot

func (v Vec2i) Dot(other Vec2i) float64

func (Vec2i) Length

func (v Vec2i) Length() float64

func (Vec2i) LengthSquared

func (v Vec2i) LengthSquared() float64

func (Vec2i) Mul

func (v Vec2i) Mul(other Vec2i) Vec2i

func (Vec2i) Muli

func (v Vec2i) Muli(i int) Vec2i

func (Vec2i) Neg

func (v Vec2i) Neg() Vec2i

func (Vec2i) Sign

func (v Vec2i) Sign() Vec2i

func (Vec2i) String

func (v Vec2i) String() string

func (Vec2i) Sub

func (v Vec2i) Sub(other Vec2i) Vec2i

func (Vec2i) Subi

func (v Vec2i) Subi(i int) Vec2i

type Vec3

type Vec3 struct {
	X, Y, Z Float
}

func NewVec3

func NewVec3(x, y, z float64) Vec3

func NewVec3FromImpl

func NewVec3FromImpl(iv impl.Vector3) Vec3

func (*Vec3) Abs

func (v *Vec3) Abs() Vec3

func (*Vec3) Add

func (v *Vec3) Add(other Vec3) Vec3

func (*Vec3) Addf

func (v *Vec3) Addf(f float64) Vec3

func (*Vec3) Ceil

func (v *Vec3) Ceil() Vec3

func (*Vec3) Clamp

func (v *Vec3) Clamp(min, max Vec3) Vec3

func (*Vec3) Cross

func (v *Vec3) Cross(other Vec3) Vec3

func (*Vec3) DistanceSquaredTo

func (v *Vec3) DistanceSquaredTo(other Vec3) float64

func (*Vec3) DistanceTo

func (v *Vec3) DistanceTo(other Vec3) float64

func (*Vec3) Div

func (v *Vec3) Div(other Vec3) Vec3

func (*Vec3) Divf

func (v *Vec3) Divf(f float64) Vec3

func (*Vec3) Dot

func (v *Vec3) Dot(other Vec3) float64

func (*Vec3) Floor

func (v *Vec3) Floor() Vec3

func (*Vec3) IsApproximatelyZero

func (v *Vec3) IsApproximatelyZero() bool

func (*Vec3) IsFinite

func (v *Vec3) IsFinite() bool

func (*Vec3) IsNormalized

func (v *Vec3) IsNormalized() bool

func (*Vec3) Length

func (v *Vec3) Length() float64

func (*Vec3) LengthSquared

func (v *Vec3) LengthSquared() float64

func (*Vec3) Lerp

func (v *Vec3) Lerp(to Vec3, weight float64) Vec3

func (*Vec3) Lerpf

func (v *Vec3) Lerpf(to Vec3, weight float64) Vec3

func (*Vec3) Mul

func (v *Vec3) Mul(other Vec3) Vec3

func (*Vec3) Mulf

func (v *Vec3) Mulf(f float64) Vec3

func (*Vec3) Neg

func (v *Vec3) Neg() Vec3

func (*Vec3) Normalize

func (v *Vec3) Normalize() Vec3

func (*Vec3) Round

func (v *Vec3) Round() Vec3

func (Vec3) String

func (v Vec3) String() string

func (*Vec3) Sub

func (v *Vec3) Sub(other Vec3) Vec3

func (*Vec3) Subf

func (v *Vec3) Subf(f float64) Vec3

type Vec3i

type Vec3i struct {
	X, Y, Z Int
}

func NewVec3i

func NewVec3i(x, y, z int) Vec3i

func (Vec3i) Abs

func (v Vec3i) Abs() Vec3i

func (Vec3i) Add

func (v Vec3i) Add(other Vec3i) Vec3i

func (Vec3i) Addi

func (v Vec3i) Addi(i int) Vec3i

func (Vec3i) Clamp

func (v Vec3i) Clamp(min, max Vec3i) Vec3i

func (Vec3i) Cross

func (v Vec3i) Cross(other Vec3i) Vec3i

func (Vec3i) DistanceSquaredTo

func (v Vec3i) DistanceSquaredTo(other Vec3i) float64

func (Vec3i) DistanceTo

func (v Vec3i) DistanceTo(other Vec3i) float64

func (Vec3i) Div

func (v Vec3i) Div(other Vec3i) Vec3i

func (Vec3i) Divi

func (v Vec3i) Divi(i int) Vec3i

func (Vec3i) Dot

func (v Vec3i) Dot(other Vec3i) float64

func (Vec3i) Length

func (v Vec3i) Length() float64

func (Vec3i) LengthSquared

func (v Vec3i) LengthSquared() float64

func (Vec3i) Mul

func (v Vec3i) Mul(other Vec3i) Vec3i

func (Vec3i) Muli

func (v Vec3i) Muli(i int) Vec3i

func (Vec3i) Neg

func (v Vec3i) Neg() Vec3i

func (Vec3i) Sign

func (v Vec3i) Sign() Vec3i

func (Vec3i) String

func (v Vec3i) String() string

func (Vec3i) Sub

func (v Vec3i) Sub(other Vec3i) Vec3i

func (Vec3i) Subi

func (v Vec3i) Subi(i int) Vec3i

type Vec4

type Vec4 struct {
	X, Y, Z, W Float
}

func NewVec4

func NewVec4(x, y, z, w float64) Vec4

func (*Vec4) Abs

func (v *Vec4) Abs() Vec4

func (*Vec4) Add

func (v *Vec4) Add(other Vec4) Vec4

func (*Vec4) Addf

func (v *Vec4) Addf(f float64) Vec4

func (*Vec4) Ceil

func (v *Vec4) Ceil() Vec4

func (*Vec4) Clamp

func (v *Vec4) Clamp(min, max Vec4) Vec4

func (*Vec4) DistanceSquaredTo

func (v *Vec4) DistanceSquaredTo(other Vec4) float64

func (*Vec4) DistanceTo

func (v *Vec4) DistanceTo(other Vec4) float64

func (*Vec4) Div

func (v *Vec4) Div(other Vec4) Vec4

func (*Vec4) Divf

func (v *Vec4) Divf(f float64) Vec4

func (*Vec4) Dot

func (v *Vec4) Dot(other Vec4) float64

func (*Vec4) Floor

func (v *Vec4) Floor() Vec4

func (*Vec4) IsApproximatelyZero

func (v *Vec4) IsApproximatelyZero() bool

func (*Vec4) IsFinite

func (v *Vec4) IsFinite() bool

func (*Vec4) IsNormalized

func (v *Vec4) IsNormalized() bool

func (*Vec4) Length

func (v *Vec4) Length() float64

func (*Vec4) LengthSquared

func (v *Vec4) LengthSquared() float64

func (*Vec4) Lerp

func (v *Vec4) Lerp(to Vec4, weight float64) Vec4

func (*Vec4) Lerpf

func (v *Vec4) Lerpf(to Vec4, weight float64) Vec4

func (*Vec4) Mul

func (v *Vec4) Mul(other Vec4) Vec4

func (*Vec4) Mulf

func (v *Vec4) Mulf(f float64) Vec4

func (*Vec4) Neg

func (v *Vec4) Neg() Vec4

func (Vec4) Normalize

func (v Vec4) Normalize() Vec4

func (*Vec4) Round

func (v *Vec4) Round() Vec4

func (*Vec4) Sign

func (v *Vec4) Sign() Vec4

func (Vec4) String

func (v Vec4) String() string

func (*Vec4) Sub

func (v *Vec4) Sub(other Vec4) Vec4

func (*Vec4) Subf

func (v *Vec4) Subf(f float64) Vec4

type Vec4i

type Vec4i struct {
	X, Y, Z, W Int
}

func NewVec4i

func NewVec4i(x, y, z, w int) Vec4i

func (Vec4i) Abs

func (v Vec4i) Abs() Vec4i

func (Vec4i) Add

func (v Vec4i) Add(other Vec4i) Vec4i

func (Vec4i) Addi

func (v Vec4i) Addi(i int) Vec4i

func (Vec4i) Clamp

func (v Vec4i) Clamp(min, max Vec4i) Vec4i

func (Vec4i) DistanceSquaredTo

func (v Vec4i) DistanceSquaredTo(other Vec4i) float64

func (Vec4i) DistanceTo

func (v Vec4i) DistanceTo(other Vec4i) float64

func (Vec4i) Div

func (v Vec4i) Div(other Vec4i) Vec4i

func (Vec4i) Divi

func (v Vec4i) Divi(i int) Vec4i

func (Vec4i) Dot

func (v Vec4i) Dot(other Vec4i) float64

func (Vec4i) Length

func (v Vec4i) Length() float64

func (Vec4i) LengthSquared

func (v Vec4i) LengthSquared() float64

func (Vec4i) Mul

func (v Vec4i) Mul(other Vec4i) Vec4i

func (Vec4i) Muli

func (v Vec4i) Muli(i int) Vec4i

func (Vec4i) Neg

func (v Vec4i) Neg() Vec4i

func (Vec4i) Sign

func (v Vec4i) Sign() Vec4i

func (Vec4i) String

func (v Vec4i) String() string

func (Vec4i) Sub

func (v Vec4i) Sub(other Vec4i) Vec4i

func (Vec4i) Subi

func (v Vec4i) Subi(i int) Vec4i

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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