d2math

package
v0.0.0-...-7f92c57 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 2 Imported by: 4

Documentation

Overview

Package d2math provides mathematical functions not included in Golang's standard math library.

The decimal numeric type used is float64.

Math also dictates the threshold for approximate equality (d2math.Epsilon). This is currently used both for moving entities and for approximate floating point equality in vector functions. See d2vector.

Index

Constants

View Source
const (
	// Epsilon is used as the threshold for 'almost equal' operations.
	Epsilon float64 = 0.0001

	// RadToDeg is used to convert anges in radians to degrees by multiplying the radians by RadToDeg. Similarly,degrees
	// are converted to radians when dividing by RadToDeg.
	RadToDeg float64 = 57.29578

	// RadFull is the radian equivalent of 360 degrees.
	RadFull float64 = 6.283185253783088
)

Variables

This section is empty.

Functions

func Abs

func Abs(a float64) float64

Abs returns the absolute value of a. It is a less CPU intensive version of the standard library math.Abs().

func AbsInt32

func AbsInt32(a int32) int32

AbsInt32 returns the absolute of the given int32

func Clamp

func Clamp(a, min, max float64) float64

Clamp returns a clamped to min and max.

func ClampInt

func ClampInt(value, min, max int) int

ClampInt ensures that the given value is between or equal to the given min or max

func CompareApprox

func CompareApprox(a, b float64) int

CompareApprox returns an integer between -1 and 1 describing the comparison of floats a and b. 0 will be returned if the absolute difference between a and b is less than Epsilon.

func EqualsApprox

func EqualsApprox(a, b float64) bool

EqualsApprox returns true if the difference between a and b is less than Epsilon.

func GetRadiansBetween

func GetRadiansBetween(p1X, p1Y, p2X, p2Y float64) float64

GetRadiansBetween returns the radians between two points. 0rad is facing to the right.

func Lerp

func Lerp(a, b, x float64) float64

Lerp returns the linear interpolation from a to b using interpolator x.

func Max

func Max(a, b uint32) uint32

Max returns the higher of two values

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the maximum of the given values

func MaxInt32

func MaxInt32(a, b int32) int32

MaxInt32 returns the higher of two values

func Min

func Min(a, b uint32) uint32

Min returns the lower of two values

func MinInt

func MinInt(a, b int) int

MinInt returns the minimum of the given values

func MinInt32

func MinInt32(a, b int32) int32

MinInt32 returns the higher of two values

func Sign

func Sign(a float64) int

Sign returns the sign of a.

func Unlerp

func Unlerp(a, b, x float64) float64

Unlerp returns the intepolator Lerp would require to return x when given a and b. The x argument of this function can be thought of as the return value of lerp. The return value of this function can be used as x in Lerp.

func WrapInt

func WrapInt(x, max int) int

WrapInt wraps x to between 0 and max. For example WrapInt(450, 360) would return 90.

Types

type RangedNumber

type RangedNumber struct {
	// contains filtered or unexported fields
}

RangedNumber is a number with a min and max range

func (*RangedNumber) Add

func (rn *RangedNumber) Add(other *RangedNumber) *RangedNumber

Add adds the given ranged number to this one, returning this one

func (RangedNumber) Clone

func (rn RangedNumber) Clone() *RangedNumber

Clone creates a new copy of a ranged number, with the same min/max

func (*RangedNumber) Copy

func (rn *RangedNumber) Copy(other *RangedNumber) *RangedNumber

Copy copies the min/max values of the given ranged number

func (*RangedNumber) Div

func (rn *RangedNumber) Div(other *RangedNumber) *RangedNumber

Div divides this ranged number by the given ranged number, returning this one

func (*RangedNumber) Equals

func (rn *RangedNumber) Equals(other *RangedNumber) bool

Equals checks equality with the given ranged number

func (*RangedNumber) Max

func (rn *RangedNumber) Max() int

Max returns the max value, swapping min/max if not ordered

func (*RangedNumber) Min

func (rn *RangedNumber) Min() int

Min returns the min value, swapping min/max if not ordered

func (*RangedNumber) Mul

func (rn *RangedNumber) Mul(other *RangedNumber) *RangedNumber

Mul multiplies this ranged number by the given ranged number, returning this one

func (*RangedNumber) Set

func (rn *RangedNumber) Set(min, max int) *RangedNumber

Set sets the min and max values, ordering the arguments if necessary

func (*RangedNumber) SetMax

func (rn *RangedNumber) SetMax(max int) *RangedNumber

SetMax sets the maximum value

func (*RangedNumber) SetMin

func (rn *RangedNumber) SetMin(min int) *RangedNumber

SetMin sets the minimum value

func (*RangedNumber) String

func (rn *RangedNumber) String() string

func (*RangedNumber) Sub

func (rn *RangedNumber) Sub(other *RangedNumber) *RangedNumber

Sub subtracts the given ranged number from this one, returning this one

Directories

Path Synopsis
Package d2vector provides an implementation of a 2D Euclidean vector using float64 to store the two values.
Package d2vector provides an implementation of a 2D Euclidean vector using float64 to store the two values.

Jump to

Keyboard shortcuts

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