geom

package
v1.52.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MPL-2.0 Imports: 6 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(s1, s2, p Point) float64

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

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    float64
	Left   float64
	Bottom float64
	Right  float64
}

Insets defines margins on each side of a rectangle.

func NewHorizontalInsets

func NewHorizontalInsets(amount float64) Insets

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

func NewUniformInsets

func NewUniformInsets(amount float64) Insets

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

func NewVerticalInsets

func NewVerticalInsets(amount float64) 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) MarshalText added in v1.52.0

func (i Insets) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (Insets) String

func (i Insets) String() string

String implements the fmt.Stringer interface.

func (*Insets) Subtract added in v1.24.0

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

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

func (*Insets) UnmarshalText added in v1.52.0

func (i *Insets) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Matrix2D added in v1.35.0

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

Matrix2D provides a 2D 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 float64) *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 float64) *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 float64) *Matrix2D

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

func NewTranslationMatrix2D added in v1.35.0

func NewTranslationMatrix2D(tx, ty float64) *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 float64)

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

func (*Matrix2D) Scale added in v1.35.0

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

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

func (m *Matrix2D) TransformPoint(where Point) Point

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

func (*Matrix2D) Translate added in v1.35.0

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

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

type Point

type Point struct {
	X, Y float64
}

Point defines a location.

func LineIntersection added in v1.13.0

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

func NewPoint(x, y float64) Point

NewPoint creates a new Point.

func NewPointPtr added in v1.8.0

func NewPointPtr(x, y float64) *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) MarshalText added in v1.52.0

func (p Point) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

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.

func (*Point) UnmarshalText added in v1.52.0

func (p *Point) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Rect

type Rect struct {
	Point
	Size
}

Rect defines a rectangle.

func NewRect added in v1.8.0

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

NewRect creates a new Rect.

func NewRectPtr added in v1.8.0

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

NewRectPtr creates a new *Rect.

func (*Rect) AddPoint added in v1.30.0

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

func (r Rect) Bottom() float64

Bottom returns the bottom edge, or Y + Height.

func (Rect) BottomLeft added in v1.28.0

func (r Rect) BottomLeft() Point

BottomLeft returns the bottom-left point of the rectangle.

func (Rect) BottomRight added in v1.28.0

func (r Rect) BottomRight() Point

BottomRight returns the bottom-right point of the rectangle.

func (Rect) Bounds added in v1.31.0

func (r Rect) Bounds() Rect

Bounds merely returns this rectangle.

func (Rect) Center added in v1.16.0

func (r Rect) Center() Point

Center returns the center of the rectangle.

func (Rect) CenterX

func (r Rect) CenterX() float64

CenterX returns the center x-coordinate of the rectangle.

func (Rect) CenterY

func (r Rect) CenterY() float64

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

func (r Rect) Intersects(other Rect) bool

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

func (Rect) IntersectsLine added in v1.28.0

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) MarshalText added in v1.52.0

func (r Rect) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (Rect) Max added in v1.15.0

func (r Rect) Max() Point

Max returns the bottom right corner of the rectangle.

func (Rect) Right added in v1.13.0

func (r Rect) Right() float64

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

func (r Rect) TopLeft() Point

TopLeft returns the top-left point of the rectangle.

func (Rect) TopRight added in v1.28.0

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.

func (*Rect) UnmarshalText added in v1.52.0

func (r *Rect) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Size

type Size struct {
	Width, Height float64
}

Size defines a width and height.

func NewSize added in v1.8.0

func NewSize(width, height float64) Size

NewSize creates a new Size.

func NewSizePtr added in v1.8.0

func NewSizePtr(x, y float64) *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) MarshalText added in v1.52.0

func (s Size) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

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.

func (*Size) UnmarshalText added in v1.52.0

func (s *Size) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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