geometry

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MIT Imports: 2 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultIndexOptions = &IndexOptions{
	Kind:      QuadTree,
	MinPoints: 64,
}
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

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

func (*Line) ContainsPoint

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

func (*Line) ContainsPoly

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

func (*Line) ContainsRect

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

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{}

func (*Line) IntersectsLine

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

func (*Line) IntersectsPoint

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

func (*Line) IntersectsPoly

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

func (*Line) IntersectsRect

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

func (*Line) Move

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

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

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

func (*Line) Valid

func (line *Line) Valid() bool

type Point

type Point struct {
	X, Y float64
}

func (Point) ContainsLine

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

func (Point) ContainsPoint

func (point Point) ContainsPoint(other Point) bool

func (Point) ContainsPoly

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

func (Point) ContainsRect

func (point Point) ContainsRect(rect Rect) bool

func (Point) Empty

func (point Point) Empty() bool

func (Point) IntersectsLine

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

func (Point) IntersectsPoint

func (point Point) IntersectsPoint(other Point) bool

func (Point) IntersectsPoly

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

func (Point) IntersectsRect

func (point Point) IntersectsRect(rect Rect) bool

func (Point) Move

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

func (Point) Rect

func (point Point) Rect() Rect

func (Point) Valid

func (point Point) Valid() bool

type Poly

type Poly struct {
	Exterior Ring
	Holes    []Ring
}

func NewPoly

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

func (*Poly) Clockwise

func (poly *Poly) Clockwise() bool

func (*Poly) ContainsLine

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

func (*Poly) ContainsPoint

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

func (*Poly) ContainsPoly

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

func (*Poly) ContainsRect

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

func (*Poly) Empty

func (poly *Poly) Empty() bool

func (*Poly) IntersectsLine

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

func (*Poly) IntersectsPoint

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

func (*Poly) IntersectsPoly

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

func (*Poly) IntersectsRect

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

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

func (*Poly) Valid

func (poly *Poly) Valid() bool

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
}

func (Rect) Area

func (rect Rect) Area() float64

func (Rect) Center

func (rect Rect) Center() Point

func (Rect) Clockwise

func (rect Rect) Clockwise() bool

func (Rect) ContainsLine

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

func (Rect) ContainsPoint

func (rect Rect) ContainsPoint(point Point) bool

func (Rect) ContainsPoly

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

func (Rect) ContainsRect

func (rect Rect) ContainsRect(other Rect) bool

func (Rect) Convex

func (rect Rect) Convex() bool

func (Rect) Empty

func (rect Rect) Empty() bool

func (Rect) Index

func (rect Rect) Index() interface{}

func (Rect) IntersectsLine

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

func (Rect) IntersectsPoint

func (rect Rect) IntersectsPoint(point Point) bool

func (Rect) IntersectsPoly

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

func (Rect) IntersectsRect

func (rect Rect) IntersectsRect(other Rect) bool

func (Rect) Move

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

func (Rect) NumPoints

func (rect Rect) NumPoints() int

func (Rect) NumSegments

func (rect Rect) NumSegments() int

func (Rect) PointAt

func (rect Rect) PointAt(index int) Point

func (Rect) Rect

func (rect Rect) Rect() Rect

func (Rect) Search

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

func (Rect) SegmentAt

func (rect Rect) SegmentAt(index int) Segment

func (Rect) Valid

func (rect Rect) Valid() bool

type Ring

type Ring = Series

type Segment

type Segment struct {
	A, B Point
}

Segment is a two point line

func (Segment) CollinearPoint

func (seg Segment) CollinearPoint(point Point) bool

func (Segment) ContainsPoint

func (seg Segment) ContainsPoint(point Point) bool

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