geom

package
v0.0.0-...-883d5d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2024 License: MPL-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package geom provides geometry primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PointSegmentDistance

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

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

func NewHorizontalInsets[T xmath.Numeric](amount T) Insets[T]

NewHorizontalInsets creates a new Insets whose left and right edges have the specified value.

func NewUniformInsets

func NewUniformInsets[T xmath.Numeric](amount T) Insets[T]

NewUniformInsets creates a new Insets whose edges all have the same value.

func NewVerticalInsets

func NewVerticalInsets[T xmath.Numeric](amount T) Insets[T]

NewVerticalInsets creates a new Insets whose top and bottom edges have the specified value.

func (*Insets[T]) Add

func (i *Insets[T]) Add(insets Insets[T]) *Insets[T]

Add modifies this Insets by adding the supplied Insets. Returns itself for easy chaining.

func (*Insets[T]) Height

func (i *Insets[T]) Height() T

Height returns the sum of the top and bottom insets.

func (*Insets[T]) String

func (i *Insets[T]) String() string

String implements the fmt.Stringer interface.

func (*Insets[T]) Subtract

func (i *Insets[T]) Subtract(insets Insets[T]) *Insets[T]

Subtract modifies this Insets by subtracting the supplied Insets. Returns itself for easy chaining.

func (*Insets[T]) Width

func (i *Insets[T]) Width() T

Width returns the sum of the left and right insets.

type Insets32

type Insets32 = Insets[float32]

Insets32 is an alias for the float32 version of Insets.

type Insets64

type Insets64 = Insets[float64]

Insets64 is an alias for the float64 version of Insets.

type Matrix2D

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

func NewIdentityMatrix2D[T constraints.Float]() *Matrix2D[T]

NewIdentityMatrix2D creates a new identity transformation 2D matrix.

func NewRotationByDegreesMatrix2D

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

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

func NewScaleMatrix2D[T constraints.Float](sx, sy T) *Matrix2D[T]

NewScaleMatrix2D creates a new 2D matrix that scales by 'sx' and 'sy'.

func NewTranslationMatrix2D

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]) Multiply

func (m *Matrix2D[T]) Multiply(other *Matrix2D[T])

Multiply this matrix by 'other'.

func (*Matrix2D[T]) Rotate

func (m *Matrix2D[T]) Rotate(radians T)

Rotate this matrix by 'radians'. Positive values are clockwise.

func (*Matrix2D[T]) Scale

func (m *Matrix2D[T]) Scale(sx, sy T)

Scale this matrix by 'sx' and 'sy'.

func (*Matrix2D[T]) TransformDistance

func (m *Matrix2D[T]) TransformDistance(distance Size[T]) Size[T]

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

func (m *Matrix2D[T]) TransformPoint(where Point[T]) Point[T]

TransformPoint returns the result of transforming the point by this matrix.

func (*Matrix2D[T]) Translate

func (m *Matrix2D[T]) Translate(tx, ty T)

Translate this matrix by 'tx' and 'ty'.

type Matrix2D32

type Matrix2D32 = Matrix2D[float32]

Matrix2D32 is an alias for the float32 version of Matrix2D.

type Matrix2D64

type Matrix2D64 = Matrix2D[float64]

Matrix2D64 is an alias for the float64 version of Matrix2D.

type Point

type Point[T xmath.Numeric] struct {
	X T `json:"x"`
	Y T `json:"y"`
}

Point defines a location.

func LineIntersection

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 NewPoint

func NewPoint[T xmath.Numeric](x, y T) Point[T]

NewPoint creates a new Point.

func NewPointPtr

func NewPointPtr[T xmath.Numeric](x, y T) *Point[T]

NewPointPtr creates a new *Point.

func (*Point[T]) Add

func (p *Point[T]) Add(pt Point[T]) *Point[T]

Add modifies this Point by adding the supplied coordinates. Returns itself for easy chaining.

func (*Point[T]) Align

func (p *Point[T]) Align() *Point[T]

Align modifies this Point to align with integer coordinates. Returns itself for easy chaining.

func (*Point[T]) Negate

func (p *Point[T]) Negate() *Point[T]

Negate modifies this Point by negating both the X and Y coordinates.

func (*Point[T]) String

func (p *Point[T]) String() string

String implements the fmt.Stringer interface.

func (*Point[T]) Subtract

func (p *Point[T]) Subtract(pt Point[T]) *Point[T]

Subtract modifies this Point by subtracting the supplied coordinates. Returns itself for easy chaining.

type Pt32

type Pt32 = Point[float32]

Pt32 is an alias for the float32 version of Point.

type Pt64

type Pt64 = Point[float64]

Pt64 is an alias for the float64 version of Point.

type Rect

type Rect[T xmath.Numeric] struct {
	Point[T] `json:",inline"`
	Size[T]  `json:",inline"`
}

Rect defines a rectangle.

func NewRect

func NewRect[T xmath.Numeric](x, y, width, height T) Rect[T]

NewRect creates a new Rect.

func NewRectPtr

func NewRectPtr[T xmath.Numeric](x, y, width, height T) *Rect[T]

NewRectPtr creates a new *Rect.

func (*Rect[T]) AddPoint

func (r *Rect[T]) AddPoint(pt Point[T]) *Rect[T]

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

func (r *Rect[T]) Align() *Rect[T]

