spatial

package module
v0.0.0-...-32abd34 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 3 Imported by: 0

README

spatial

Learning about spatial trees, e.g. quad/oct trees

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadNumberOfPoints    = errors.New("asked for too many points or < 0")
	ErrPointOutsideOfBounds = errors.New("point outside of bounds")
)

Functions

func Point2dDistance

func Point2dDistance(p, q Point2d) float64

Types

type Bound

type Bound struct {
	Min, Max Point2d
}

Bound is a copy of https://github.com/paulmach/orb/blob/215f32c132d13f906979dbb36bd24c1e0511b6d2/bound.go#L12

func (Bound) Bottom

func (b Bound) Bottom() float64

Bottom returns the bottom of the bound.

func (Bound) Bound

func (b Bound) Bound() Bound

Bound returns the the same bound.

func (Bound) Center

func (b Bound) Center() Point2d

Center returns the center of the bounds by "averaging" the x and y coords.

func (Bound) Contains

func (b Bound) Contains(point Point2d) bool

Contains determines if the point is within the bound. Points on the boundary are considered within.

func (Bound) Equal

func (b Bound) Equal(c Bound) bool

Equal returns if two bounds are equal.

func (Bound) Extend

func (b Bound) Extend(point Point2d) Bound

Extend grows the bound to include the new point.

func (Bound) Intersects

func (b Bound) Intersects(bound Bound) bool

Intersects determines if two bounds intersect. Returns true if they are touching.

func (Bound) IsEmpty

func (b Bound) IsEmpty() bool

IsEmpty returns true if it contains zero area or if it's in some malformed negative state where the left point is larger than the right. This can be caused by padding too much negative.

func (Bound) IsZero

func (b Bound) IsZero() bool

IsZero return true if the bound just includes just null island.

func (Bound) Left

func (b Bound) Left() float64

Left returns the left of the bound.

func (Bound) LeftTop

func (b Bound) LeftTop() Point2d

LeftTop returns the upper left point of the bound.

func (Bound) Pad

func (b Bound) Pad(d float64) Bound

Pad extends the bound in all directions by the given value.

func (Bound) Right

func (b Bound) Right() float64

Right returns the right of the bound.

func (Bound) RightBottom

func (b Bound) RightBottom() Point2d

RightBottom return the lower right point of the bound.

func (Bound) Top

func (b Bound) Top() float64

Top returns the top of the bound.

func (Bound) Union

func (b Bound) Union(other Bound) Bound

Union extends this bound to contain the union of this and the given bound.

type LinearSlice

type LinearSlice[T comparable] struct {
	// contains filtered or unexported fields
}

LinearSlice is meant for testing the other types. It is optimized for testing ease

func NewLinearSlice

func NewLinearSlice[T comparable](points []T, distance_func func(T, T) float64) LinearSlice[T]

func (LinearSlice[T]) Contains

func (s LinearSlice[T]) Contains(p T) bool

Contains returns true if p is in s.

func (LinearSlice[T]) InRange

func (s LinearSlice[T]) InRange(p T, r float64) []T

InRange returns all points in s within range of p.

func (LinearSlice[T]) InRangeCount

func (s LinearSlice[T]) InRangeCount(p T, r float64) int

InRangeCount counts all the points in `s` that are closer to `p` than `r`

func (*LinearSlice[T]) Insert

func (s *LinearSlice[T]) Insert(p T)

Insert inserts p into s.

func (LinearSlice[T]) Nearest

func (s LinearSlice[T]) Nearest(p T) T

Nearest returns the nearest point in s to p.

func (LinearSlice[T]) NearestN

func (s LinearSlice[T]) NearestN(p T, n int) ([]T, error)

NearestN returns the nearest n points in s to p. If `n > len(s)`, returns an error

func (*LinearSlice[T]) Remove

func (s *LinearSlice[T]) Remove(p T)

Remove removes the first instance of p from s. If it is not found, nothing happens

type Point2d

type Point2d struct {
	X, Y float64
}

type Quadtree

type Quadtree[T any] struct {
	// contains filtered or unexported fields
}

Quadtree is based heavily off of https://github.com/paulmach/orb/blob/215f32c132d13f906979dbb36bd24c1e0511b6d2/quadtree/quadtree.go

func NewQuadtree

func NewQuadtree[T any](
	bounds Bound,
	get_point func(T) Point2d,
	calc_distance func(T, T) float64,
) *Quadtree[T]

func (*Quadtree[T]) Insert

func (q *Quadtree[T]) Insert(p T) error

Insert a point to the Quadtree. It must be within the bounds of the tree.

func (*Quadtree[T]) Slice

func (q *Quadtree[T]) Slice() []T

Slice is designed to be as obviously correct as possible to start We'll see about greater efficiency later

type Spatial

type Spatial interface {
	Insert(p Point2d)
	Remove(p Point2d)
	Contains(p Point2d) bool
	Nearest(p Point2d) Point2d
	NearestN(p Point2d, n int) []Point2d
	InRange(p Point2d, r float64) []Point2d
	InRangeCount(p Point2d, r float64) int
}

Jump to

Keyboard shortcuts

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