polygons

package module
v0.0.0-...-66ba2ad Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 11 Imported by: 1

README

polygons

This library is intended to do fast, zero-alloc searches within a collection of polygons.

It is optimized for performance and avoiding GC presssure.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GobDump

func GobDump(filename string, obj interface{}) error

GobDump saves the object in a gzipped GOB encoded file

func GobLoad

func GobLoad(filename string, obj interface{}) error

GobLoad populates the object from a gzipped GOB encoded file

Types

type BBox

type BBox [2]Pair

type Finder

type Finder[T constraints.Unsigned] struct {
	// contains filtered or unexported fields
}

Finder is a collection polygons with associated integer ids The ids do not have to be unique (multiple polygons can share an id) Searching for a polygon containing a point is optimized by creating an RTree of bounding boxes, and then searching candidates within matching bounding boxes

func NewFinder

func NewFinder[T constraints.Unsigned]() *Finder[T]

NewFinder returns a Finder for finding a containing polygon

func (*Finder[T]) Add

func (py *Finder[T]) Add(id int, pp PPoints)

Add a polygon to be searched

func (*Finder[T]) Search

func (py *Finder[T]) Search(pt [2]float64) (int, float64)
func (s *Finder[T]) Dump() {
	t := s.tree
	for i, r := range t.Children() {
		fmt.Printf("%2d %v\n", i, r)
		if i > 10 {
			break
		}
	}
}

Search returns the id of the polygon that contains the given point If polygons are searchable, it returns the id of the closest polygon and the distance away

If not found and no search index, it returns -1

func (*Finder[T]) Size

func (py *Finder[T]) Size() int

Size returns the number of polygons being searched

func (*Finder[T]) Sort

func (py *Finder[T]) Sort()

Sort creates a sorted array of boxes so that they can be used in a binary search

type GeoType

type GeoType = geo.GeoType

type PPoints

type PPoints []Pair

func (PPoints) BBox

func (pp PPoints) BBox() BBox

func (PPoints) Contains

func (pps PPoints) Contains(p Pair) bool

Returns true if the PPoint p lies inside the polygon[] with n vertices

func (PPoints) ContainsPoint

func (pps PPoints) ContainsPoint(pt geo.Point) bool

ContainsPoint returns true if the point is within the polygon

func (PPoints) String

func (pp PPoints) String() string

type Pair

type Pair [2]float64

func (Pair) Less

func (p Pair) Less(x Pair) bool

func (Pair) Point

func (p Pair) Point() geo.Point

type Point

type Point = geo.Point

type PolyPoint

type PolyPoint struct {
	P Pair
	I int
}

func (PolyPoint) Less

func (p PolyPoint) Less(x PolyPoint) bool

type PolyPoints

type PolyPoints []PolyPoint

func (PolyPoints) IndexPoint

func (pp PolyPoints) IndexPoint(i int) Point

func (PolyPoints) Len

func (pp PolyPoints) Len() int

func (PolyPoints) Size

func (pp PolyPoints) Size() int

Jump to

Keyboard shortcuts

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