geom

package
v1.74.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MPL-2.0 Imports: 5 Imported by: 61

Documentation

Overview

Package geom provides geometry primitives.

Index

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

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 added in v1.69.0

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 added in v1.24.0

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 added in v1.69.0

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

Width returns the sum of the left and right 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]) Multiply added in v1.35.0

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

Multiply this matrix by 'other'.

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

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 added in v1.35.0

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 added in v1.35.0

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

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

type Point

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

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 NewPoint added in v1.8.0

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

NewPoint creates a new Point.

func NewPointPtr added in v1.8.0

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 added in v1.36.0

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 Rect

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

Rect defines a rectangle.

func NewRect added in v1.8.0

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

NewRect creates a new Rect.

func NewRectPtr added in v1.8.0

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

NewRectPtr creates a new *Rect.

func (*Rect[T]) AddPoint added in v1.30.0

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 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

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

BottomLeft returns the bottom-left point of the rectangle.

func (Rect[T]) BottomRight added in v1.28.0

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

BottomRight returns the bottom-right point of the rectangle.

func (*Rect[T]) Bounds added in v1.31.0

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

Bounds merely returns this rectangle.

func (Rect[T]) Center added in v1.16.0

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 added in v1.6.0

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

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

func (Rect[T]) IntersectsLine added in v1.28.0

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 added in v1.15.0

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

Max returns the bottom right corner of the rectangle.

func (Rect[T]) Right added in v1.13.0

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 added in v1.28.0

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

TopLeft returns the top-left point of the rectangle.

func (Rect[T]) TopRight added in v1.28.0

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 Size

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

Size defines a width and height.

func NewSize added in v1.8.0

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

NewSize creates a new Size.

func NewSizePtr added in v1.8.0

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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