Documentation
¶
Overview ¶
Package geom provides Vector2 and the shapes Circle, Rect, and Segment for spatial calculations, along with Lerp and easing curves for interpolation.
Index ¶
- func EaseInCubic(t float64) float64
- func EaseInOutCubic(t float64) float64
- func EaseInOutQuad(t float64) float64
- func EaseInQuad(t float64) float64
- func EaseLinear(t float64) float64
- func EaseNames() []string
- func EaseOutCubic(t float64) float64
- func EaseOutQuad(t float64) float64
- func Lerp(from, to, weight float64) float64
- type Circle
- type Ease
- type Rect
- func (r Rect) Area() float64
- func (r Rect) BoundingBox() Rect
- func (r Rect) Center() Vector2
- func (r Rect) ClosestPoint(point Vector2) Vector2
- func (r Rect) Contains(point Vector2) bool
- func (r Rect) DistanceSquared(point Vector2) float64
- func (r Rect) Expand(amount float64) Rect
- func (r Rect) Extents() Vector2
- func (r Rect) Height() float64
- func (r Rect) IsEmpty() bool
- func (r Rect) IsValid() bool
- func (r Rect) Normalize() Rect
- func (r Rect) OverlapsOrTouches(other Rect) bool
- func (r Rect) Size() Vector2
- func (r Rect) String() string
- func (r Rect) Union(other Rect) Rect
- func (r Rect) Width() float64
- type Segment
- type Vector2
- func (v Vector2) Add(other Vector2) Vector2
- func (v Vector2) AlmostEqual(other Vector2, epsilon float64) bool
- func (v Vector2) Angle(other Vector2) float64
- func (v Vector2) AngleDeg(other Vector2) float64
- func (v Vector2) Clamp(min, max Vector2) Vector2
- func (v Vector2) ClampMagnitude(maxLength float64) Vector2
- func (v Vector2) Cross(other Vector2) float64
- func (v Vector2) Distance(other Vector2) float64
- func (v Vector2) DistanceSquared(other Vector2) float64
- func (v Vector2) Div(scalar float64) Vector2
- func (v Vector2) Dot(other Vector2) float64
- func (v Vector2) IsZero() bool
- func (v Vector2) Length() float64
- func (v Vector2) LengthSquared() float64
- func (v Vector2) Lerp(other Vector2, t float64) Vector2
- func (v Vector2) Max(other Vector2) Vector2
- func (v Vector2) Min(other Vector2) Vector2
- func (v Vector2) Mul(scalar float64) Vector2
- func (v Vector2) Neg() Vector2
- func (v Vector2) Normalize() Vector2
- func (v Vector2) Project(onto Vector2) Vector2
- func (v Vector2) Reflect(normal Vector2) Vector2
- func (v Vector2) Rotate(angle float64) Vector2
- func (v Vector2) String() string
- func (v Vector2) Sub(other Vector2) Vector2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EaseInCubic ¶ added in v0.2.0
EaseInCubic returns a cubic easing weight that starts slowly and accelerates.
func EaseInOutCubic ¶ added in v0.2.0
EaseInOutCubic returns a cubic easing weight that accelerates in the first half and decelerates in the second.
func EaseInOutQuad ¶ added in v0.2.0
EaseInOutQuad returns a quadratic easing weight that accelerates in the first half and decelerates in the second.
func EaseInQuad ¶ added in v0.2.0
EaseInQuad returns a quadratic easing weight that starts slowly and accelerates.
func EaseLinear ¶ added in v0.2.0
EaseLinear returns t unchanged for constant-speed interpolation.
func EaseNames ¶ added in v0.4.0
func EaseNames() []string
EaseNames returns the registered ease names in unspecified order.
func EaseOutCubic ¶ added in v0.2.0
EaseOutCubic returns a cubic easing weight that starts quickly and decelerates.
func EaseOutQuad ¶ added in v0.2.0
EaseOutQuad returns a quadratic easing weight that starts quickly and decelerates.
Types ¶
type Circle ¶ added in v0.0.2
type Circle struct {
// Center is the center point.
Center Vector2
// Radius is the radius; its magnitude is used, so negative values behave
// like their positive counterparts.
Radius float64
}
Circle is a two-dimensional circle represented by its center and radius.
func (Circle) BoundingBox ¶ added in v0.0.2
BoundingBox returns the smallest Rect containing c.
func (Circle) Circumference ¶ added in v0.0.2
Circumference returns the circle's circumference.
func (Circle) Contains ¶ added in v0.0.2
Contains reports whether point lies inside or on the circle's boundary.
func (Circle) OverlapsOrTouches ¶ added in v0.1.0
OverlapsOrTouches reports whether c and other overlap or share a boundary point.
func (Circle) OverlapsOrTouchesRect ¶ added in v0.1.0
OverlapsOrTouchesRect reports whether c overlaps or touches r. It returns false when r is invalid.
type Ease ¶ added in v0.2.0
Ease maps normalized time to an interpolation weight. Use the result with Lerp or Vector2.Lerp to shape motion.
The curves provided by this package map [0, 1] to [0, 1], with endpoints at 0 and 1. They do not clamp inputs outside this range.
func EaseByName ¶ added in v0.4.0
EaseByName returns the registered ease for name and whether one exists.
type Rect ¶
type Rect struct {
// Min is the lower coordinate bound on each axis.
Min Vector2
// Max is the upper coordinate bound on each axis.
Max Vector2
}
Rect is a two-dimensional axis-aligned bounding rectangle. Canonical rectangles have Min no greater than Max on either axis.
func RectFromCenterSize ¶
RectFromCenterSize returns a rectangle centered at center with the given size. Negative size components produce the same canonical bounds as their absolute values.
func RectFromMinMax ¶
RectFromMinMax returns a rectangle from two opposite corners. The corners are normalized so Min is no greater than Max on either axis.
func (Rect) Area ¶
Area returns the rectangle's area. Invalid or non-canonical rectangles have zero area.
func (Rect) BoundingBox ¶
BoundingBox returns r because a rectangle is already axis-aligned.
func (Rect) ClosestPoint ¶
ClosestPoint returns the point in r nearest to point. An invalid rectangle returns the zero vector.
func (Rect) DistanceSquared ¶
DistanceSquared returns the squared distance from point to r. It returns zero for points inside or on the rectangle, and for invalid rectangles.
func (Rect) Expand ¶
Expand grows r outward by amount on every side. Negative amounts shrink the rectangle and clamp each extent at zero.
func (Rect) Height ¶
Height returns the distance between the rectangle's horizontal sides. It is negative when Max.Y is less than Min.Y.
func (Rect) OverlapsOrTouches ¶
OverlapsOrTouches reports whether two rectangles overlap or share any boundary point.
type Segment ¶ added in v0.0.2
type Segment struct {
// Start is one endpoint of the segment.
Start Vector2
// End is the other endpoint of the segment.
End Vector2
}
Segment is a finite line segment between Start and End.
func (Segment) BoundingBox ¶ added in v0.0.2
BoundingBox returns the canonical axis-aligned Rect containing s.
func (Segment) ClosestPoint ¶ added in v0.0.2
ClosestPoint returns the point on the segment nearest to point. A zero-length segment returns its single endpoint.
func (Segment) DistanceToPoint ¶ added in v0.0.2
DistanceToPoint returns the shortest distance from point to s. Points on the segment have zero distance.
type Vector2 ¶
type Vector2 struct {
// X is the horizontal component.
X float64 `json:"x"`
// Y is the vertical component.
Y float64 `json:"y"`
}
Vector2 is a two-dimensional vector.
func (Vector2) AlmostEqual ¶
AlmostEqual reports whether the components of v and other differ by no more than epsilon. Negative epsilon always returns false.
func (Vector2) Angle ¶
Angle returns the signed angle in radians from v to other. Positive values indicate counter-clockwise rotation; zero vectors have no meaningful angle.
func (Vector2) Clamp ¶
Clamp clamps each component of v to the corresponding range in min and max. Reversed bounds are normalized per component before clamping.
func (Vector2) ClampMagnitude ¶
ClampMagnitude limits v's magnitude to maxLength without changing its direction. A non-positive maxLength returns a zero vector.
func (Vector2) Cross ¶
Cross returns the scalar two-dimensional cross product of v and other. A positive result means other is counter-clockwise from v; a negative result means clockwise.
func (Vector2) Distance ¶
Distance returns the Euclidean distance between v and other. Use DistanceSquared when only comparing distances.
func (Vector2) DistanceSquared ¶
DistanceSquared returns the squared Euclidean distance between v and other. It avoids a square root when only comparing distances.
func (Vector2) Div ¶
Div returns v divided by scalar. If the scalar is zero, it returns a zero vector to avoid infinities or NaNs.
func (Vector2) IsZero ¶
IsZero reports whether both components of v are exactly zero. It is not an epsilon comparison and returns false for non-finite values.
func (Vector2) LengthSquared ¶
LengthSquared returns the squared Euclidean magnitude of v.
func (Vector2) Lerp ¶
Lerp linearly interpolates from v to other by t. Values outside [0, 1] extrapolate beyond the endpoints.
func (Vector2) Max ¶
Max returns a vector containing the maximum components of this vector and another vector.
func (Vector2) Min ¶
Min returns a vector containing the minimum components of this vector and another vector.
func (Vector2) Normalize ¶
Normalize returns a unit vector in v's direction. A zero vector returns a zero vector; non-finite input propagates non-finite results.
func (Vector2) Project ¶
Project returns the component of v parallel to onto. Projection onto a zero vector returns a zero vector.
func (Vector2) Reflect ¶
Reflect returns v reflected across a surface with the given normal. The normal must be unit length; a zero normal returns v unchanged.
func (Vector2) Rotate ¶
Rotate returns v rotated counter-clockwise by angle radians. Rotation preserves the vector's magnitude apart from floating-point error.