poly

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package poly provides types and functions for working with polygons in support of the pathfind package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFloats

func ParseFloats(s string) []float32

ParseFloats parses a slice of float32s from a comma-separated string of numbers, for example "186.5,364.7,303.25,374,303.1,412". Spaces are ignored.

Types

type Line

type Line struct {
	Seg LineSeg
}

Line represents a straight line that goes through the two points of a line segment and continues to infinity in both directions.

func (Line) Intersect

func (l Line) Intersect(m Line) (p geom.Vec2, exists bool)

Intersect returns the intersection point p of two lines l and m. Returns false if the lines are parallel and therefore no such intersection point exists.

func (Line) Side

func (l Line) Side(p geom.Vec2) int

Side reports on which side of the line point p is. It is +1 on one side, -1 on the other side, and 0 on the line.

type LineSeg

type LineSeg struct {
	A, B geom.Vec2
}

A LineSeg represents a line segment between two points A and B.

func (LineSeg) ClosestPt

func (l LineSeg) ClosestPt(p geom.Vec2) geom.Vec2

ClosestPt returns the point on the line segment l that is closest to point p. This is either the orthogonal projection of p onto l or one of l's end points if the projection is not within the line segment.

func (LineSeg) Crosses

func (l LineSeg) Crosses(m LineSeg) bool

Crosses returns true if line segments l and m cross each other, otherwise false.

func (LineSeg) Len

func (l LineSeg) Len() float32

Len returns the length of a line segment.

func (LineSeg) Middle

func (l LineSeg) Middle() geom.Vec2

Middle returns the middle of the line segment.

func (LineSeg) NearEq

func (l LineSeg) NearEq(m LineSeg) bool

NearEq determines whether two line segments are equal or not. The order of the end points is relevant.

func (LineSeg) String

func (l LineSeg) String() string

String returns a string representation of l like "L(1.5, 1):(2, 3.4)".

type Polygon

type Polygon []geom.Vec2

A Polygon is a polygon in 2-dimensional space, represented as a slice of its vertices.

func ParsePolygon

func ParsePolygon(coords string) Polygon

ParsePolygon parses a new polygon from a comma-separated coordinate string, for example "186.5,364.7,303.25,374,303.1,412". Should have an even number of coordinate values. Rest is ignored.

func (Polygon) ClosestPt

func (p Polygon) ClosestPt(pt geom.Vec2) geom.Vec2

ClosestPt returns the closest point to point pt on the outline of polygon p.

func (Polygon) Contains

func (p Polygon) Contains(pt geom.Vec2, toleranceOnOutside bool) bool

Contains checks if point pt lies inside the boundary of polygon p.

func (Polygon) Edge

func (p Polygon) Edge(i int) LineSeg

Edge returns the edge with index i of polygon p.

func (Polygon) IsConcaveAt

func (p Polygon) IsConcaveAt(i int) bool

IsConcaveAt checks, whether the vertex with index i of polygon p is concave or not.

func (Polygon) IsCrossedBy

func (p Polygon) IsCrossedBy(ls LineSeg) bool

IsCrossedBy checks if any side of polygon p is crossed by line segment ls.

func (Polygon) WrapIndex

func (p Polygon) WrapIndex(i int) int

WrapIndex returns an index based on i that can be safely used to access an element of p. It wraps around if i < 0 or i >= len(p).

type PolygonSet

type PolygonSet []Polygon

A PolygonSet represents multiple polygons.

func ParsePolygons

func ParsePolygons(coords []string) PolygonSet

ParsePolygons parses polygons from n comma-separated coordinate strings and returns them as a PolygonSet. See ParsePolygon for details on the format.

func (PolygonSet) ClosestPt

func (ps PolygonSet) ClosestPt(pt geom.Vec2) geom.Vec2

ClosestPt returns the closest point to point pt on any of the outlines of polygon set ps.

func (PolygonSet) Contains

func (ps PolygonSet) Contains(pt geom.Vec2) bool

Contains checks if point pt lies inside the boundaries of a polygon set. Overlapping polygons can form holes and islands.

Jump to

Keyboard shortcuts

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