Documentation ¶
Overview ¶
Package geo conatins geometric and mathematical types and functions.
Index ¶
- type NumGen
- type Rect
- func (r Rect) Area() float64
- func (r Rect) Bottom() float64
- func (r Rect) BottomLeft() (x, y float64)
- func (r Rect) BottomRight() (x, y float64)
- func (r Rect) Center() (x, y float64)
- func (r Rect) CenterX() float64
- func (r Rect) CenterY() float64
- func (r *Rect) Clamp(bounds Rect)
- func (r Rect) Clamped(bounds Rect) Rect
- func (r Rect) CollideList(others []Rect) int
- func (r Rect) CollideListAll(others []Rect) []int
- func (r Rect) CollidePoint(x, y float64) bool
- func (r Rect) CollideRect(other Rect) bool
- func (r Rect) Contains(other Rect) bool
- func (r *Rect) Fit(bounds Rect)
- func (r Rect) Fitted(bounds Rect) Rect
- func (r Rect) Height() float64
- func (r *Rect) Inflate(dw, dh float64)
- func (r Rect) Inflated(dw, dh float64) Rect
- func (r Rect) Intersect(other Rect) Rect
- func (r Rect) Left() float64
- func (r Rect) MidBottom() (x, y float64)
- func (r Rect) MidLeft() (x, y float64)
- func (r Rect) MidRight() (x, y float64)
- func (r Rect) MidTop() (x, y float64)
- func (r *Rect) Move(dx, dy float64)
- func (r Rect) Moved(dx, dy float64) Rect
- func (r *Rect) Normalize()
- func (r Rect) Normalized() Rect
- func (r Rect) Right() float64
- func (r *Rect) SetBottom(bottom float64)
- func (r *Rect) SetBottomLeft(x, y float64)
- func (r *Rect) SetBottomRight(x, y float64)
- func (r *Rect) SetCenter(x, y float64)
- func (r *Rect) SetCenterX(x float64)
- func (r *Rect) SetCenterY(y float64)
- func (r *Rect) SetHeight(h float64)
- func (r *Rect) SetLeft(left float64)
- func (r *Rect) SetMidBottom(x, y float64)
- func (r *Rect) SetMidLeft(x, y float64)
- func (r *Rect) SetMidRight(x, y float64)
- func (r *Rect) SetMidTop(x, y float64)
- func (r *Rect) SetRight(right float64)
- func (r *Rect) SetSize(w, h float64)
- func (r *Rect) SetTop(top float64)
- func (r *Rect) SetTopLeft(x, y float64)
- func (r *Rect) SetTopRight(x, y float64)
- func (r *Rect) SetWidth(w float64)
- func (r Rect) Size() (w, h float64)
- func (r Rect) Top() (top float64)
- func (r Rect) TopLeft() (x, y float64)
- func (r Rect) TopRight() (x, y float64)
- func (r *Rect) Union(other Rect)
- func (r Rect) Unioned(other Rect) Rect
- func (r Rect) Width() float64
- type Vec
- func (v *Vec) Add(v2 Vec)
- func (v Vec) Angle() float64
- func (v Vec) AngleFrom(v2 Vec) float64
- func (v Vec) Dist(v2 Vec) float64
- func (v Vec) Dist2(v2 Vec) float64
- func (v *Vec) Div(n float64)
- func (v Vec) DividedBy(n float64) Vec
- func (v Vec) Dot(v2 Vec) float64
- func (v Vec) Equals(v2 Vec, e float64) bool
- func (v Vec) Len() float64
- func (v Vec) Len2() float64
- func (v *Vec) Limit(len float64)
- func (v Vec) Limited(len float64) Vec
- func (v Vec) Minus(v2 Vec) Vec
- func (v *Vec) Mul(n float64)
- func (v *Vec) Normalize()
- func (v Vec) Normalized() Vec
- func (v Vec) Plus(v2 Vec) Vec
- func (v *Vec) Project(v2 Vec)
- func (v Vec) Projected(v2 Vec) Vec
- func (v *Vec) Rotate(rad float64)
- func (v Vec) Rotated(rad float64) Vec
- func (v *Vec) SetLen(l float64)
- func (v *Vec) Sub(v2 Vec)
- func (v Vec) Times(n float64) Vec
- func (v Vec) WithLen(l float64) Vec
- type VecGen
- func DynamicVec(v *Vec) VecGen
- func OffsetVec(gen VecGen, offset VecGen) VecGen
- func RandVecArc(minRadius, maxRadius, minRadians, maxRadians float64) VecGen
- func RandVecCircle(minRadius, maxRadius float64) VecGen
- func RandVecRect(rect Rect) VecGen
- func RandVecRects(rects []Rect) VecGen
- func StaticVec(v Vec) VecGen
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NumGen ¶
type NumGen func() float64
NumGen (Number Generator) is a function that returns a number.
func RandRadius ¶
RandRadius returns a NumGen that returns a uniform circle radius between minR and maxR.
type Rect ¶
type Rect struct {
X, Y, W, H float64
}
Rect defines rectangular coordinates.
func RectUnion ¶
RectUnion returns a Rect that contains all the given Rects. An empty list returns a Rect with size 0.
func (Rect) BottomLeft ¶
BottomLeft returns the coordinates of the bottom left corner.
func (Rect) BottomRight ¶
BottomRight returns the coordinates of the bottom right corner.
func (*Rect) Clamp ¶
Clamp moves this Rect so that it is within bounds. If it is too large than it is centered within bounds.
func (Rect) Clamped ¶
Clamped returns a new Rect that is moved to be within bounds. If it is too large than it is centered within bounds.
func (Rect) CollideList ¶
CollideList returns the index of the first Rect this one collides with, or -1 if it collides with none.
func (Rect) CollideListAll ¶
CollideListAll returns a list of indices of the Rects that collide with this one, or an empty list if none.
func (Rect) CollidePoint ¶
CollidePoint returns true if the point is within the Rect. A point along the right or bottom edge is not considered inside.
func (Rect) CollideRect ¶
CollideRect returns true if the Rects overlap.
func (*Rect) Fit ¶
Fit modifies this Rect so that it is moved and resized to fit within bounds while maintaining its original aspect ratio.
func (Rect) Fitted ¶
Fitted returns a new Rect that is moved and resized to fit within bounds while maintaining its original aspect ratio.
func (*Rect) Inflate ¶
Inflate keeps the same center but changes the size by the given amount, in place.
func (Rect) Inflated ¶
Inflated returns a new Rect with the same center whose size is chaged by the given amount.
func (Rect) Intersect ¶
Intersect returns a new Rect that marks the area where the two overlap. If there is no intersection the returned Rect will have 0 size.
func (Rect) MidBottom ¶
MidBottom returns the coordinates at the bottom of the rectangle below the center.
func (Rect) MidLeft ¶
MidLeft returns the coordinates at the left of the rectangle in line with the center.
func (Rect) MidRight ¶
MidRight returns the coordinates at the right of the rectangle in line with the center.
func (*Rect) Normalize ¶
func (r *Rect) Normalize()
Normalize fips the Rect in place if its size is negative.
func (Rect) Normalized ¶
Normalized returns a fipped but equivalent Rect if its size is negative.
func (*Rect) SetBottomLeft ¶
SetBottomLeft set the coordinates of the bottom left corner.
func (*Rect) SetBottomRight ¶
SetBottomRight sets the coordinates of the bottom right corner.
func (*Rect) SetCenterX ¶
SetCenterX sets the center x coordinates.
func (*Rect) SetCenterY ¶
SetCenterY set the center y coordinates.
func (*Rect) SetMidBottom ¶
SetMidBottom sets the coordinates at the bottom of the rectangle below the center.
func (*Rect) SetMidLeft ¶
SetMidLeft sets the coordinates at the left of the rectangle in line with the center.
func (*Rect) SetMidRight ¶
SetMidRight sets the coordinates at the right of the rectangle in line with the center.
func (*Rect) SetMidTop ¶
SetMidTop sets the coordinates at the top of the rectangle above the center.
func (*Rect) SetTopLeft ¶
SetTopLeft sets the coordinates of the top left corner.
func (*Rect) SetTopRight ¶
SetTopRight sets the coordinates of the top right corner.
type Vec ¶
type Vec struct {
X, Y float64
}
Vec is a 2D vector. Many of the functions for Vec have two versions, one that modifies the Vec and one that returns a new Vec. Their names follow a convention that is hopefully inuitive. For example, when working with Vec as a value you use v1.Plus(v2) which returns a new value and reads like when working with other value types such as "1 + 2".
func (Vec) Angle ¶
Angle returns the radians relative to the positive x-axis (counterclockwise in screen coordinates). The returned value is in the range [-π, π).
func (Vec) AngleFrom ¶
AngleFrom returns the radians from v2 to v (counterclockwise in screen coordinates). The returned value is in the range [-π, π).
func (Vec) Equals ¶
Equals returns true if the corresponding components of the vectors are within the error e.
func (*Vec) Limit ¶
Limit constrains the length of the vector be no greater than len. If the vector is already less than len then no change is made.
func (Vec) Limited ¶
Limited returns a new vector in the same direction as v with length no greater than len. The vector returned will be equivalent to v if v.Len() <= len.
func (*Vec) Normalize ¶
func (v *Vec) Normalize()
Normalize modifies v to be of length one in the same direction.
func (Vec) Normalized ¶
Normalized returns a new vector of length one in the same direction as v.
func (*Vec) Rotate ¶
Rotate rotates the vector (counterclockwise in screen coordinates) by the given radians.
func (Vec) Rotated ¶
Rotated returns a new vector that is equal to this one rotated (counterclockwise in screen coordinates) by the given radians.
func (*Vec) SetLen ¶
SetLen sets the length of the vector. Negative lengths will flip the vectors direction. If v's length is zero then it will remain unchanged.
type VecGen ¶
type VecGen func() Vec
VecGen (Vector Generator) is a function that returns a vector.
func DynamicVec ¶
DynamicVec returns a VecGen that always returns a copy of the vector pointed to by v.
func OffsetVec ¶
OffsetVec returns a VecGen that adds offset to gen. For example, if you wanted to use RandCircle as an initial position you might use
OffsetVec(RandVecCircle(5, 10), StaticVec(Vec{X: 100, Y: 100}))
to center the circle at position 100, 100.
func RandVecArc ¶
RandVecArc returns a VecGen that will generate a random vector within the slice of a circle defined by the parameters. The radians are relative to the +x axis. Negative radii are undefined.
func RandVecCircle ¶
RandVecCircle returns a VecGen that will generate a random vector within the given radii. Negative radii are undefined.
func RandVecRect ¶
RandVecRect returns a VecGen that will generate a random vector within the given Rect.
func RandVecRects ¶
RandVecRects returns a VecGen that will generate a random vector that is uniformly distributed between all the given rects. If the slice given is empty then the zero vector is returned.