Documentation
¶
Index ¶
- Constants
- func AngleBetween(source, destination *Vector2D) float64
- func AngleDifference(a, b float64) float64
- func Distance(a, b *Vector2D) float64
- func Lerp(a, b, t float64) float64
- func LerpAngle(a, b, t float64) float64
- func NearColorHueOnly(col color.Color, randomThresh float64) color.RGBA
- func RandomFireColor() color.RGBA
- func RandomRange(min, max float64) float64
- func RandomRangeInt(min, max int) int
- func SquaredDistance(a, b *Vector2D) float64
- func TwoPolygonsIntersect(p1, p2 *Polygon) (intersects bool)
- type AABB
- type Collidable
- type Identifiable
- type Polygon
- func (p *Polygon) CircleIntersects(circlePoint *Vector2D, radius float64) (intersects bool)
- func (p *Polygon) CircleIntersectsEdge(p1, p2 *Vector2D, circlePoint *Vector2D, circleRadius float64) (intersects bool)
- func (p *Polygon) GetAxes() (axes []*Vector2D)
- func (p *Polygon) GetClosestPointOnEdge(p1, p2, p3 *Vector2D) (point *Vector2D)
- func (p *Polygon) PointIsInside(point *Vector2D) (inside bool)
- func (p *Polygon) ProjectOnto(axis *Vector2D) (minimum, maximum float64)
- func (p *Polygon) Transform(position *Vector2D, radius, rotation float64)
- type PolygonXYPoint
- type SafeStorage
- type SpatialHash
- type Vector2D
- func RandomAngularVector(minStrength, maxStrength float64) *Vector2D
- func RandomRadius(radius float64) *Vector2D
- func ResolveCirclePolygon(circlePoint *Vector2D, circleRadius float64, polygon *Polygon) (point *Vector2D, angle float64)
- func ResolveTwoPolygons(p1, p2 *Polygon) (resolution *Vector2D)
- func SVGPathToVector2DArray(path string) (points []*Vector2D)
- func Vector(x, y float64) *Vector2D
- func VectorFromAngle(angle, magnitude float64) *Vector2D
- func (v *Vector2D) Add(other *Vector2D) *Vector2D
- func (v *Vector2D) AngleBetween(other *Vector2D) float64
- func (v *Vector2D) Copy() *Vector2D
- func (v *Vector2D) Cross(other *Vector2D) float64
- func (v *Vector2D) Direction() float64
- func (v *Vector2D) Dot(other *Vector2D) float64
- func (v *Vector2D) Magnitude() float64
- func (v *Vector2D) Normalize() *Vector2D
- func (v *Vector2D) Rotate(angle float64) *Vector2D
- func (v *Vector2D) Scale(scalar float64) *Vector2D
- func (v *Vector2D) SquaredMagnitude() float64
- func (v *Vector2D) Subtract(other *Vector2D) *Vector2D
- func (v *Vector2D) SubtractFrom(other *Vector2D) *Vector2D
Constants ¶
const SHIFT_A = 10
const SHIFT_B = 10
Variables ¶
This section is empty.
Functions ¶
func AngleDifference ¶
AngleDifference returns the smallest difference between two angles in radians
The result is in the range [-π, π]
func Distance ¶
Get the distance between two points
Prefer SquaredDistance for comparisons between distances
func RandomFireColor ¶
func RandomRange ¶
RandomRange returns a random float64 between min and max
If min is greater than max, they are swapped
func RandomRangeInt ¶
RandomRangeInt returns a random int between min and max
If min is greater than max, they are swapped
func SquaredDistance ¶
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 ¶
Types ¶
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 (*Polygon) CircleIntersects ¶
func (*Polygon) CircleIntersectsEdge ¶
func (*Polygon) GetClosestPointOnEdge ¶
func (*Polygon) PointIsInside ¶
func (*Polygon) ProjectOnto ¶
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]) 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
}