geo

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MPL-2.0 Imports: 7 Imported by: 14

Documentation

Index

Constants

View Source
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 EuclideanDistance(x1, y1, x2, y2 float64) float64

func GetUnitNormalVector

func GetUnitNormalVector(x1, y1, x2, y2 float64) (float64, float64)

func PrecisionCompare

func PrecisionCompare(a, b, e float64) int

compare a and b and consider them equal if difference is less than precision e (e.g. e=0.001)

func Sign

func Sign(i float64) int

func TruncateDecimals

func TruncateDecimals(v float64) float64

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

type BezierCurve struct {
	Curve *bezier.Curve
	// contains filtered or unexported fields
}

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

type Box struct {
	TopLeft *Point
	Width   float64
	Height  float64
}

func NewBox

func NewBox(tl *Point, width, height float64) *Box

func (*Box) Center

func (b *Box) Center() *Point

func (*Box) Copy

func (b *Box) Copy() *Box

func (*Box) Intersections

func (b *Box) Intersections(s Segment) []*Point

func (*Box) ToString

func (b *Box) ToString() string

type Ellipse

type Ellipse struct {
	Center *Point
	Rx     float64
	Ry     float64
}

func NewEllipse

func NewEllipse(center *Point, rx, ry float64) *Ellipse

func (Ellipse) Intersections

func (e Ellipse) Intersections(segment Segment) []*Point

type Intersectable

type Intersectable interface {
	Intersections(segment Segment) []*Point
}

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

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

func ComputeIntersections

func ComputeIntersections(px, py, lx, ly []float64) []*Point

nolint

func IntersectionPoint

func IntersectionPoint(u0, u1, v0, v1 *Point) *Point

get the point of intersection between line segments u and v (or nil if they do not intersect)

func NewPoint

func NewPoint(x, y float64) *Point

func (*Point) AddVector

func (start *Point) AddVector(v Vector) *Point

Moves the given point by Vector

func (*Point) Compare

func (p1 *Point) Compare(p2 *Point) int

func (*Point) Copy

func (p *Point) Copy() *Point

func (*Point) Equals

func (p1 *Point) Equals(p2 *Point) bool

func (*Point) FormattedCoordinates

func (p *Point) FormattedCoordinates() string

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

func (q *Point) OnSegment(p, r *Point) bool

func (*Point) ToString

func (p *Point) ToString() string

func (*Point) ToVector added in v0.1.6

func (endpoint *Point) ToVector() Vector

Creates a Vector pointing to point

func (*Point) Transpose

func (p *Point) Transpose()

func (*Point) VectorTo

func (start *Point) VectorTo(endpoint *Point) Vector

Creates a Vector of the size between start and endpoint, pointing to endpoint

type Points

type Points []*Point

func (Points) Equals

func (ps Points) Equals(other Points) bool

func (Points) GetMedian

func (ps Points) GetMedian() *Point

func (Points) ToString

func (points Points) ToString() string

type RelativePoint

type RelativePoint struct {
	XPercentage float64
	YPercentage float64
}

func NewRelativePoint

func NewRelativePoint(xPercentage, yPercentage float64) *RelativePoint

type Route

type Route []*Point

func (Route) GetBoundingBox

func (route Route) GetBoundingBox() (tl, br *Point)

func (Route) GetPointAtDistance

func (route Route) GetPointAtDistance(distance float64) (*Point, int)

return the point at _distance_ along the route, and the index of the segment it's on

func (Route) Length

func (route Route) Length() float64

type Segment

type Segment struct {
	Start *Point
	End   *Point
}

func NewSegment

func NewSegment(from, to *Point) *Segment

func (*Segment) GetBounds

func (segment *Segment) GetBounds(segments []*Segment, buffer float64) (float64, float64)

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

func (Segment) Intersections

func (segment Segment) Intersections(otherSegment Segment) []*Point

func (Segment) Length added in v0.1.6

func (segment Segment) Length() float64

func (Segment) Overlaps

func (s Segment) Overlaps(otherS Segment, isHorizontal bool, buffer float64) bool

func (Segment) ToString

func (s Segment) ToString() string

func (Segment) ToVector added in v0.1.6

func (segment Segment) ToVector() Vector

type Vector

type Vector []float64

A N-Dimensional Vector with components (x, y, z, ...) based on the origin

func NewVector

func NewVector(components ...float64) Vector

New Vector from components

func NewVectorFromProperties

func NewVectorFromProperties(length float64, angleInRadians float64) Vector

New Vector of length and pointing in the direction of angle

func (Vector) Add

func (a Vector) Add(b Vector) Vector

func (Vector) AddLength

func (a Vector) AddLength(length float64) Vector

Creates a Vector by extending the length of the current one by length

func (Vector) Degrees added in v0.1.6

func (a Vector) Degrees() float64

func (Vector) Length

func (a Vector) Length() float64

func (Vector) Minus

func (a Vector) Minus(b Vector) Vector

func (Vector) Multiply

func (a Vector) Multiply(v float64) Vector

func (Vector) Radians added in v0.1.6

func (a Vector) Radians() float64

func (Vector) Reverse added in v0.1.6

func (a Vector) Reverse() Vector

func (Vector) ToPoint

func (a Vector) ToPoint() *Point

func (Vector) Unit

func (a Vector) Unit() Vector

Creates an unit Vector pointing in the same direction of this Vector

Jump to

Keyboard shortcuts

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