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 ¶
- func Clamp(v, size geom.Vec) geom.Vec
- func Wrap(v, size geom.Vec) geom.Vec
- type Edges
- type Surface
- func (s *Surface) Expand(aabb *plane.AABB, margin float32)
- func (s *Surface) Left(aabb *plane.AABB) bool
- func (s *Surface) Translate(aabb *plane.AABB, delta geom.Vec)
- func (s *Surface) TranslateRun(boxes unsafe.Pointer, stride uintptr, deltas []geom.Vec)
- func (s *Surface) WrapAABB(aabb geom.AABB) plane.AABB
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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 ¶
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 ¶
NewSurface builds a plane of the given size and edge rules.
func NewToroidal2D ¶
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) Translate ¶
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
TranslateRun is Translate of the box at boxes+i·stride by deltas[i], for every i whose delta is not zero.