Documentation
¶
Overview ¶
Package geom holds the 2D vocabulary of aabbworld: Vec, a point or a displacement, and AABB, an axis-aligned box. Both are plain values with no notion of a world or its edges; the packages above build those on top.
Vec ¶
A Vec is two float32 coordinates. Vec.Add and Vec.Sub return a new Vec; Vec.AddMutable changes one in place for the hot paths that shift a box every tick.
AABB ¶
An AABB is its top-left and bottom-right corner, built by NewAABB from both corners or by NewAABBAt from a position and a size. AABB.Intersects is true when two boxes overlap or merely touch; AABB.Contains when one lies wholly in the other. AABB.Penetration is the shortest push that separates two overlapping boxes, zero when they do not overlap, and is what the collision solver works from. AABB.AxisDistanceX and AABB.AxisDistanceY are the gap between two boxes along one axis.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AABB ¶
AABB is a minimal axis-aligned rectangle defined by its top-left and bottom-right corners.
func (AABB) AxisDistanceX ¶
AxisDistanceTo returns the gap between tow given AABBs on the axis selected by axisValue.
func (AABB) AxisDistanceY ¶
func (AABB) Contains ¶
Contains reports whether other lies entirely within axis-aligned bounding box.
func (AABB) Intersects ¶
Intersects reports whether the boxes overlap or touch.
func (AABB) Penetration ¶
Penetration is the shortest translation that moves ab clear of other, or zero when apart.
type Vec ¶
type Vec struct{ X, Y float32 }
Vec is a 2D vector in float32 coordinates.
func (Vec) Add ¶
Add returns a new vector that is the sum of v and v2.
Example ¶
ExampleVec_Add demonstrates how to use the Add method.
v1 := NewVec(1.0, 2.0) v2 := NewVec(3.0, 4.0) result := v1.Add(v2) fmt.Println(result)
Output: (4,6)
func (*Vec) AddMutable ¶
AddMutable adds v2 to v in place.
Example ¶
ExampleVec_AddMutable demonstrates how to use the AddMutable method.
v1 := NewVec(1.0, 2.0) v2 := NewVec(3.0, 4.0) v1.AddMutable(v2) fmt.Println(v1)
Output: (4,6)
func (Vec) Equals ¶
Equals reports whether v and v2 have the same components.
Example ¶
ExampleVec_Equals demonstrates how to use the Equals method.
v1 := NewVec(1.0, 2.0) v2 := NewVec(1.0, 2.0) v3 := NewVec(3.0, 4.0) fmt.Println(v1.Equals(v2)) fmt.Println(v1.Equals(v3))
Output: true false