xmath

package
v1.32.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MPL-2.0 Imports: 4 Imported by: 17

Documentation

Overview

Package xmath provides math-related utilities.

Index

Constants

View Source
const (
	// DegreesToRadians converts a value in degrees to radians when multiplied
	// with the value.
	DegreesToRadians = math.Pi / 180
	// RadiansToDegrees converts a value in radians to degrees when multiplied
	// with the value.
	RadiansToDegrees = 180 / math.Pi
)

Variables

This section is empty.

Functions

func AbsFloat32

func AbsFloat32(x float32) float32

AbsFloat32 returns the absolute value of x.

func AbsInt

func AbsInt(x int) int

AbsInt returns the absolute value of x.

func CeilFloat32

func CeilFloat32(x float32) float32

CeilFloat32 returns the smallest integer value greater than or equal to x.

func FloorFloat32

func FloorFloat32(x float32) float32

FloorFloat32 returns the greatest integer value less than or equal to x.

func MaxFloat32

func MaxFloat32(a, b float32) float32

MaxFloat32 returns the larger of a or b. Note that there is no special handling for Inf, NaN, or +0 vs -0. If you want/need that, up-cast to float64 and use math.Max().

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the larger of a or b.

func MinFloat32

func MinFloat32(a, b float32) float32

MinFloat32 returns the smaller of a or b. Note that there is no special handling for Inf, NaN, or +0 vs -0. If you want/need that, up-cast to float64 and use math.Min().

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller of a or b.

func Round

func Round(x float64) float64

Round returns the closest integer.

func RoundFloat32

func RoundFloat32(x float32) float32

RoundFloat32 returns the closest integer.

Types

type BitSet

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

BitSet contains a set of bits.

func (*BitSet) Clear

func (b *BitSet) Clear(index int)

Clear the bit at 'index'.

func (*BitSet) ClearRange

func (b *BitSet) ClearRange(start, end int)

ClearRange clears the bits from 'start' to 'end', inclusive.

func (*BitSet) Clone

func (b *BitSet) Clone() *BitSet

Clone this BitSet.

func (*BitSet) Copy

func (b *BitSet) Copy(other *BitSet)

Copy the content of 'other' into this BitSet, making them equal.

func (*BitSet) Count

func (b *BitSet) Count() int

Count returns the number of set bits.

func (*BitSet) Data

func (b *BitSet) Data() []uint64

Data returns a copy of the underlying storage.

func (*BitSet) EnsureCapacity

func (b *BitSet) EnsureCapacity(words int)

EnsureCapacity ensures that the BitSet has enough underlying storage to accommodate setting a bit as high as index position 'words' x 64 - 1 without needing to allocate more storage.

func (*BitSet) Equal

func (b *BitSet) Equal(other *BitSet) bool

Equal returns true if this BitSet is equal to 'other'.

func (*BitSet) FirstSet

func (b *BitSet) FirstSet() int

FirstSet returns the first set bit. If no bits are set, then -1 is returned.

func (*BitSet) Flip

func (b *BitSet) Flip(index int)

Flip the bit at 'index'.

func (*BitSet) FlipRange

func (b *BitSet) FlipRange(start, end int)

FlipRange flips the bits from 'start' to 'end', inclusive.

func (*BitSet) LastSet

func (b *BitSet) LastSet() int

LastSet returns the last set bit. If no bits are set, then -1 is returned.

func (*BitSet) Load

func (b *BitSet) Load(data []uint64)

Load replaces the current data with the bits set in 'data'.

func (*BitSet) NextClear

func (b *BitSet) NextClear(start int) int

NextClear returns the next clear bit starting from 'start'.

func (*BitSet) NextSet

func (b *BitSet) NextSet(start int) int

NextSet returns the next set bit starting from 'start'. If no bits are set at or beyond 'start', then -1 is returned.

func (*BitSet) PreviousClear

func (b *BitSet) PreviousClear(start int) int

PreviousClear returns the previous clear bit starting from 'start'. If no bits are clear at or before 'start', then -1 is returned.

func (*BitSet) PreviousSet

func (b *BitSet) PreviousSet(start int) int

PreviousSet returns the previous set bit starting from 'start'. If no bits are set at or before 'start', then -1 is returned.

func (*BitSet) Reset

func (b *BitSet) Reset()

Reset the BitSet back to an empty state.

func (*BitSet) Set

func (b *BitSet) Set(index int)

Set the bit at 'index'.

func (*BitSet) SetRange

func (b *BitSet) SetRange(start, end int)

SetRange sets the bits from 'start' to 'end', inclusive.

func (*BitSet) State

func (b *BitSet) State(index int) bool

State returns the state of the bit at 'index'.

func (*BitSet) Trim

func (b *BitSet) Trim()

Trim the BitSet down to the minimum required to store the set bits.

type Matrix2D

type Matrix2D struct {
	XX, YX, XY, YY, X0, Y0 float64
}

Matrix2D provides a 2D matrix.

func NewIdentityMatrix2D

func NewIdentityMatrix2D() *Matrix2D

NewIdentityMatrix2D creates a new identity transformation 2D matrix.

func NewMatrix2D

func NewMatrix2D(xx, yx, xy, yy, x0, y0 float64) *Matrix2D

NewMatrix2D creates a new 2D matrix.

func NewRotationMatrix2D

func NewRotationMatrix2D(radians float64) *Matrix2D

NewRotationMatrix2D creates a new 2D matrix that rotates by 'radians'. Positive values are clockwise.

func NewScaleMatrix2D

func NewScaleMatrix2D(sx, sy float64) *Matrix2D

NewScaleMatrix2D creates a new 2D matrix that scales by 'sx' and 'sy'.

func NewTranslationMatrix2D

func NewTranslationMatrix2D(tx, ty float64) *Matrix2D

NewTranslationMatrix2D creates a new 2D matrix that translates by 'tx' and 'ty'.

func (*Matrix2D) Multiply

func (m *Matrix2D) Multiply(other *Matrix2D)

Multiply this matrix by 'other'.

func (*Matrix2D) Rotate

func (m *Matrix2D) Rotate(radians float64)

Rotate this matrix by 'radians'. Positive values are clockwise.

func (*Matrix2D) Scale

func (m *Matrix2D) Scale(sx, sy float64)

Scale this matrix by 'sx' and 'sy'.

func (*Matrix2D) TransformDistance

func (m *Matrix2D) TransformDistance(size geom.Size) geom.Size

TransformDistance returns the result of transforming the distance vector (size.Width and size.Height) by this matrix. This is similar to TransformPoint(), except that the translation components of the transformation are ignored.

func (*Matrix2D) TransformPoint

func (m *Matrix2D) TransformPoint(where geom.Point) geom.Point

TransformPoint returns the result of transforming the point by this matrix.

func (*Matrix2D) Translate

func (m *Matrix2D) Translate(tx, ty float64)

Translate this matrix by 'tx' and 'ty'.

Directories

Path Synopsis
Package fixed provides fixed-point values that can be added, subtracted, multiplied and divided.
Package fixed provides fixed-point values that can be added, subtracted, multiplied and divided.
Package geom provides geometry primitives.
Package geom provides geometry primitives.
Package rand provides a Randomizer based upon the crypto/rand package.
Package rand provides a Randomizer based upon the crypto/rand package.

Jump to

Keyboard shortcuts

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