Documentation ¶
Overview ¶
Package geom provides geometry primitives.
Index ¶
- func PointSegmentDistance[T constraints.Float](s1, s2, p Point[T]) T
- func PointSegmentDistanceSquared[T constraints.Float](s1, s2, p Point[T]) T
- type Insets
- type Matrix2D
- func NewIdentityMatrix2D[T constraints.Float]() *Matrix2D[T]
- func NewRotationByDegreesMatrix2D[T constraints.Float](degrees T) *Matrix2D[T]
- func NewRotationMatrix2D[T constraints.Float](radians T) *Matrix2D[T]
- func NewScaleMatrix2D[T constraints.Float](sx, sy T) *Matrix2D[T]
- func NewTranslationMatrix2D[T constraints.Float](tx, ty T) *Matrix2D[T]
- type Point
- type Rect
- func (r *Rect[T]) AddPoint(pt Point[T]) *Rect[T]
- func (r *Rect[T]) Align() *Rect[T]
- func (r Rect[T]) Bottom() T
- func (r Rect[T]) BottomLeft() Point[T]
- func (r Rect[T]) BottomRight() Point[T]
- func (r *Rect[T]) Bounds() Rect[T]
- func (r Rect[T]) Center() Point[T]
- func (r Rect[T]) CenterX() T
- func (r Rect[T]) CenterY() T
- func (r Rect[T]) ContainsPoint(pt Point[T]) bool
- func (r Rect[T]) ContainsRect(in Rect[T]) bool
- func (r *Rect[T]) CopyAndZeroLocation() Rect[T]
- func (r *Rect[T]) Inset(insets Insets[T]) *Rect[T]
- func (r *Rect[T]) InsetUniform(amount T) *Rect[T]
- func (r *Rect[T]) Intersect(other Rect[T]) *Rect[T]
- func (r Rect[T]) Intersects(other Rect[T]) bool
- func (r Rect[T]) IntersectsLine(start, end Point[T]) bool
- func (r Rect[T]) IsEmpty() bool
- func (r Rect[T]) Max() Point[T]
- func (r Rect[T]) Right() T
- func (r *Rect[T]) String() string
- func (r Rect[T]) TopLeft() Point[T]
- func (r Rect[T]) TopRight() Point[T]
- func (r *Rect[T]) Union(other Rect[T]) *Rect[T]
- type Size
- func (s *Size[T]) Add(size Size[T]) *Size[T]
- func (s *Size[T]) AddInsets(insets Insets[T]) *Size[T]
- func (s *Size[T]) ConstrainForHint(hint Size[T]) *Size[T]
- func (s *Size[T]) GrowToInteger() *Size[T]
- func (s *Size[T]) Max(other Size[T]) *Size[T]
- func (s *Size[T]) Min(other Size[T]) *Size[T]
- func (s *Size[T]) String() string
- func (s *Size[T]) Subtract(size Size[T]) *Size[T]
- func (s *Size[T]) SubtractInsets(insets Insets[T]) *Size[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PointSegmentDistance ¶ added in v1.13.0
func PointSegmentDistance[T constraints.Float](s1, s2, p Point[T]) T
PointSegmentDistance returns the distance from a point to a line segment. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this function returns 0.
func PointSegmentDistanceSquared ¶ added in v1.13.0
func PointSegmentDistanceSquared[T constraints.Float](s1, s2, p Point[T]) T
PointSegmentDistanceSquared returns the square of the distance from a point to a line segment. The distance measured is the distance between the specified point and the closest point between the specified end points. If the specified point intersects the line segment in between the end points, this function returns 0.
Types ¶
type Insets ¶
type Insets[T xmath.Numeric] struct { Top T `json:"top"` Left T `json:"left"` Bottom T `json:"bottom"` Right T `json:"right"` }
Insets defines margins on each side of a rectangle.
func NewHorizontalInsets ¶
NewHorizontalInsets creates a new Insets whose left and right edges have the specified value.
func NewUniformInsets ¶
NewUniformInsets creates a new Insets whose edges all have the same value.
func NewVerticalInsets ¶
NewVerticalInsets creates a new Insets whose top and bottom edges have the specified value.
func (*Insets[T]) Add ¶
Add modifies this Insets by adding the supplied Insets. Returns itself for easy chaining.
func (*Insets[T]) Height ¶ added in v1.69.0
func (i *Insets[T]) Height() T
Height returns the sum of the top and bottom insets.
type Matrix2D ¶ added in v1.35.0
type Matrix2D[T constraints.Float] struct { ScaleX T SkewX T TransX T SkewY T ScaleY T TransY T }
Matrix2D provides a 2D matrix.
func NewIdentityMatrix2D ¶ added in v1.35.0
func NewIdentityMatrix2D[T constraints.Float]() *Matrix2D[T]
NewIdentityMatrix2D creates a new identity transformation 2D matrix.
func NewRotationByDegreesMatrix2D ¶ added in v1.35.0
func NewRotationByDegreesMatrix2D[T constraints.Float](degrees T) *Matrix2D[T]
NewRotationByDegreesMatrix2D creates a new 2D matrix that rotates by 'degrees'. Positive values are clockwise.
func NewRotationMatrix2D ¶ added in v1.35.0
func NewRotationMatrix2D[T constraints.Float](radians T) *Matrix2D[T]
NewRotationMatrix2D creates a new 2D matrix that rotates by 'radians'. Positive values are clockwise.
func NewScaleMatrix2D ¶ added in v1.35.0
func NewScaleMatrix2D[T constraints.Float](sx, sy T) *Matrix2D[T]
NewScaleMatrix2D creates a new 2D matrix that scales by 'sx' and 'sy'.
func NewTranslationMatrix2D ¶ added in v1.35.0
func NewTranslationMatrix2D[T constraints.Float](tx, ty T) *Matrix2D[T]
NewTranslationMatrix2D creates a new 2D matrix that translates by 'tx' and 'ty'.
func (*Matrix2D[T]) Rotate ¶ added in v1.35.0
func (m *Matrix2D[T]) Rotate(radians T)
Rotate this matrix by 'radians'. Positive values are clockwise.
func (*Matrix2D[T]) Scale ¶ added in v1.35.0
func (m *Matrix2D[T]) Scale(sx, sy T)
Scale this matrix by 'sx' and 'sy'.
func (*Matrix2D[T]) TransformDistance ¶ added in v1.35.0
TransformDistance returns the result of transforming the distance vector by this matrix. This is similar to TransformPoint(), except that the translation components of the transformation are ignored.
func (*Matrix2D[T]) TransformPoint ¶ added in v1.35.0
TransformPoint returns the result of transforming the point by this matrix.
type Point ¶
Point defines a location.
func LineIntersection ¶ added in v1.13.0
func LineIntersection[T constraints.Float](a1, a2, b1, b2 Point[T]) []Point[T]
LineIntersection determines the intersection of two lines, if any. A return of no points indicates no intersection. One point indicates intersection at a single point. Two points indicates an overlapping line segment.
func NewPointPtr ¶ added in v1.8.0
NewPointPtr creates a new *Point.
func (*Point[T]) Add ¶
Add modifies this Point by adding the supplied coordinates. Returns itself for easy chaining.
func (*Point[T]) Align ¶
Align modifies this Point to align with integer coordinates. Returns itself for easy chaining.
func (*Point[T]) Negate ¶ added in v1.36.0
Negate modifies this Point by negating both the X and Y coordinates.
type Rect ¶
Rect defines a rectangle.
func NewRectPtr ¶ added in v1.8.0
NewRectPtr creates a new *Rect.
func (*Rect[T]) AddPoint ¶ added in v1.30.0
AddPoint adds a Point to this Rect. If the Rect has a negative width or height, then the Rect's upper-left corner will be set to the Point and its width and height will be set to 0. Returns itself for easy chaining.
func (*Rect[T]) Align ¶
Align modifies this rectangle to align with integer coordinates that would encompass the original rectangle. Returns itself for easy chaining.
func (Rect[T]) Bottom ¶ added in v1.13.0
func (r Rect[T]) Bottom() T
Bottom returns the bottom edge, or Y + Height.
func (Rect[T]) BottomLeft ¶ added in v1.28.0
BottomLeft returns the bottom-left point of the rectangle.
func (Rect[T]) BottomRight ¶ added in v1.28.0
BottomRight returns the bottom-right point of the rectangle.
func (Rect[T]) CenterX ¶
func (r Rect[T]) CenterX() T
CenterX returns the center x-coordinate of the rectangle.
func (Rect[T]) CenterY ¶
func (r Rect[T]) CenterY() T
CenterY returns the center y-coordinate of the rectangle.
func (Rect[T]) ContainsPoint ¶
ContainsPoint returns true if the coordinates are within the Rect.
func (Rect[T]) ContainsRect ¶
ContainsRect returns true if this Rect fully contains the passed in Rect.
func (*Rect[T]) CopyAndZeroLocation ¶
CopyAndZeroLocation creates a new copy of the Rect and sets the location of the copy to 0,0.
func (*Rect[T]) InsetUniform ¶
InsetUniform insets this Rect by the specified amount on all sides. Positive values make the Rect smaller, while negative values make it larger. Returns itself for easy chaining.
func (*Rect[T]) Intersect ¶
Intersect this Rect with another Rect, storing the result into this Rect. Returns itself for easy chaining.
func (Rect[T]) Intersects ¶ added in v1.6.0
Intersects returns true if this rect and the other rect intersect.
func (Rect[T]) IntersectsLine ¶ added in v1.28.0
IntersectsLine returns true if this rect and the line described by start and end intersect.
func (Rect[T]) Right ¶ added in v1.13.0
func (r Rect[T]) Right() T
Right returns the right edge, or X + Width.
type Size ¶
Size defines a width and height.
func NewSizePtr ¶ added in v1.8.0
NewSizePtr creates a new *Size.
func (*Size[T]) Add ¶
Add modifies this Size by adding the supplied Size. Returns itself for easy chaining.
func (*Size[T]) AddInsets ¶
AddInsets modifies this Size by expanding it to accommodate the specified insets. Returns itself for easy chaining.
func (*Size[T]) ConstrainForHint ¶
ConstrainForHint ensures this size is no larger than the hint. Hint values less than one are ignored. Returns itself for easy chaining.
func (*Size[T]) GrowToInteger ¶
GrowToInteger modifies this Size such that its width and height are both the smallest integers greater than or equal to their original values. Returns itself for easy chaining.
func (*Size[T]) Max ¶
Max modifies this Size to contain the largest values between itself and 'other'. Returns itself for easy chaining.
func (*Size[T]) Min ¶
Min modifies this Size to contain the smallest values between itself and 'other'. Returns itself for easy chaining.
func (*Size[T]) Subtract ¶
Subtract modifies this Size by subtracting the supplied Size. Returns itself for easy chaining.
func (*Size[T]) SubtractInsets ¶
SubtractInsets modifies this Size by reducing it to accommodate the specified insets. Returns itself for easy chaining.