Documentation ¶
Overview ¶
Package r2 implements operations relating to objects in R2.
Index ¶
- type Box
- func (b Box) Area() float64
- func (b Box) Bottom() Line
- func (b Box) Center() Vec2
- func (b Box) Contains(v Vec2) bool
- func (b Box) GetCorner1() Vec2
- func (b Box) GetCorner2() Vec2
- func (b Box) GetCorner3() Vec2
- func (b Box) GetCorner4() Vec2
- func (b Box) Height() float64
- func (b Box) Intersect(l Line) (Vec2, bool)
- func (b Box) Left() Line
- func (b Box) Right() Line
- func (b Box) Top() Line
- func (b Box) Width() float64
- type Line
- type Vec2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct { // A defines the top-left corner of the box A Vec2 // S defines the size of the box S Vec2 }
Box defines a box in R2
A | | | v (1) A.X,A.Y +------+ A.X+S.X,A.Y (2) |\ | | \ | | \ | | \S | | \ | | \|
(3)A.X,A.Y+S.Y +------+ A.X+S.X,A.Y+S.Y (4)
func BoundingBox ¶
BoundingBox creates a minimum axis-aligned bounding box for the given list of points.
func (Box) GetCorner1 ¶
GetCorner1 returns the top left corner of the box
func (Box) GetCorner2 ¶
GetCorner2 returns the top right corner of the box
func (Box) GetCorner3 ¶
GetCorner3 returns the bottom left corner of the box.
func (Box) GetCorner4 ¶
GetCorner4 returns the bottom right corner of the box.
type Line ¶
type Line struct { // A defines the basis point of the line A Vec2 // S defines the direction and length of the line S Vec2 }
Line describes a line in R2
(1) A.X,A.Y + \ \ \ \ + A.X+S.X,A.Y+S.Y (2)
func MakeLineFromEndpoints ¶
Return a line which has endpoints a, b
type Vec2 ¶
Vec2 implements a vector in R2
func IntersectLines ¶
This code is transliterated from here:
https://github.com/JulNadeauCA/libagar/blob/master/gui/primitive.co
Which is in turn based on Gem I.2 in Graphics Gems II by James Arvo.
func (Vec2) ScaleToLength ¶
ScaleToLength keeps the vector direction, but updates the length