Documentation ¶
Index ¶
- Constants
- func EuclideanDistance(x1, y1, x2, y2 float64) float64
- func GetUnitNormalVector(x1, y1, x2, y2 float64) (float64, float64)
- func PrecisionCompare(a, b, e float64) int
- func Sign(i float64) int
- func TruncateDecimals(v float64) float64
- type BezierCurve
- type Box
- type Ellipse
- type Intersectable
- type Orientation
- type Point
- func (start *Point) AddVector(v Vector) *Point
- func (p1 *Point) Compare(p2 *Point) int
- func (p *Point) Copy() *Point
- func (p *Point) DistanceToLine(p1, p2 *Point) float64
- func (p1 *Point) Equals(p2 *Point) bool
- func (p *Point) FormattedCoordinates() string
- func (pFrom *Point) GetOrientation(pTo *Point) Orientation
- func (a *Point) Interpolate(b *Point, t float64) *Point
- func (p *Point) OnOrthogonalSegment(a, b *Point) bool
- func (p *Point) ToString() string
- func (endpoint *Point) ToVector() Vector
- func (p *Point) Transpose()
- func (p *Point) TruncateDecimals()
- func (p *Point) TruncateFloat32()
- func (start *Point) VectorTo(endpoint *Point) Vector
- type Points
- type RelativePoint
- type Route
- type Segment
- func (segment *Segment) GetBounds(segments []*Segment, buffer float64) (float64, float64)
- func (segment Segment) Intersections(otherSegment Segment) []*Point
- func (segment Segment) Intersects(otherSegment Segment) bool
- func (segment Segment) Length() float64
- func (s Segment) Overlaps(otherS Segment, isHorizontal bool, buffer float64) bool
- func (s Segment) ToString() string
- func (segment Segment) ToVector() Vector
- type Vector
- func (a Vector) Add(b Vector) Vector
- func (a Vector) AddLength(length float64) Vector
- func (a Vector) Degrees() float64
- func (a Vector) Length() float64
- func (a Vector) Minus(b Vector) Vector
- func (a Vector) Multiply(v float64) Vector
- func (a Vector) Radians() float64
- func (a Vector) Reverse() Vector
- func (a Vector) ToPoint() *Point
- func (a Vector) Unit() Vector
Constants ¶
const PRECISION = 0.0001
How precise should comparisons be, avoid being too precise due to floating point issues
Variables ¶
This section is empty.
Functions ¶
func EuclideanDistance ¶
func GetUnitNormalVector ¶
func PrecisionCompare ¶
compare a and b and consider them equal if difference is less than precision e (e.g. e=0.001)
func TruncateDecimals ¶
TruncateDecimals truncates floats to keep up to 3 digits after decimal, to avoid issues with floats on different machines. Since we're not launching rockets, 3 decimals is enough precision for what we're doing
Types ¶
type BezierCurve ¶
func NewBezierCurve ¶
func NewBezierCurve(points []*Point) *BezierCurve
func (BezierCurve) At ¶
func (bc BezierCurve) At(point float64) *Point
func (BezierCurve) Intersections ¶
func (bc BezierCurve) Intersections(segment Segment) []*Point
type Box ¶
func (*Box) Intersections ¶
func (*Box) Intersects ¶ added in v0.2.5
Intersects returns true if the segment comes within buffer of the box
type Intersectable ¶
type Orientation ¶
type Orientation int
const ( TopLeft Orientation = iota TopRight BottomLeft BottomRight Top Right Bottom Left NONE )
func (Orientation) GetOpposite ¶
func (o Orientation) GetOpposite() Orientation
func (Orientation) IsDiagonal ¶
func (o Orientation) IsDiagonal() bool
func (Orientation) IsHorizontal ¶
func (o Orientation) IsHorizontal() bool
func (Orientation) IsVertical ¶
func (o Orientation) IsVertical() bool
func (Orientation) SameSide ¶
func (o1 Orientation) SameSide(o2 Orientation) bool
func (Orientation) ToString ¶
func (o Orientation) ToString() string
type Point ¶
func IntersectionPoint ¶
get the point of intersection between line segments u and v (or nil if they do not intersect)
func (*Point) DistanceToLine ¶
https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
func (*Point) FormattedCoordinates ¶
func (*Point) GetOrientation ¶
func (pFrom *Point) GetOrientation(pTo *Point) Orientation
GetOrientation gets orientation of pFrom to pTo E.g. pFrom ---> pTo, here, pFrom is to the left of pTo, so Left would be returned
func (*Point) Interpolate ¶ added in v0.4.2
point t% of the way between a and b
func (*Point) OnOrthogonalSegment ¶ added in v0.2.5
returns true if point p is on orthogonal segment between points a and b
func (*Point) TruncateDecimals ¶ added in v0.5.0
func (p *Point) TruncateDecimals()
func (*Point) TruncateFloat32 ¶ added in v0.5.0
func (p *Point) TruncateFloat32()
type Points ¶
type Points []*Point
func RemovePoints ¶ added in v0.5.0
RemovePoints returns a new Points slice without the points in toRemove
type RelativePoint ¶
func NewRelativePoint ¶
func NewRelativePoint(xPercentage, yPercentage float64) *RelativePoint
type Route ¶
type Route []*Point
func (Route) GetBoundingBox ¶
func (Route) GetPointAtDistance ¶
return the point at _distance_ along the route, and the index of the segment it's on
type Segment ¶
func NewSegment ¶
func (*Segment) GetBounds ¶
getBounds takes a segment and returns the floor and ceil of where it can shift to If there is no floor or ceiling, negative or positive infinity is used, respectively The direction is inferred, e.g. b/c the passed in segment is vertical, it's inferred we want horizontal bounds buffer says how close the segment can be, on both axes, to other segments given . │ │ . │ │ . │ │ . │ │ . │ non-overlap . │ . │ . │ . │ segment . │ │ . │ │ ceil . │ │ │ . │ │ . floor │ │ . │ . │ . │ . │ NOTE: the assumption is that all segments given are orthogonal