util

package
v0.0.0-...-d85e1bb Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SHIFT_A = 10
View Source
const SHIFT_B = 10

Variables

This section is empty.

Functions

func AngleBetween

func AngleBetween(source, destination *Vector2D) float64

Get the angle between two vectors in radians

The result is in the range [-π, π]

func AngleDifference

func AngleDifference(a, b float64) float64

AngleDifference returns the smallest difference between two angles in radians

The result is in the range [-π, π]

func Distance

func Distance(a, b *Vector2D) float64

Get the distance between two points

Prefer SquaredDistance for comparisons between distances

func Lerp

func Lerp(a, b, t float64) float64

Smoothly interpolate between two values

func LerpAngle

func LerpAngle(a, b, t float64) float64

Smoothly interpolate between two angles in radians

func NearColorHueOnly

func NearColorHueOnly(col color.Color, randomThresh float64) color.RGBA

func RandomFireColor

func RandomFireColor() color.RGBA

func RandomRange

func RandomRange(min, max float64) float64

RandomRange returns a random float64 between min and max

If min is greater than max, they are swapped

func RandomRangeInt

func RandomRangeInt(min, max int) int

RandomRangeInt returns a random int between min and max

If min is greater than max, they are swapped

func SquaredDistance

func SquaredDistance(a, b *Vector2D) float64

Get the squared distance between two points

This is more efficient than using the Distance function if you don't need the actual distance

func TwoPolygonsIntersect

func TwoPolygonsIntersect(p1, p2 *Polygon) (intersects bool)

Types

type AABB

type AABB struct {
	X1, Y1, X2, Y2 float64
}

func (*AABB) Contains

func (a *AABB) Contains(x, y float64) bool

func (*AABB) GetCenter

func (a *AABB) GetCenter() *Vector2D

func (*AABB) Intersects

func (a *AABB) Intersects(b *AABB) bool

type Collidable

type Collidable interface {
	Identifiable
	GetAABB() *AABB
}

type Identifiable

type Identifiable interface {
	GetID() uint64
}

type Polygon

type Polygon struct {
	Reference, Points []*Vector2D

	AABB *AABB
	// contains filtered or unexported fields
}

func NewPolygon

func NewPolygon(points []*Vector2D, position *Vector2D, radius, rotation float64) (p *Polygon)

func (*Polygon) CircleIntersects

func (p *Polygon) CircleIntersects(circlePoint *Vector2D, radius float64) (intersects bool)

func (*Polygon) CircleIntersectsEdge

func (p *Polygon) CircleIntersectsEdge(p1, p2 *Vector2D, circlePoint *Vector2D, circleRadius float64) (intersects bool)

func (*Polygon) GetAxes

func (p *Polygon) GetAxes() (axes []*Vector2D)

func (*Polygon) GetClosestPointOnEdge

func (p *Polygon) GetClosestPointOnEdge(p1, p2, p3 *Vector2D) (point *Vector2D)

func (*Polygon) PointIsInside

func (p *Polygon) PointIsInside(point *Vector2D) (inside bool)

func (*Polygon) ProjectOnto

func (p *Polygon) ProjectOnto(axis *Vector2D) (minimum, maximum float64)

func (*Polygon) Transform

func (p *Polygon) Transform(position *Vector2D, radius, rotation float64)

type PolygonXYPoint

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

type SafeStorage

type SafeStorage[T Identifiable] struct {
	// contains filtered or unexported fields
}

func NewSafeStorage

func NewSafeStorage[T Identifiable]() *SafeStorage[T]

func (*SafeStorage[T]) Add

func (ss *SafeStorage[T]) Add(item T)

Adds an item to the storage. In this instance, it is enqueued for addition until next flush.

func (*SafeStorage[T]) Clear

func (ss *SafeStorage[T]) Clear()

Clears all items from the storage.

func (*SafeStorage[T]) Flush

func (ss *SafeStorage[T]) Flush()

Flushes all enqueued additions and removals to the storage.

func (*SafeStorage[T]) ForEach

func (ss *SafeStorage[T]) ForEach(f func(T))

Iterates over all items in the storage and applies the provided function to each item.

func (*SafeStorage[T]) Get

func (ss *SafeStorage[T]) Get(id uint64) T

Retrieves an item from the storage by its ID. Returns nil if the item does not exist.

func (*SafeStorage[T]) Remove

func (ss *SafeStorage[T]) Remove(item T)

Removes an item from the storage. In this instance, it is enqueued for removal until next flush.

func (*SafeStorage[T]) Size

func (ss *SafeStorage[T]) Size() int

Returns the number of items in the storage.

type SpatialHash

type SpatialHash[T Collidable] struct {
	// contains filtered or unexported fields
}

func NewSpatialHash

func NewSpatialHash[T Collidable]() *SpatialHash[T]

func (*SpatialHash[T]) All

func (sh *SpatialHash[T]) All() (results []T)

func (*SpatialHash[T]) Clear

func (sh *SpatialHash[T]) Clear()

func (*SpatialHash[T]) Insert

func (sh *SpatialHash[T]) Insert(item T)

func (*SpatialHash[T]) Retrieve

func (sh *SpatialHash[T]) Retrieve(aabb *AABB) (results []T)

func (*SpatialHash[T]) RetrieveAround

func (sh *SpatialHash[T]) RetrieveAround(x, y, radius float64) []T

type Vector2D

type Vector2D struct {
	X, Y float64
}

func RandomAngularVector

func RandomAngularVector(minStrength, maxStrength float64) *Vector2D

func RandomRadius

func RandomRadius(radius float64) *Vector2D

func ResolveCirclePolygon

func ResolveCirclePolygon(circlePoint *Vector2D, circleRadius float64, polygon *Polygon) (point *Vector2D, angle float64)

func ResolveTwoPolygons

func ResolveTwoPolygons(p1, p2 *Polygon) (resolution *Vector2D)

func SVGPathToVector2DArray

func SVGPathToVector2DArray(path string) (points []*Vector2D)

func Vector

func Vector(x, y float64) *Vector2D

func VectorFromAngle

func VectorFromAngle(angle, magnitude float64) *Vector2D

func (*Vector2D) Add

func (v *Vector2D) Add(other *Vector2D) *Vector2D

func (*Vector2D) AngleBetween

func (v *Vector2D) AngleBetween(other *Vector2D) float64

func (*Vector2D) Copy

func (v *Vector2D) Copy() *Vector2D

func (*Vector2D) Cross

func (v *Vector2D) Cross(other *Vector2D) float64

func (*Vector2D) Direction

func (v *Vector2D) Direction() float64

func (*Vector2D) Dot

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

func (*Vector2D) Magnitude

func (v *Vector2D) Magnitude() float64

func (*Vector2D) Normalize

func (v *Vector2D) Normalize() *Vector2D

func (*Vector2D) Rotate

func (v *Vector2D) Rotate(angle float64) *Vector2D

func (*Vector2D) Scale

func (v *Vector2D) Scale(scalar float64) *Vector2D

func (*Vector2D) SquaredMagnitude

func (v *Vector2D) SquaredMagnitude() float64

func (*Vector2D) Subtract

func (v *Vector2D) Subtract(other *Vector2D) *Vector2D

func (*Vector2D) SubtractFrom

func (v *Vector2D) SubtractFrom(other *Vector2D) *Vector2D

Jump to

Keyboard shortcuts

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