geom

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MPL-2.0 Imports: 2 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)

Add modifies this Insets by adding the supplied Insets.

func (Insets) String

func (i Insets) String() string

String implements the fmt.Stringer interface.

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)

Add modifies this Point by adding the supplied coordinates.

func (*Point) Align

func (p *Point) Align()

Align modifies this Point to align with integer coordinates.

func (Point) String

func (p Point) String() string

String implements the fmt.Stringer interface.

func (*Point) Subtract

func (p *Point) Subtract(pt Point)

Subtract modifies this Point by subtracting the supplied coordinates.

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

func (r *Rect) Align()

Align modifies this rectangle to align with integer coordinates that would encompass the original rectangle.

func (Rect) Bottom added in v1.13.0

func (r Rect) Bottom() float64

Bottom returns the bottom edge, or Y + Height.

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)

Inset this Rect by the specified Insets.

func (*Rect) InsetUniform

func (r *Rect) InsetUniform(amount float64)

InsetUniform insets this Rect by the specified amount on all sides. Positive values make the Rect smaller, while negative values make it larger.

func (*Rect) Intersect

func (r *Rect) Intersect(other Rect)

Intersect this Rect with another Rect, storing the result into this Rect.

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

func (r Rect) IsEmpty() bool

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

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

func (r *Rect) Union(other Rect)

Union this Rect with another Rect, storing the result into this Rect.

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)

Add modifies this Size by adding the supplied Size.

func (*Size) AddInsets

func (s *Size) AddInsets(insets Insets)

AddInsets modifies this Size by expanding it to accommodate the specified insets.

func (*Size) ConstrainForHint

func (s *Size) ConstrainForHint(hint Size)

ConstrainForHint ensures this size is no larger than the hint. Hint values less than one are ignored.

func (*Size) GrowToInteger

func (s *Size) GrowToInteger()

GrowToInteger modifies this Size such that its width and height are both the smallest integers greater than or equal to their original values.

func (*Size) Max

func (s *Size) Max(other Size)

Max modifies this Size to contain the largest values between itself and 'other'.

func (*Size) Min

func (s *Size) Min(other Size)

Min modifies this Size to contain the smallest values between itself and 'other'.

func (Size) String

func (s Size) String() string

String implements the fmt.Stringer interface.

func (*Size) Subtract

func (s *Size) Subtract(size Size)

Subtract modifies this Size by subtracting the supplied Size.

func (*Size) SubtractInsets

func (s *Size) SubtractInsets(insets Insets)

SubtractInsets modifies this Size by reducing it to accommodate the specified insets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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