Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UniqueCoords ¶
UniqueCoords creates a new coordinate array (with the same layout as the inputs) that contains each unique coordinate in the coordData. The ordering of the coords are the same as the input.
Example ¶
package main import ( "fmt" "github.com/twpayne/go-geom" "github.com/twpayne/go-geom/sorting" "github.com/twpayne/go-geom/transform" ) type coordTransformExampleCompare struct{} func (c coordTransformExampleCompare) IsEquals(x, y geom.Coord) bool { return x[0] == y[0] && x[1] == y[1] } func (c coordTransformExampleCompare) IsLess(x, y geom.Coord) bool { return sorting.IsLess2D(x, y) } func main() { coordData := []float64{0, 0, 1, 1, 1, 1, 3, 3, 0, 0} layout := geom.XY filteredCoords := transform.UniqueCoords(layout, coordTransformExampleCompare{}, coordData) fmt.Println(filteredCoords) }
Output: [0 0 1 1 3 3]
Types ¶
type TreeSet ¶
type TreeSet struct {
// contains filtered or unexported fields
}
TreeSet sorts the coordinates according to the Compare strategy and removes duplicates as dicated by the Equals function of the Compare strategy
func NewTreeSet ¶
NewTreeSet creates a new TreeSet instance
Example ¶
package main import ( "fmt" "github.com/twpayne/go-geom" "github.com/twpayne/go-geom/sorting" "github.com/twpayne/go-geom/transform" ) type treeSetExampleCompare struct{} func (c treeSetExampleCompare) IsEquals(x, y geom.Coord) bool { return x[0] == y[0] && x[1] == y[1] } func (c treeSetExampleCompare) IsLess(x, y geom.Coord) bool { return sorting.IsLess2D(x, y) } func main() { set := transform.NewTreeSet(geom.XY, treeSetExampleCompare{}) set.Insert([]float64{3, 1}) set.Insert([]float64{3, 2}) set.Insert([]float64{1, 2}) fmt.Println(set.ToFlatArray()) }
Output: [1 2 3 1 3 2]
func (*TreeSet) Insert ¶
Insert adds a new coordinate to the tree set the coordinate must be the same size as the Stride of the layout provided when constructing the TreeSet Returns true if the coordinate was added, false if it was already in the tree
func (*TreeSet) ToFlatArray ¶
ToFlatArray returns an array of floats containing all the coordinates in the TreeSet