Align modifies this rectangle to align with integer coordinates that would encompass the original rectangle. Returns itself for easy chaining.

func (Rect[T]) Bottom

func (r Rect[T]) Bottom() T

Bottom returns the bottom edge, or Y + Height.

func (Rect[T]) BottomLeft

func (r Rect[T]) BottomLeft() Point[T]

BottomLeft returns the bottom-left point of the rectangle.

func (Rect[T]) BottomRight

func (r Rect[T]) BottomRight() Point[T]

BottomRight returns the bottom-right point of the rectangle.

func (*Rect[T]) Bounds

func (r *Rect[T]) Bounds() Rect[T]

Bounds merely returns this rectangle.

func (Rect[T]) Center

func (r Rect[T]) Center() Point[T]

Center returns the center 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

func (r Rect[T]) ContainsPoint(pt Point[T]) bool

ContainsPoint returns true if the coordinates are within the Rect.

func (Rect[T]) ContainsRect

func (r Rect[T]) ContainsRect(in Rect[T]) bool

ContainsRect returns true if this Rect fully contains the passed in Rect.

func (*Rect[T]) CopyAndZeroLocation

func (r *Rect[T]) CopyAndZeroLocation() Rect[T]

CopyAndZeroLocation creates a new copy of the Rect and sets the location of the copy to 0,0.

func (*Rect[T]) Inset

func (r *Rect[T]) Inset(insets Insets[T]) *Rect[T]

Inset this Rect by the specified Insets. Returns itself for easy chaining.

func (*Rect[T]) InsetUniform

func (r *Rect[T]) InsetUniform(amount T) *Rect[T]

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

func (r *Rect[T]) Intersect(other Rect[T]) *Rect[T]

Intersect this Rect with another Rect, storing the result into this Rect. Returns itself for easy chaining.

func (Rect[T]) Intersects

func (r Rect[T]) Intersects(other Rect[T]) bool

Intersects returns true if this rect and the other rect intersect.

func (Rect[T]) IntersectsLine

func (r Rect[T]) IntersectsLine(start, end Point[T]) bool

IntersectsLine returns true if this rect and the line described by start and end intersect.

func (Rect[T]) IsEmpty

func (r Rect[T]) IsEmpty() bool

IsEmpty returns true if either the width or height is zero or less.

func (Rect[T]) Max

func (r Rect[T]) Max() Point[T]

Max returns the bottom right corner of the rectangle.

func (Rect[T]) Right

func (r Rect[T]) Right() T

Right returns the right edge, or X + Width.

func (*Rect[T]) String

func (r *Rect[T]) String() string

String implements the fmt.Stringer interface.

func (Rect[T]) TopLeft

func (r Rect[T]) TopLeft() Point[T]

TopLeft returns the top-left point of the rectangle.

func (Rect[T]) TopRight

func (r Rect[T]) TopRight() Point[T]

TopRight returns the top-right point of the rectangle.

func (*Rect[T]) Union

func (r *Rect[T]) Union(other Rect[T]) *Rect[T]

Union this Rect with another Rect, storing the result into this Rect. Returns itself for easy chaining.

type Rect32

type Rect32 = Rect[float32]

Rect32 is an alias for the float32 version of Rect.

type Rect64

type Rect64 = Rect[float64]

Rect64 is an alias for the float64 version of Rect.

type Size

type Size[T xmath.Numeric] struct {
	Width  T `json:"w"`
	Height T `json:"h"`
}

Size defines a width and height.

func NewSize

func NewSize[T xmath.Numeric](width, height T) Size[T]

NewSize creates a new Size.

func NewSizePtr

func NewSizePtr[T xmath.Numeric](x, y T) *Size[T]

NewSizePtr creates a new *Size.

func (*Size[T]) Add

func (s *Size[T]) Add(size Size[T]) *Size[T]

Add modifies this Size by adding the supplied Size. Returns itself for easy chaining.

func (*Size[T]) AddInsets

func (s *Size[T]) AddInsets(insets Insets[T]) *Size[T]

AddInsets modifies this Size by expanding it to accommodate the specified insets. Returns itself for easy chaining.

func (*Size[T]) ConstrainForHint

func (s *Size[T]) ConstrainForHint(hint Size[T]) *Size[T]

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

func (s *Size[T]) GrowToInteger() *Size[T]

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

func (s *Size[T]) Max(other Size[T]) *Size[T]

Max modifies this Size to contain the largest values between itself and 'other'. Returns itself for easy chaining.

func (*Size[T]) Min

func (s *Size[T]) Min(other Size[T]) *Size[T]

Min modifies this Size to contain the smallest values between itself and 'other'. Returns itself for easy chaining.

func (*Size[T]) String

func (s *Size[T]) String() string

String implements the fmt.Stringer interface.

func (*Size[T]) Subtract

func (s *Size[T]) Subtract(size Size[T]) *Size[T]

Subtract modifies this Size by subtracting the supplied Size. Returns itself for easy chaining.

func (*Size[T]) SubtractInsets

func (s *Size[T]) SubtractInsets(insets Insets[T]) *Size[T]

SubtractInsets modifies this Size by reducing it to accommodate the specified insets. Returns itself for easy chaining.

type Size32

type Size32 = Size[float32]

Size32 is an alias for the float32 version of Size.

type Size64

type Size64 = Size[float64]

Size64 is an alias for the float64 version of Size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL