transform

package
v1.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2020 License: BSD-2-Clause Imports: 2 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func UniqueCoords

func UniqueCoords(layout geom.Layout, compare Compare, coordData []float64) []float64

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 Compare

type Compare interface {
	IsEquals(x, y geom.Coord) bool
	IsLess(x, y geom.Coord) bool
}

Compare compares two coordinates for equality and magnitude

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

func NewTreeSet(layout geom.Layout, compare Compare) *TreeSet

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

func (set *TreeSet) Insert(coord geom.Coord) bool

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

func (set *TreeSet) ToFlatArray() []float64

ToFlatArray returns an array of floats containing all the coordinates in the TreeSet

Jump to

Keyboard shortcuts

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