Documentation ¶
Overview ¶
Package polygon provides functions for manipulation of polygon structures. A polygon is an N straight sided, not self-intersecting, shape, where N is greater than 2.
The conventions for this package are x increases to the right, and y increases up the page (reverse of typical image formats). This convention gives meaning to clockwise and counter-clockwise.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Zeroish = 1e-6
Zeroish is defined to merge points and avoid rounding error problems. The number is chosen to connect anything closer than 0.001 (which is a convenience default for values representing millimeters).
Functions ¶
func MatchPoint ¶
MatchPoint recognizes when a is close enough to any of the points b...
Types ¶
type Point ¶
type Point struct {
X, Y float64
}
Point holds a 2d coordinate value. X increases to the right. Y increases up the page. These are the conventions of mathematical graph paper and not those of typical image formats.
type Shape ¶
type Shape struct {
// MinX etc represent the bounding box for a polygon.
MinX, MinY, MaxX, MaxY float64
// Hole indicates the polygon points are ordered (clockwise)
// to represent a hole instead of an additive shape.
Hole bool
// Consecutive points on the perimeter of the polygon. There
// is an implicit edge joining the last point to the first
// point.
PS []Point
}
Shape holds the points in a polygon and some convenience fields, such as the properties of its bounding box and whether the perimeter is clockwise (by convention a Hole) or counterclockwise (by convention a shape).
type Shapes ¶
type Shapes struct {
P []*Shape
}
Shapes holds a set of polygon shapes each of arrays of (x,y) points.
func (*Shapes) Append ¶
Append appends a polygon shape constructed from a series of consecutive points. If p is nil, it is allocated. The return value is the appended collection of shapes.
func (*Shapes) BB ¶ added in v0.7.1
Return the bounding box lower left and top right corner points for the shapes.
func (*Shapes) Builder ¶
Builder turns a set of points into a polygon shape and appends it to the provided value, p. If p is nil it is allocated. If the operation cannot be performed, the function panics. If you require more error control, call p.Append() instead.
func (*Shapes) Inflate ¶ added in v0.7.1
Inflate inflates an indexed shape by distance, d. Holes are deflated by this amount. If we inflate a circle by d, its diameter will increase by that much.