geom

package
v1.122.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MPL-2.0 Imports: 4 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 xmath.Numeric](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 xmath.Numeric](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 ConvertInsets added in v1.100.0

func ConvertInsets[T, F xmath.Numeric](i Insets[F]) Insets[T]

ConvertInsets converts a Insets of type F into one of type T.

func NewHorizontalInsets

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

NewHorizontalInsets returns an Insets whose left and right edges have the specified value.

func NewInsets added in v1.100.0

func NewInsets[T xmath.Numeric](top, left, bottom, right T) Insets[T]

NewInsets returns an Insets with the given values for its edges.

func NewSymmetricInsets added in v1.100.0

func NewSymmetricInsets[T xmath.Numeric](h, v T) Insets[T]

NewSymmetricInsets returns an Insets whose edges match their opposite edge.

func NewUniformInsets

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

NewUniformInsets returns an Insets whose edges all have the same value.

func NewVerticalInsets

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

NewVerticalInsets returns an Insets whose top and bottom edges have the specified value.

func (Insets[T]) Add

func (i Insets[T]) Add(in Insets[T]) Insets[T]

Add returns a new Insets which is the result of adding this Insets with the provided Insets.

func (Insets[T]) Div added in v1.100.0

func (i Insets[T]) Div(value T) Insets[T]

Div returns a new Insets which is the result of dividing the values of this Insets by the value.

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]) Mul added in v1.100.0

func (i Insets[T]) Mul(value T) Insets[T]

Mul returns a new Insets which is the result of multiplying the values of this Insets by the value.

func (Insets[T]) Size added in v1.100.0

func (i Insets[T]) Size() Size[T]

Size returns the Size of the Insets.

func (Insets[T]) String

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

String implements fmt.Stringer.

func (Insets[T]) Sub added in v1.100.0

func (i Insets[T]) Sub(in Insets[T]) Insets[T]

Sub returns a new Insets which is the result of subtracting the provided Insets from this Insets.

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

type Matrix[T constraints.Float] struct {
	ScaleX T `json:"scale_x"`
	SkewX  T `json:"skew_x"`
	TransX T `json:"trans_x"`
	SkewY  T `json:"skew_y"`
	ScaleY T `json:"scale_y"`
	TransY T `json:"trans_y"`
}

Matrix provides a 2D matrix.

func NewIdentityMatrix added in v1.100.0

func NewIdentityMatrix[T constraints.Float]() Matrix[T]

NewIdentityMatrix creates a new identity transformation Matrix.

func NewRotationByDegreesMatrix added in v1.100.0

func NewRotationByDegreesMatrix[T constraints.Float](degrees T) Matrix[T]

NewRotationByDegreesMatrix creates a new Matrix that rotates by 'degrees'. Positive values are clockwise.

func NewRotationMatrix added in v1.100.0

func NewRotationMatrix[T constraints.Float](radians T) Matrix[T]

NewRotationMatrix creates a new Matrix that rotates by 'radians'. Positive values are clockwise.

func NewScaleMatrix added in v1.100.0

func NewScaleMatrix[T constraints.Float](sx, sy T) Matrix[T]

NewScaleMatrix creates a new Matrix that scales by 'sx' and 'sy'.

func NewTranslationMatrix added in v1.100.0

func NewTranslationMatrix[T constraints.Float](tx, ty T) Matrix[T]

NewTranslationMatrix creates a new Matrix that translates by 'tx' and 'ty'.

func (Matrix[T]) Multiply added in v1.100.0

func (m Matrix[T]) Multiply(other Matrix[T]) Matrix[T]

Multiply returns this Matrix multiplied by the other Matrix.

func (Matrix[T]) Rotate added in v1.100.0

func (m Matrix[T]) Rotate(radians T) Matrix[T]

Rotate returns a new Matrix which is a copy of this Matrix rotated by 'radians'. Positive values are clockwise.

func (Matrix[T]) RotateByDegrees added in v1.100.0

func (m Matrix[T]) RotateByDegrees(degrees T) Matrix[T]

RotateByDegrees returns a new Matrix which is a copy of this Matrix rotated by 'degrees'. Positive values are clockwise.

func (Matrix[T]) Scale added in v1.100.0

func (m Matrix[T]) Scale(sx, sy T) Matrix[T]

Scale returns a new Matrix which is a copy of this Matrix scaled by 'sx' and 'sy'.

func (Matrix[T]) String added in v1.100.0

func (m Matrix[T]) String() string

String implements fmt.Stringer.

func (Matrix[T]) TransformPoint added in v1.100.0

func (m Matrix[T]) TransformPoint(p Point[T]) Point[T]

TransformPoint returns the result of transforming the given Point by this Matrix.

func (Matrix[T]) Translate added in v1.100.0

func (m Matrix[T]) Translate(tx, ty T) Matrix[T]

Translate returns a new Matrix which is a copy of this Matrix translated 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 ConvertPoint added in v1.100.0

func ConvertPoint[T, F xmath.Numeric](pt Point[F]) Point[T]

