Documentation
¶
Overview ¶
Package geometry provides geometric types and operations for 2D space.
Vector2 is the primary type — a generic 2D point/vector supporting addition, subtraction, scaling, distance, magnitude, and unit-vector operations. Rectangle represents an axis-aligned bounding box. These types are used throughout the codebase for world coordinates.
Index ¶
- type Rectangle
- type Vector2
- func (p Vector2) Add(other Vector2) Vector2
- func (p Vector2) AsFloats() (float64, float64)
- func (p Vector2) AsInts() (int, int)
- func (p Vector2) DistanceTo(other Vector2) float64
- func (p Vector2) IsZero() bool
- func (p Vector2) Lerp(other Vector2, t float64) Vector2
- func (p Vector2) Magnitude() float64
- func (v Vector2) MarshalBinary() ([]byte, error)
- func (p Vector2) Max(other Vector2) Vector2
- func (p Vector2) Min(other Vector2) Vector2
- func (p Vector2) Scale(scalar float64) Vector2
- func (p Vector2) String() string
- func (p Vector2) Sub(other Vector2) Vector2
- func (p Vector2) Unit() Vector2
- func (v *Vector2) UnmarshalBinary(data []byte) error
- func (p Vector2) X() float64
- func (p Vector2) Y() float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rectangle ¶
Rectangle represents a rectangular area defined by its minimum and maximum positions.
func NewRectangle ¶
NewRectangle creates and returns a new Rectangle with the given minimum and maximum positions.
func NewRectangleFromPoints ¶
func SquareWithCenter ¶
type Vector2 ¶
type Vector2 struct {
// contains filtered or unexported fields
}
Vector2 represents a 2D point in space.
func NewVector2 ¶
NewVector2 creates and returns a new Vector2 with the given x and y values.
func RandomPointInRectangle ¶
func RandomPointInRectangle(r Rectangle, rng util.Float64Source) Vector2
RandomPointInRectangle returns a random point within the given rectangle.
func Zero2D ¶
func Zero2D() Vector2
Zero2D returns a zero Vector2, which is a vector with both x and y set to 0. It is a convenient way to create a zero vector without needing to specify the values.
func (Vector2) Add ¶
Add returns a new Vector2 that is the sum of the current Vector2 and the given Vector2.
func (Vector2) DistanceTo ¶
DistanceTo calculates the Euclidean distance between two Vector2s.
func (Vector2) Lerp ¶ added in v0.1.14
Lerp linearly interpolates between the current Vector2 and the given Vector2: it returns the current vector when t is 0 and the given vector when t is 1. It does not clamp t, so values outside [0,1] extrapolate along the line through both points. This method uses the form p*(1-t) + other*t to ensure the endpoints are exact in floating point arithmetic (at t=0 it returns p exactly, at t=1 it returns other exactly).
func (Vector2) MarshalBinary ¶ added in v0.1.11
MarshalBinary encodes the vector as 16 big-endian bytes (x then y, IEEE 754 bits). It implements encoding.BinaryMarshaler so vectors, and the engine components holding them, can be persisted in savegames (encoding/gob uses this implementation automatically).
func (Vector2) Max ¶
Max returns a new Vector2 that is the maximum of the current Vector2 and the given Vector2.
func (Vector2) Min ¶
Min returns a new Vector2 that is the minimum of the current Vector2 and the given Vector2.
func (Vector2) Scale ¶
Scale returns a new Vector2 that is the multiplication of the current Vector2 and the given scalar value.
func (Vector2) Sub ¶
Sub returns a new Vector2 that is the difference of the current Vector2 and the given Vector2.
func (*Vector2) UnmarshalBinary ¶ added in v0.1.11
UnmarshalBinary decodes 16 bytes produced by MarshalBinary.