geom32

package
v1.45.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package geom32 provides geometry primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PointSegmentDistance

func PointSegmentDistance(s1, s2, p Point) float32

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(s1, s2, p Point) float32

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 struct {
	Top    float32
	Left   float32
	Bottom float32
	Right  float32
}

Insets defines margins on each side of a rectangle.

func NewHorizontalInsets

func NewHorizontalInsets(amount float32) Insets

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

func NewUniformInsets

func NewUniformInsets(amount float32) Insets

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

func NewVerticalInsets

func NewVerticalInsets(amount float32) Insets

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

func (*Insets) Add

func (i *Insets) Add(insets Insets) *Insets

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

func (Insets) String

func (i Insets) String() string

String implements the fmt.Stringer interface.

func (*Insets) Subtract

func (i *Insets) Subtract(insets Insets) *Insets

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

type Matrix2D added in v1.35.0

type Matrix2D struct {
	ScaleX float32
	SkewX  float32
	TransX float32
	SkewY  float32
	ScaleY float32
	TransY float32
}

Matrix2D provides a matrix.

func NewIdentityMatrix2D added in v1.35.0

func NewIdentityMatrix2D() *Matrix2D

NewIdentityMatrix2D creates a new identity transformation 2D matrix.

func NewRotationByDegreesMatrix2D added in v1.35.0

func NewRotationByDegreesMatrix2D(degrees float32) *Matrix2D

NewRotationByDegreesMatrix2D creates a new 2D matrix that rotates by 'degrees'. Positive values are clockwise.

func NewRotationMatrix2D added in v1.35.0

func NewRotationMatrix2D(radians float32) *Matrix2D

NewRotationMatrix2D creates a new 2D matrix that rotates by 'radians'. Positive values are clockwise.

func NewScaleMatrix2D added in v1.35.0

func NewScaleMatrix2D(sx, sy float32) *Matrix2D

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

func NewTranslationMatrix2D added in v1.35.0

func NewTranslationMatrix2D(tx, ty float32) *Matrix2D

NewTranslationMatrix2D creates a new 2D matrix that translates by 'tx' and 'ty'.

func (*Matrix2D) Multiply added in v1.35.0

func (m *Matrix2D) Multiply(other *Matrix2D)

Multiply this matrix by 'other'.

func (*Matrix2D) Rotate added in v1.35.0

func (m *Matrix2D) Rotate(radians float32)

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

func (*Matrix2D) Scale added in v1.35.0

func (m *Matrix2D) Scale(sx, sy float32)

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

func (*Matrix2D) TransformDistance added in v1.35.0

func (m *Matrix2D) TransformDistance(distance Size) Size

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

func (m *Matrix2D) TransformPt(pt Point) Point

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

func (*Matrix2D) Translate added in v1.35.0

func (m *Matrix2D) Translate(tx, ty float32)

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

type Point

type Point struct {
	X, Y float32
}

Point defines a location.

func LineIntersection

func LineIntersection(a1, a2, b1, b2 Point) []Point

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(x, y float32) Point

NewPoint creates a new Point.

func NewPointPtr

func NewPointPtr(x, y float32) *Point

NewPointPtr creates a new *Point.

func (*Point) Add

func (p *Point) Add(pt Point) *Point

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

func (*Point) Align

func (p *Point) Align() *Point

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

func (*Point) Negate added in v1.36.0

func (p *Point) Negate() *Point

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

func (Point) String

func (p Point) String() string

String implements the fmt.Stringer interface.

func (*Point) Subtract

func (p *Point) Subtract(pt Point) *Point

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

type Rect

type Rect struct {
	Point
	Size
}

Rect defines a rectangle.

func NewRect

func NewRect(x, y, width, height float32) Rect

NewRect creates a new Rect.

func NewRectPtr

func NewRectPtr(x, y, width, height float32) *Rect

NewRectPtr creates a new *Rect.

func (*Rect) AddPoint

func (r *Rect) AddPoint(pt Point) *Rect

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

func (r *Rect) Align() *Rect

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

func (Rect) Bottom

func (r Rect) Bottom() float32

Bottom returns the bottom edge, or Y + Height.

func (Rect) BottomLeft

func (r Rect) BottomLeft() Point

BottomLeft returns the bottom-left point of the rectangle.

func (Rect) BottomRight

func (r Rect) BottomRight() Point

BottomRight returns the bottom-right point of the rectangle.

func (Rect) Bounds

func (r Rect) Bounds() Rect

Bounds merely returns this rectangle.

func (Rect) Center

func (r Rect) Center() Point

Center returns the center of the rectangle.

func (Rect) CenterX

func (r Rect) CenterX() float32

CenterX returns the center x-coordinate of the rectangle.

func (Rect) CenterY

func (r Rect) CenterY() float32

CenterY returns the center y-coordinate of the rectangle.

func (Rect) ContainsPoint

func (r Rect) ContainsPoint(pt Point) bool

ContainsPoint returns true if the coordinates are within the Rect.

func (Rect) ContainsRect

func (r Rect) ContainsRect(in Rect) bool

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

func (*Rect) CopyAndZeroLocation

func (r *Rect) CopyAndZeroLocation() Rect

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

func (*Rect) Inset

func (r *Rect) Inset(insets Insets) *Rect

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

func (*Rect) InsetUniform

func (r *Rect) InsetUniform(amount float32) *Rect

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

func (r *Rect) Intersect(other Rect) *Rect

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

func (Rect) Intersects

func (r Rect) Intersects(other Rect) bool

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

func (Rect) IntersectsLine

func (r Rect) IntersectsLine(start, end Point) bool

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

func (Rect) IsEmpty

func (r Rect) IsEmpty() bool

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

func (Rect) Max

func (r Rect) Max() Point

Max returns the bottom right corner of the rectangle.

func (Rect) Right

func (r Rect) Right() float32

Right returns the right edge, or X + Width.

func (Rect) String

func (r Rect) String() string

String implements the fmt.Stringer interface.

func (Rect) TopLeft

func (r Rect) TopLeft() Point

TopLeft returns the top-left point of the rectangle.

func (Rect) TopRight

func (r Rect) TopRight() Point

TopRight returns the top-right point of the rectangle.

func (*Rect) Union

func (r *Rect) Union(other Rect) *Rect

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

type Size

type Size struct {
	Width, Height float32
}

Size defines a width and height.

func NewSize

func NewSize(width, height float32) Size

NewSize creates a new Size.

func NewSizePtr

func NewSizePtr(x, y float32) *Size

NewSizePtr creates a new *Size.

func (*Size) Add

func (s *Size) Add(size Size) *Size

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

func (*Size) AddInsets

func (s *Size) AddInsets(insets Insets) *Size

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

func (*Size) ConstrainForHint

func (s *Size) ConstrainForHint(hint Size) *Size

ConstrainForHint ensures this size is no larger than the hint. Hint values less than one are ignored. Returns itself for easy chaining.

func (*Size) GrowToInteger

func (s *Size) GrowToInteger() *Size

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

func (s *Size) Max(other Size) *Size

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

func (*Size) Min

func (s *Size) Min(other Size) *Size

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

func (Size) String

func (s Size) String() string

String implements the fmt.Stringer interface.

func (*Size) Subtract

func (s *Size) Subtract(size Size) *Size

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

func (*Size) SubtractInsets

func (s *Size) SubtractInsets(insets Insets) *Size

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