sorting

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: 1 Imported by: 9

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLess2D

func IsLess2D(v1, v2 []float64) bool

IsLess2D is a comparator that compares based on the size of the x and y coords.

First the x coordinates are compared. if x coords are equal then the y coords are compared

Types

type FlatCoord

type FlatCoord struct {
	// contains filtered or unexported fields
}

FlatCoord is a sort.Interface implementation that will result in sorting the wrapped coords based on the the comparator function

Note: this data struct cannot be used with its 0 values. it must be constructed using NewFlatCoordSorting

func NewFlatCoordSorting

func NewFlatCoordSorting(layout geom.Layout, coordData []float64, comparator IsLess) FlatCoord

NewFlatCoordSorting creates a sort.Interface implementation based on the Comparator function

Example
coords := []float64{1, 0, 0, 1, 2, 2, -1, 0}
isLess := func(c1, c2 []float64) bool {
	return c1[0] < c2[0]
}
sort.Sort(sorting.NewFlatCoordSorting(geom.XY, coords, isLess))
fmt.Println(coords)
Output:

[-1 0 0 1 1 0 2 2]

func NewFlatCoordSorting2D

func NewFlatCoordSorting2D(layout geom.Layout, coordData []float64) FlatCoord

NewFlatCoordSorting2D creates a Compare2D based sort.Interface implementation

Example
// Some description
coords := []float64{1, 0, 0, 1, 2, 2, 2, -2, -1, 0}
sort.Sort(sorting.NewFlatCoordSorting2D(geom.XY, coords))
fmt.Println(coords)
Output:

[-1 0 0 1 1 0 2 -2 2 2]

func (FlatCoord) Len

func (s FlatCoord) Len() int

func (FlatCoord) Less

func (s FlatCoord) Less(i, j int) bool

func (FlatCoord) Swap

func (s FlatCoord) Swap(i, j int)

type IsLess

type IsLess func(v1, v2 []float64) bool

IsLess the function used by FlatCoord to sort the coordinate array returns true is v1 is less than v2

Jump to

Keyboard shortcuts

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