geometry

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIndexOptions = &IndexOptions{
	Kind:      QuadTree,
	MinPoints: 64,
}

DefaultIndexOptions ...

View Source
var WorldPolygon = NewPoly([]Point{
	{-180, -90}, {-180, 90}, {180, 90}, {180, -90}, {-180, -90},
}, nil, &IndexOptions{})

WorldPolygon is the maximum bounds for any GeoPoint

Functions

This section is empty.

Types

type Geometry

type Geometry interface {
	Rect() Rect
	Empty() bool
	Valid() bool
	ContainsPoint(point Point) bool
	IntersectsPoint(point Point) bool
	ContainsRect(rect Rect) bool
	IntersectsRect(rect Rect) bool
	ContainsLine(line *Line) bool
	IntersectsLine(line *Line) bool
	ContainsPoly(poly *Poly) bool
	IntersectsPoly(poly *Poly) bool
}

Geometry is a standard geometry

type IndexKind

type IndexKind byte

IndexKind is the kind of index to use in the options.

const (
	None IndexKind = iota
	RTree
	QuadTree
)

IndexKind types

func (IndexKind) String

func (kind IndexKind) String() string

type IndexOptions

type IndexOptions struct {
	Kind      IndexKind
	MinPoints int
}

IndexOptions are segment indexing options

type Line

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

Line is a open series of points

func NewLine

func NewLine(points []Point, opts *IndexOptions) *Line

NewLine creates a new Line

func (*Line) Clockwise

func (series *Line) Clockwise() bool

Clockwise ...

func (*Line) Closed

func (series *Line) Closed() bool

Closed return true if the shape is closed

func (*Line) ContainsLine

func (line *Line) ContainsLine(other *Line) bool

ContainsLine ...

func (*Line) ContainsPoint

func (line *Line) ContainsPoint(point Point) bool

ContainsPoint ...

func (*Line) ContainsPoly

func (line *Line) ContainsPoly(poly *Poly) bool

ContainsPoly ...

func (*Line) ContainsRect

func (line *Line) ContainsRect(rect Rect) bool

ContainsRect ...

func (*Line) Convex

func (series *Line) Convex() bool

Convex returns true if the points create a convex loop or linestring

func (*Line) Empty

func (series *Line) Empty() bool

Empty returns true if the series does not take up space.

func (*Line) Index

func (series *Line) Index() interface{}

Index ...

func (*Line) IntersectsLine

func (line *Line) IntersectsLine(other *Line) bool

IntersectsLine ...

func (*Line) IntersectsPoint

func (line *Line) IntersectsPoint(point Point) bool

IntersectsPoint ...

func (*Line) IntersectsPoly

func (line *Line) IntersectsPoly(poly *Poly) bool

IntersectsPoly ...

func (*Line) IntersectsRect

func (line *Line) IntersectsRect(rect Rect) bool

IntersectsRect ...

func (*Line) Move

func (line *Line) Move(deltaX, deltaY float64) *Line

Move ...

func (*Line) NumPoints

func (series *Line) NumPoints() int

NumPoints returns the number of points in the series

func (*Line) NumSegments

func (series *Line) NumSegments() int

NumSegments ...

func (*Line) PointAt

func (series *Line) PointAt(index int) Point

PointAt returns the point at index

func (*Line) Rect

func (series *Line) Rect() Rect

Rect returns the series rectangle

func (*Line) Search

func (series *Line) Search(
	rect Rect, iter func(seg Segment, idx int) bool,
)

Search finds a searches for segments that intersect the provided rectangle

func (*Line) SegmentAt

func (series *Line) SegmentAt(index int) Segment

SegmentAt ...

func (*Line) Valid

func (line *Line) Valid() bool

Valid ...

type Point

type Point struct {
	X, Y float64
}

Point ...

func (Point) ContainsLine

func (point Point) ContainsLine(line *Line) bool

ContainsLine ...

func (Point) ContainsPoint

func (point Point) ContainsPoint(other Point) bool

ContainsPoint ...

func (Point) ContainsPoly

func (point Point) ContainsPoly(poly *Poly) bool

ContainsPoly ...

func (Point) ContainsRect

func (point Point) ContainsRect(rect Rect) bool

ContainsRect ...

func (Point) Empty

func (point Point) Empty() bool

Empty ...

func (Point) IntersectsLine

func (point Point) IntersectsLine(line *Line) bool

IntersectsLine ...

func (Point) IntersectsPoint

func (point Point) IntersectsPoint(other Point) bool

IntersectsPoint ...

func (Point) IntersectsPoly

func (point Point) IntersectsPoly(poly *Poly) bool

IntersectsPoly ...

func (Point) IntersectsRect

func (point Point) IntersectsRect(rect Rect) bool

IntersectsRect ...

func (Point) Move

func (point Point) Move(deltaX, deltaY float64) Point

Move ...

func (Point) Rect

func (point Point) Rect() Rect

Rect ...

func (Point) Valid

func (point Point) Valid() bool

Valid ...

type Poly

type Poly struct {
	Exterior Ring
	Holes    []Ring
}

Poly ...

func NewPoly

func NewPoly(exterior []Point, holes [][]Point, opts *IndexOptions) *Poly

NewPoly ...

func (*Poly) Clockwise

func (poly *Poly) Clockwise() bool

Clockwise ...

