plane

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: 4 Imported by: 0 modules, 0 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 plane is the surface behind a Space: the edge rules of a bounded plane or a torus, and what they do to the public plane's boxes — folding, moving, growing, and telling when one has left.

Edges

Edges is the rule per axis: nothing (a box stops at the edge, clamped whole), WrapX or WrapY (the axis is periodic), OpenX or OpenY (a box may leave). Torus wraps both. Edges.Valid refuses an axis that both wraps and is open.

Surface

A Surface is a size and its Edges, built by NewSurface, or by NewEuclidean2D and NewToroidal2D for the two common cases. Surface.Translate moves a box by a delta, axis by axis: folded back in on a wrapping axis, let go on an open one, clamped on a closed one; Surface.TranslateRun does it to every box of a column of records by its own delta. Surface.Expand grows a box by a margin on every side and folds it the same way. Surface.WrapAABB folds any rectangle into a box the plane holds. Surface.Left reports a box wholly past an open edge, which a Space then drops from its index.

Clamp and Wrap

Clamp bounds a point to the plane; Wrap folds it back in on both axes. They are the scalar rules the Surface applies per axis.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(v, size geom.Vec) geom.Vec

Clamp bounds v to the inclusive box [0,size].

func Wrap

func Wrap(v, size geom.Vec) geom.Vec

Wrap folds v back into [0,size) on each axis.

Types

type Edges

type Edges uint8

Edges is what happens to a box at the edges of the world, per axis; zero stops it whole.

const (
	WrapX Edges = 1 << iota
	WrapY
	OpenX
	OpenY
	Torus = WrapX | WrapY
)

func (Edges) Valid

func (e Edges) Valid() bool

Valid reports whether no axis is asked both to wrap and to be open.

type Surface

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

Surface is a plane of a given size that keeps boxes canonical under its edge rules.

func NewEuclidean2D

func NewEuclidean2D(sizeX, sizeY float32) *Surface

NewEuclidean2D builds a plane closed on every side.

Example (NormalizeVec_float32)
euclidean := NewEuclidean2D(10.0, 10.0)
vec := geom.NewVec(5., 5)
delta := geom.NewVec(3., 4)
vec.AddMutable(delta)
vec = euclidean.normalizeVec(vec)
fmt.Println(vec)
Output:
(8,9)
Example (NormalizeVec_int)

ExampleNormalizeVecEuclidean2D_int demonstrates how to use NewBoundedPlane with int type.

plane := NewEuclidean2D(10, 10)
vec := geom.NewVec(5, 5)
delta := geom.NewVec(3, 4)
vec.AddMutable(delta)
vec = plane.normalizeVec(vec)
fmt.Println(vec)
Output:
(8,9)

func NewSurface

func NewSurface(sizeX, sizeY float32, edges Edges) *Surface

NewSurface builds a plane of the given size and edge rules.

func NewToroidal2D

func NewToroidal2D(sizeX, sizeY float32) *Surface

NewToroidal2D builds a plane that wraps on both axes.

Example (NormalizeVec_float32)
toroidal := NewToroidal2D(10.0, 10.0)
vec := geom.NewVec(9., 9)
delta := geom.NewVec(3., 4)
vec.AddMutable(delta)
vec = toroidal.normalizeVec(vec)
fmt.Println(vec)
Output:
(2,3)
Example (NormalizeVec_int)

ExampleNewToroidal2D_normalizeVec_int demonstrates how to use NewToroidal2D with int type.

toroidal := NewToroidal2D(10, 10)
vec := geom.NewVec(9, 9)
delta := geom.NewVec(3, 4)
vec.AddMutable(delta)
vec = toroidal.normalizeVec(vec)
fmt.Println(vec)
Output:
(2,3)

func (*Surface) Expand

func (s *Surface) Expand(aabb *plane.AABB, margin float32)

Expand grows aabb by margin on every side and folds it like WrapAABB.

func (*Surface) Left

func (s *Surface) Left(aabb *plane.AABB) bool

Left reports whether aabb lies wholly past an open edge.

func (*Surface) Translate

func (s *Surface) Translate(aabb *plane.AABB, delta geom.Vec)

Translate moves aabb by delta: wrapped, stopped whole, or let go, by the rule of each axis.

func (*Surface) TranslateRun added in v1.15.0

func (s *Surface) TranslateRun(boxes unsafe.Pointer, stride uintptr, deltas []geom.Vec)

TranslateRun is Translate of the box at boxes+i·stride by deltas[i], for every i whose delta is not zero.

func (*Surface) WrapAABB

func (s *Surface) WrapAABB(aabb geom.AABB) plane.AABB

WrapAABB folds a rectangle into the plane: wrapped on a wrapping axis, clipped on any other.

Jump to

Keyboard shortcuts

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