Documentation ¶
Overview ¶
Package r2 provides 2D vectors and boxes and operations on them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Box ¶
type Box struct {
Min, Max Vec
}
Box is a 2D bounding box. Well formed Boxes have Min components smaller than Max components.
func NewBox ¶ added in v0.12.0
NewBox is shorthand for Box{Min:Vec{x0,y0}, Max:Vec{x1,y1}}. The sides are swapped so that the resulting Box is well formed.
func (Box) Add ¶ added in v0.12.0
Add adds v to the bounding box components. It is the equivalent of translating the Box by v.
func (Box) Canon ¶ added in v0.12.0
Canon returns the canonical version of b. The returned Box has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Box) Contains ¶ added in v0.12.0
Contains returns true if v is contained within the bounds of the Box.
func (Box) Empty ¶ added in v0.12.0
Empty returns true if a Box's volume is zero or if a Min component is greater than its Max component.
func (Box) Scale ¶ added in v0.12.0
Scale returns a new Box scaled by a size vector around its center. The scaling is done element wise, which is to say the Box's X size is scaled by v.X. Negative components of v are interpreted as zero.
func (Box) Union ¶ added in v0.12.0
Union returns a box enclosing both the receiver and argument Boxes.
func (Box) Vertices ¶ added in v0.12.0
Vertices returns a slice of the 4 vertices corresponding to each of the Box's corners.
The order of the vertices is CCW in the XY plane starting at the box minimum. If viewing box from +Z position the ordering is as follows:
- Bottom left.
- Bottom right.
- Top right.
- Top left.
type Rotation ¶ added in v0.9.0
type Rotation struct {
// contains filtered or unexported fields
}
Rotation describes a rotation in 2D.
func NewRotation ¶ added in v0.9.0
NewRotation creates a rotation by alpha, around p.
type Triangle ¶ added in v0.12.0
type Triangle [3]Vec
Triangle represents a triangle in 2D space and is composed by 3 vectors corresponding to the position of each of the vertices.
func (Triangle) Centroid ¶ added in v0.12.0
Centroid returns the intersection of the three medians of the triangle as a point in space.
func (Triangle) IsDegenerate ¶ added in v0.12.0
IsDegenerate returns true if all of triangle's vertices are within tol distance of its longest side.