geometry

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 4 Imported by: 1

README

geometry

GoDoc

This package provides efficient 2D geometry utilities for Go.

  • Features Point, Rect, Line, and Polygon geometry types
  • Operations such as Intersects, Contains, and Point-in-polygon
  • Support for geometry indexing

This package was extracted from the https://github.com/tidwall/geojson project

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultIndexOptions = &IndexOptions{Kind: QuadTree, MinPoints: 64}
	NoIndexing          = &IndexOptions{Kind: None, MinPoints: 0}
)
View Source
var AZ = []Point{}/* 1582 elements not displayed */
View Source
var RI = []Point{}/* 214 elements not displayed */
View Source
var TX = []Point{}/* 12478 elements not displayed */

Functions

This section is empty.

Types

type Geometry

type Geometry interface {
	Rect() Rect
	Empty() 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 = 0
	QuadTree IndexKind = 1
)

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() []byte

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) RawPoints

func (series *Line) RawPoints() []Point

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 for segments that intersect the provided rectangle

func (*Line) SegmentAt

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

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

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) ContainsPointEx

func (poly *Poly) ContainsPointEx(point Point) (contains bool, holeIndex int)

ContainsPointEx returns true if the polygon contains a point. Returns the index of the hole that contains the point, or -1 if the point is not inside of a hole.

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

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) Closed

func (rect Rect) Closed() 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) East

func (rect Rect) East() Segment

func (Rect) Empty

func (rect Rect) Empty() bool

func (Rect) Index

func (rect Rect) Index() []byte

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) NE

func (rect Rect) NE() Point

func (Rect) NW

func (rect Rect) NW() Point

func (Rect) North

func (rect Rect) North() Segment

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) RawPoints

func (rect Rect) RawPoints() []Point

func (Rect) Rect

func (rect Rect) Rect() Rect

func (Rect) SE

func (rect Rect) SE() Point

func (Rect) SW

func (rect Rect) SW() Point

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) South

func (rect Rect) South() Segment

func (Rect) Union

func (rect Rect) Union(other Rect) Rect

func (Rect) West

func (rect Rect) West() Segment

type Ring

type Ring = Series

type Segment

type Segment struct {
	A, B Point
}

Segment is a two point line

func DistanceToSeries

func DistanceToSeries(
	series Series,
	distToRect func(rect Rect) float64,
	distToSegment func(seg Segment) float64,
) (seg Segment, idx int, dist float64)

DistanceToSeries returns an arbritary distance to a Series. All the calculations are performed within two functions, that must be provided by the caller: - distToRect to calculate a distance to a Rectangle. - distToSegment to calculate a distance to a Segment. Returns NaN if the series is empty.

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 segment

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
	Index() []byte
	RawPoints() []Point
	Closed() bool
	Search(rect Rect, iter func(seg Segment, index int) 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