Documentation ¶
Index ¶
- Constants
- type Plane
- func (pln *Plane) ErasePoints(points []Point, strict bool) error
- func (pln *Plane) Flip(dimension int)
- func (pln *Plane) FlipPoints(points []Point, dimension int) []Point
- func (pln *Plane) GetDimensions() [2]int
- func (pln *Plane) Init(dimensions [2]int)
- func (pln *Plane) JoinAndFillPoints(points []Point) []Point
- func (pln *Plane) JoinPoints(points []Point) []Point
- func (pln *Plane) ReadPoints() []Point
- func (pln *Plane) ReadPointsByFilter(f filterFunction) []Point
- func (pln *Plane) WritePoints(points []Point, strict bool) error
- type Point
- type PointSet
- func (set *PointSet) Add(point Point)
- func (set *PointSet) AddArray(pointArray []Point)
- func (set *PointSet) AsArray() []Point
- func (set *PointSet) CheckFor(point Point) bool
- func (set *PointSet) CheckForAll(points []Point) bool
- func (set *PointSet) Init()
- func (set *PointSet) Remove(point Point)
- func (set *PointSet) RemoveArray(pointArray []Point)
Constants ¶
const VERSION string = "v1.0.4"
Current gopoints version
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plane ¶
type Plane struct {
// contains filtered or unexported fields
}
Plane is essentially a wrapper around PointSet, but with a specific size for dimension X and Y (although these are not strictly enforced by any of the methods) and some methods to interact with points both on the plane and passed as an argument.
func (*Plane) ErasePoints ¶
ErasePoints removes points passed to it in the first argument from the plane's PointSet. It can optionally reject points which are not already on the plane if the second argument is `true`.
func (*Plane) Flip ¶
Flip flips the plane along the X or the Y axis. Sometimes you may need to flip the points on the plane, for example when converting to an image where the Y (1) axis it flipped. The axis of the flip is given as an integer - 0 for X and 1 for Y.
func (*Plane) FlipPoints ¶
FlipPoints is much the same as Flip, but acts on a given set of points as opposed to the whole plane. It also returns the flipped points as a slice.
func (*Plane) GetDimensions ¶
GetDimensions returns the size of the plane as an array of two integers
func (*Plane) Init ¶
Init initialises the plane with dimensions passed as an array of 2 integers, and creates a PointSet to store the points on the plane.
func (*Plane) JoinAndFillPoints ¶
JoinAndFillPoints works much like JoinPoints except it also attempts to work out the "inside" and "outside" of the shape being created, and then fill it with points. This is a one-size-fits-all implementation works reasonably well for most simple shapes, but it's probably always better to make your own.
func (*Plane) JoinPoints ¶
JoinPoints accepts a slice of points and joins each consecutive point using a line of points. It then returns all the points together as a slice.
func (*Plane) ReadPoints ¶
ReadPoints reads all points from the plane's PointSet and returns them as an array (technically a slice).
func (*Plane) ReadPointsByFilter ¶
ReadPointsByFilter accepts a function as an argument, and runs the function with the X and Y coordinates of each point on the plane as argument 1 and 2 respectively. For each point that the function returns `true` for, that point is returned as part of a slice of points.
type Point ¶
type Point struct {
X, Y int
}
A simple 2D point struct holding an X and a Y coordinate, with no methods
type PointSet ¶
type PointSet struct {
// contains filtered or unexported fields
}
A simple set implementation for 2D points as Go does not provide one. Uses map keys as the storage as they do not repeat and are unordered. The value used is a blank struct as it causes little to no overead due to its 0-byte size.
func (*PointSet) Add ¶
Add adds a single point into the set (unless it already exists of course - it's a set after all)
func (*PointSet) AddArray ¶
AddArray works much like Add but accepts a slice of points (poor naming) and adds each element of it to the set
func (*PointSet) CheckForAll ¶
CheckForAll checks if all points in the given slice are present in the set and returns a single boolean to indicate the result
func (*PointSet) Init ¶
func (set *PointSet) Init()
Init initialises the set by creating the map which stores the data. This is called implicitly by all other methods of the set so does not need to be called explicitly. It does not overwrite the set if called multiple times.
func (*PointSet) RemoveArray ¶
RemoveArray works much like Remove but accepts a slice of points (poor naming) and removes each element of it from the set