Documentation ¶
Index ¶
- Constants
- func CalcEllipseSegmentCount[T constraints.Float](r, e T) int
- type Contour
- type Polygon
- func (p Polygon[T]) Bounds() geom.Rect[T]
- func (p Polygon[T]) Clone() Polygon[T]
- func (p Polygon[T]) Contains(pt geom.Point[T]) bool
- func (p Polygon[T]) ContainsEvenOdd(pt geom.Point[T]) bool
- func (p Polygon[T]) Intersect(other Polygon[T]) Polygon[T]
- func (p Polygon[T]) Subtract(other Polygon[T]) Polygon[T]
- func (p Polygon[T]) Union(other Polygon[T]) Polygon[T]
- func (p Polygon[T]) Xor(other Polygon[T]) Polygon[T]
Constants ¶
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.
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
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]) ContainsEvenOdd ¶
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]) Subtract ¶
Subtract returns the result of removing the other polygon from this polygon.