poly

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: 4 Imported by: 2

Documentation

Index

Constants

View Source
const Epsilon = 2.2204460492503131e-16

Epsilon controls how close a point has to be to be considered the same as another. If performance becomes an issue, you can increase this value, which will cause more points to merge together, reducing the amount of work that must be done. Don't raise it too high, though, as it can distort the resulting polygon.

Variables

This section is empty.

Functions

func CalcEllipseSegmentCount added in v1.20.0

func CalcEllipseSegmentCount[T constraints.Float](r, e T) int

CalcEllipseSegmentCount returns a suggested number of segments to use when generating an ellipse. 'r' is the largest radius of the ellipse. 'e' is the acceptable error, typically 1 or less.

Types

type Contour

type Contour[T constraints.Float] []geom.Point[T]

Contour is a sequence of vertices connected by line segments, forming a closed shape.

func (Contour[T]) Bounds

func (c Contour[T]) Bounds() geom.Rect[T]

Bounds returns the bounding rectangle of a contour.

func (Contour[T]) Clone

func (c Contour[T]) Clone() Contour[T]

Clone returns a copy of this contour.

func (Contour[T]) Contains

func (c Contour[T]) Contains(pt geom.Point[T]) bool

Contains returns true if the point is contained by the contour.

type Polygon

type Polygon[T constraints.Float] []Contour[T]

Polygon holds one or more contour lines. The polygon may contain holes and may be self-intersecting.

func ApproximateEllipse added in v1.16.0

func ApproximateEllipse[T constraints.Float](bounds geom.Rect[T], sections int) Polygon[T]

ApproximateEllipse creates a polygon that approximates an ellipse. 'sections' indicates how many segments to break the ellipse contour into.

func ApproximateEllipseAuto added in v1.20.0

func ApproximateEllipseAuto[T constraints.Float](bounds geom.Rect[T]) Polygon[T]

ApproximateEllipseAuto creates a polygon that approximates an ellipse, automatically choose the number of segments to break the ellipse contour into. This uses CalcEllipseSegmentCount() with an 'e' of 0.2.

func Rect added in v1.16.0

func Rect[T constraints.Float](bounds geom.Rect[T]) Polygon[T]

Rect creates a new polygon in the shape of a rectangle.

func (Polygon[T]) Bounds

func (p Polygon[T]) Bounds() geom.Rect[T]

Bounds returns the bounding rectangle of this polygon.

func (Polygon[T]) Clone

func (p Polygon[T]) Clone() Polygon[T]

Clone returns a duplicate of this polygon.

func (Polygon[T]) Contains

func (p Polygon[T]) Contains(pt geom.Point[T]) bool

Contains returns true if the point is contained by the polygon.

func (Polygon[T]) ContainsEvenOdd

func (p Polygon[T]) ContainsEvenOdd(pt geom.Point[T]) bool

ContainsEvenOdd returns true if the point is contained by the polygon using the even-odd rule. https://en.wikipedia.org/wiki/Even-odd_rule

func (Polygon[T]) Intersect

func (p Polygon[T]) Intersect(other Polygon[T]) Polygon[T]

Intersect returns the intersection of both polygons.

func (Polygon[T]) Subtract

func (p Polygon[T]) Subtract(other Polygon[T]) Polygon[T]

Subtract returns the result of removing the other polygon from this polygon.

func (Polygon[T]) Union

func (p Polygon[T]) Union(other Polygon[T]) Polygon[T]

Union returns the union of both polygons.

func (Polygon[T]) Xor

func (p Polygon[T]) Xor(other Polygon[T]) Polygon[T]

Xor returns the result of xor'ing this polygon with the other polygon.

Jump to

Keyboard shortcuts

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