ConvertPoint converts a Point of type F into one of type T.

func LineIntersection added in v1.13.0

func LineIntersection[T xmath.Numeric](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 returns a new Point.

func (Point[T]) Add

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

Add returns a new Point which is the result of adding this Point with the provided Point.

func (Point[T]) Ceil added in v1.100.0

func (p Point[T]) Ceil() Point[T]

Ceil returns a new Point which is aligned to integer coordinates by using Ceil() on them.

func (Point[T]) Cross added in v1.100.0

func (p Point[T]) Cross(pt Point[T]) T

Cross returns the cross product of the two Points.

func (Point[T]) Div added in v1.100.0

func (p Point[T]) Div(value T) Point[T]

Div returns a new Point which is the result of dividing the coordinates of this point by the value.

func (Point[T]) Dot added in v1.100.0

func (p Point[T]) Dot(pt Point[T]) T

Dot returns the dot product of the two Points.

func (Point[T]) EqualWithin added in v1.100.0

func (p Point[T]) EqualWithin(pt Point[T], tolerance T) bool

EqualWithin returns true if the two points are within the given tolerance of each other.

func (Point[T]) Floor added in v1.100.0

func (p Point[T]) Floor() Point[T]

Floor returns a new Point which is aligned to integer coordinates by using Floor on them.

func (Point[T]) In added in v1.100.0

func (p Point[T]) In(r Rect[T]) bool

In returns true if this Point is within the Rect.

func (Point[T]) Mul added in v1.100.0

func (p Point[T]) Mul(value T) Point[T]

Mul returns a new Point which is the result of multiplying the coordinates of this point by the value.

func (Point[T]) Neg added in v1.100.0

func (p Point[T]) Neg() Point[T]

Neg returns a new Point that holds the negated coordinates of this Point.

func (Point[T]) String

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

String implements the fmt.Stringer interface.

func (Point[T]) Sub added in v1.100.0

func (p Point[T]) Sub(pt Point[T]) Point[T]

Sub returns a new Point which is the result of subtracting the provided Point from this Point.

type Rect

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

Rect defines a rectangle.

func ConvertRect added in v1.100.0

func ConvertRect[T, F xmath.Numeric](r Rect[F]) Rect[T]

ConvertRect converts a Rect of type F into one of type T.

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 (Rect[T]) Align

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

Align returns a new Rect aligned with integer coordinates that would encompass the original rectangle.

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

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

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

BottomRight returns the bottom-right point of the Rect.

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

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

Center returns the center of the Rect.

func (Rect[T]) CenterX

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

CenterX returns the center x-coordinate of the Rect.

func (Rect[T]) CenterY

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

CenterY returns the center y-coordinate of the Rect.

func (Rect[T]) Contains added in v1.100.0

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

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

func (Rect[T]) Empty added in v1.100.0

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

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

func (Rect[T]) Expand added in v1.100.0

func (r Rect[T]) Expand(pt Point[T]) Rect[T]

Expand returns a new Rect that expands this Rect to encompass the provided Point. 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.

func (Rect[T]) Inset

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

Inset returns a new Rect which has been inset by the specified Insets.

func (Rect[T]) Intersect

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

Intersect returns the result of intersecting this Rect with another Rect.

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]) 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 fmt.Stringer.

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

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

TopLeft returns the top-left point of the Rect.

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

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

TopRight returns the top-right point of the Rect.

func (Rect[T]) Union

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

Union returns the result of unioning this Rect with another Rect.

type Size

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

Size defines a width and height.

func ConvertSize added in v1.100.0

func ConvertSize[T, F xmath.Numeric](s Size[F]) Size[T]

ConvertSize converts a Size of type F into one of type T.

func NewSize added in v1.8.0

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

NewSize creates a new Size.

func (Size[T]) Add

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

Add returns a new Size which is the result of adding this Size with the provided Size.

func (Size[T]) Ceil added in v1.100.0

func (s Size[T]) Ceil() Size[T]

Ceil returns a new Size with its width and height ceiled.

func (Size[T]) ConstrainForHint

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

ConstrainForHint returns a size no larger than the hint value. Hint values less than one are ignored.

func (Size[T]) Div added in v1.100.0

func (s Size[T]) Div(value T) Size[T]

Div returns a new Size which is the result of dividing this Size by the value.

func (Size[T]) Floor added in v1.100.0

func (s Size[T]) Floor() Size[T]

Floor returns a new Size with its width and height floored.

func (Size[T]) Max

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

Max returns the largest Size between itself and 'other'.

func (Size[T]) Min

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

Min returns the smallest Size between itself and 'other'.

func (Size[T]) Mul added in v1.100.0

func (s Size[T]) Mul(value T) Size[T]

Mul returns a new Size which is the result of multiplying this Size by the value.

func (Size[T]) String

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

String implements fmt.Stringer.

func (Size[T]) Sub added in v1.100.0

func (s Size[T]) Sub(size Size[T]) Size[T]

Sub returns a new Size which is the result of subtracting the provided Size from this Size.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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