Documentation ¶
Index ¶
- type Point
- func (p Point) Add(q Point) Point
- func (p Point) Dist(q Point) float64
- func (p Point) Div(q Point) Point
- func (p Point) Eq(q Point) bool
- func (p Point) Len() float64
- func (p Point) Mul(q Point) Point
- func (p Point) Normalize() Point
- func (p Point) SqDist(q Point) float64
- func (p Point) String() string
- func (p Point) Sub(q Point) Point
- type Rectangle
- func (r Rectangle) Add(p Point) Rectangle
- func (r Rectangle) Center() Point
- func (r Rectangle) Dx() float64
- func (r Rectangle) Dy() float64
- func (r Rectangle) Eq(s Rectangle) bool
- func (r Rectangle) Intersect(s Rectangle) Rectangle
- func (r Rectangle) Overlaps(s Rectangle) bool
- func (r Rectangle) OverlapsX(s Rectangle) bool
- func (r Rectangle) OverlapsY(s Rectangle) bool
- func (r Rectangle) Pad(p float64) Rectangle
- func (r Rectangle) Rpad(p float64) Rectangle
- func (r Rectangle) Size() Point
- func (r Rectangle) String() string
- func (r Rectangle) Sub(p Point) Rectangle
- type Torus
- func (t Torus) AlignRects(a, b Rectangle) (Rectangle, Rectangle)
- func (t Torus) Dist(a, b Point) float64
- func (t Torus) Intersect(a, b Rectangle) Rectangle
- func (t Torus) Norm(a Point) Point
- func (t Torus) NormRect(r Rectangle) Rectangle
- func (t Torus) Overlaps(a, b Rectangle) bool
- func (t Torus) SqDist(a, b Point) float64
- func (t Torus) Sub(a, b Point) Point
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Point ¶
type Point struct {
X, Y float64
}
A Point is an X, Y coordinate pair. The axes increase right and down.
type Rectangle ¶
type Rectangle struct {
Min, Max Point
}
A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.
func (Rectangle) Intersect ¶
Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.
func (Rectangle) OverlapsX ¶
OverlapsX returns whether r and s have a non-empty intersection in the x direction.
func (Rectangle) OverlapsY ¶
OverlapsY returns whether r and s have a non-empty intersection in the y direction.
func (Rectangle) Pad ¶
Pad returns a rectangle with p added to the left, right, top, and bottom of r.
func (Rectangle) Rpad ¶
Rpad returns a rectangle with p removed from the left, right, top, and bottom of r.
type Torus ¶
type Torus struct {
W, H float64
}
A Torus represents a torus with the given width and height.
func (Torus) AlignRects ¶
AlignRects returns a pair of rectangles. The first is the normalized equivalent of a. The second is equivalent to b on the torus. If there is b equivalent that overlaps a on the torus, then it is returned, otherwise it is any b equivalent.
Both a and b are assumed to be smaller than the width and height of the torus.
func (Torus) Intersect ¶
Intersect returns the intersection of a and b on the torus.
Both a and b must be smaller than the size of the torus.
func (Torus) Norm ¶
Norm returns a point that is equivalent to a on the torus, but is within (0,0)-(W-1, H-1).
func (Torus) NormRect ¶
NormRect returns a rectangle equivalent to r on the torus, but with its minimum point normalized.
func (Torus) Overlaps ¶
Overlaps returns true if the two rectangles intersect on the torus.
Both a and b must be smaller than the size of the torus.