func (*Poly) ContainsLine

func (poly *Poly) ContainsLine(line *Line) bool

ContainsLine ...

func (*Poly) ContainsPoint

func (poly *Poly) ContainsPoint(point Point) bool

ContainsPoint ...

func (*Poly) ContainsPoly

func (poly *Poly) ContainsPoly(other *Poly) bool

ContainsPoly ...

func (*Poly) ContainsRect

func (poly *Poly) ContainsRect(rect Rect) bool

ContainsRect ...

func (*Poly) Empty

func (poly *Poly) Empty() bool

Empty ...

func (*Poly) IntersectsLine

func (poly *Poly) IntersectsLine(line *Line) bool

IntersectsLine ...

func (*Poly) IntersectsPoint

func (poly *Poly) IntersectsPoint(point Point) bool

IntersectsPoint ...

func (*Poly) IntersectsPoly

func (poly *Poly) IntersectsPoly(other *Poly) bool

IntersectsPoly ...

func (*Poly) IntersectsRect

func (poly *Poly) IntersectsRect(rect Rect) bool

IntersectsRect ...

func (*Poly) Move

func (poly *Poly) Move(deltaX, deltaY float64) *Poly

Move the polygon by delta. Returns a new polygon

func (*Poly) Rect

func (poly *Poly) Rect() Rect

Rect ...

func (*Poly) Valid

func (poly *Poly) Valid() bool

Valid ...

type RaycastResult

type RaycastResult struct {
	In bool // point on the left
	On bool // point is directly on top of
}

RaycastResult holds the results of the Raycast operation

type Rect

type Rect struct {
	Min, Max Point
}

Rect ...

func (Rect) Area

func (rect Rect) Area() float64

Area ...

func (Rect) Center

func (rect Rect) Center() Point

Center ...

func (Rect) Clockwise

func (rect Rect) Clockwise() bool

Clockwise ...

func (Rect) ContainsLine

func (rect Rect) ContainsLine(line *Line) bool

ContainsLine ...

func (Rect) ContainsPoint

func (rect Rect) ContainsPoint(point Point) bool

ContainsPoint ...

func (Rect) ContainsPoly

func (rect Rect) ContainsPoly(poly *Poly) bool

ContainsPoly ...

func (Rect) ContainsRect

func (rect Rect) ContainsRect(other Rect) bool

ContainsRect ...

func (Rect) Convex

func (rect Rect) Convex() bool

Convex ...

func (Rect) Empty

func (rect Rect) Empty() bool

Empty ...

func (Rect) Index

func (rect Rect) Index() interface{}

Index ...

func (Rect) IntersectsLine

func (rect Rect) IntersectsLine(line *Line) bool

IntersectsLine ...

func (Rect) IntersectsPoint

func (rect Rect) IntersectsPoint(point Point) bool

IntersectsPoint ...

func (Rect) IntersectsPoly

func (rect Rect) IntersectsPoly(poly *Poly) bool

IntersectsPoly ...

func (Rect) IntersectsRect

func (rect Rect) IntersectsRect(other Rect) bool

IntersectsRect ...

func (Rect) Move

func (rect Rect) Move(deltaX, deltaY float64) Rect

Move ...

func (Rect) NumPoints

func (rect Rect) NumPoints() int

NumPoints ...

func (Rect) NumSegments

func (rect Rect) NumSegments() int

NumSegments ...

func (Rect) PointAt

func (rect Rect) PointAt(index int) Point

PointAt ...

func (Rect) Rect

func (rect Rect) Rect() Rect

Rect ...

func (Rect) Search

func (rect Rect) Search(target Rect, iter func(seg Segment, idx int) bool)

Search ...

func (Rect) SegmentAt

func (rect Rect) SegmentAt(index int) Segment

SegmentAt ...

func (Rect) Valid

func (rect Rect) Valid() bool

Valid ...

type Ring

type Ring = Series

Ring ...

type Segment

type Segment struct {
	A, B Point
}

Segment is a two point line

func (Segment) CollinearPoint

func (seg Segment) CollinearPoint(point Point) bool

CollinearPoint ...

func (Segment) ContainsPoint

func (seg Segment) ContainsPoint(point Point) bool

ContainsPoint ...

func (Segment) ContainsSegment

func (seg Segment) ContainsSegment(other Segment) bool

ContainsSegment returns true if segment contains other segment

func (Segment) IntersectsSegment

func (seg Segment) IntersectsSegment(other Segment) bool

IntersectsSegment detects if segment intersects with other segement

func (Segment) Move

func (seg Segment) Move(deltaX, deltaY float64) Segment

Move a segment by delta

func (Segment) Raycast

func (seg Segment) Raycast(point Point) RaycastResult

Raycast performs the raycast operation

func (Segment) Rect

func (seg Segment) Rect() Rect

Rect is the outer boundaries of the segment.

type Series

type Series interface {
	Rect() Rect
	Empty() bool
	Convex() bool
	Clockwise() bool
	NumPoints() int
	NumSegments() int
	PointAt(index int) Point
	SegmentAt(index int) Segment
	Search(rect Rect, iter func(seg Segment, index int) bool)
	Index() interface{}
	Valid() bool
}

Series is just a series of points with utilities for efficiently accessing segments from rectangle queries, making stuff like point-in-polygon lookups very quick.

Jump to

Keyboard shortcuts

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