geom

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 1 Imported by: 2 modules, 66 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type AABB struct {
	TopLeft     Vec
	BottomRight Vec
}

AABB is a minimal axis-aligned rectangle defined by its top-left and bottom-right corners.

func NewAABB

func NewAABB(topLeft, bottomRight Vec) AABB

NewAABB constructs a axis-aligned bounding box from explicit corner vectors.

func NewAABBAt

func NewAABBAt(pos Vec, width, height float32) AABB

NewAABBAt builds a AABB starting at pos with the provided width and height.

func (AABB) AxisDistanceX

func (ab AABB) AxisDistanceX(other AABB) float32

AxisDistanceTo returns the gap between tow given AABBs on the axis selected by axisValue.

func (AABB) AxisDistanceY

func (ab AABB) AxisDistanceY(other AABB) float32

func (AABB) Contains

func (ab AABB) Contains(other AABB) bool

Contains reports whether other lies entirely within axis-aligned bounding box.

func (AABB) Equals

func (ab AABB) Equals(other AABB) bool

Equals reports whether ab and other share the same corners.

func (AABB) Intersects

func (ab AABB) Intersects(other AABB) bool

Intersects reports whether the boxes overlap or touch.

func (AABB) Penetration

func (ab AABB) Penetration(other AABB) Vec

Penetration is the shortest translation that moves ab clear of other, or zero when apart.

func (AABB) String

func (ab AABB) String() string

String formats the box using its top-left and bottom-right corners.

type Vec

type Vec struct{ X, Y float32 }

Vec is a 2D vector in float32 coordinates.

func NewVec

func NewVec(X, Y float32) Vec

func (Vec) Add

func (v Vec) Add(v2 Vec) Vec

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

func (v *Vec) AddMutable(v2 Vec)

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

func (v Vec) Equals(v2 Vec) bool

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

func (Vec) String

func (v Vec) String() string

String formats v as "(X,Y)".

Example

ExampleVec_String demonstrates how to use the String method.

v := NewVec(1.0, 2.0)
fmt.Println(v.String())
Output:
(1,2)

func (Vec) Sub

func (v Vec) Sub(v2 Vec) Vec

Sub returns a new vector that subtracts v2 from v.

Example

ExampleVec_Sub demonstrates how to use the Sub method.

v1 := NewVec(5.0, 7.0)
v2 := NewVec(2.0, 3.0)
result := v1.Sub(v2)
fmt.Println(result)
Output:
(3,4)

Jump to

Keyboard shortcuts

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