maths

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 8 Imported by: 21

Documentation

Overview

Package math contains generic math functions that we need for doing transforms. this package will augment the go math library.

Index

Constants

View Source
const (
	LEFT eventType = iota
	RIGHT
)
View Source
const (
	WebMercator = webmercator.SRID
	WGS84       = tegola.WGS84
	Deg2Rad     = math.Pi / 180
	Rad2Deg     = 180 / math.Pi
	PiDiv2      = math.Pi / 2.0
	PiDiv4      = math.Pi / 4.0
)

Variables

This section is empty.

Functions

func AreaOfPolygon

func AreaOfPolygon(p tegola.Polygon) (area float64)

AreaOfPolygon will calculate the Area of a polygon using the surveyor's formula (https://en.wikipedia.org/wiki/Shoelace_formula)

func AreaOfPolygonLineString added in v0.4.0

func AreaOfPolygonLineString(line tegola.LineString) (area float64)

func AreaOfRing added in v0.4.0

func AreaOfRing(points ...Pt) (area float64)

func AreaOfTriangle added in v0.4.0

func AreaOfTriangle(v0, v1, v2 Pt) float64

func Contains added in v0.4.0

func Contains(subject []float64, pt Pt) (bool, error)

Contains takes a subject (made up of point pairs) and a pt, and returns weather the pt is contained by the subject.

func DegToRad

func DegToRad(deg float64) float64

func DistOfLine added in v0.4.0

func DistOfLine(l tegola.LineString) (dist float64)

DistOfLine will calculate the Manhattan distance of a line.

func DoesIntersect added in v0.4.0

func DoesIntersect(s1, s2 Line) bool

DoesIntersect does a quick intersect check using the saddle method.

func Exp2 added in v0.7.0

func Exp2(p uint64) uint64

Powers of 2

func FindAllIntersectsWithEventQueueWithoutIntersectNotPolygon added in v0.4.0

func FindAllIntersectsWithEventQueueWithoutIntersectNotPolygon(eq []event, segments []Line, skipfn func(srcIdx, destIdx int) bool, fn func(srcIdx, destIdx int))

func FindIntersects added in v0.4.0

func FindIntersects(segments []Line, fn func(srcIdx, destIdx int, ptfn func() Pt) bool)

FindIntersects call the provided function with the indexs of the lines from the segments slice that intersect with each other. If the function returns false, it will stop iteration. To find the intersection point call the ptfn that is passed to the call back.

func FindIntersectsWithEventQueue added in v0.4.0

func FindIntersectsWithEventQueue(polygonCheck bool, eq []event, segments []Line, fn func(srcIdx, destIdx int, ptfn func() Pt) bool)

func FindIntersectsWithEventQueueWithoutIntersect added in v0.4.0

func FindIntersectsWithEventQueueWithoutIntersect(polygonCheck bool, eq []event, segments []Line, fn func(srcIdx, destIdx int) bool)

func FindIntersectsWithEventQueueWithoutIntersectNew added in v0.4.0

func FindIntersectsWithEventQueueWithoutIntersectNew(polygonCheck bool, eq []event, segments []Line, fn func(srcIdx, destIdx int) bool)

func FindIntersectsWithEventQueueWithoutIntersectNotPolygon added in v0.4.0

func FindIntersectsWithEventQueueWithoutIntersectNotPolygon(eq []event, segments []Line, fn func(srcIdx, destIdx int) bool)

func FindIntersectsWithoutIntersect added in v0.4.0

func FindIntersectsWithoutIntersect(segments []Line, fn func(srcIdx, destIdx int) bool)

FindIntersects call the provided function with the indexs of the lines from the segments slice that intersect with each other. If the function returns false, it will stop iteration. To find the intersection point call the ptfn that is passed to the call back.

func FindPolygonIntersects added in v0.4.0

func FindPolygonIntersects(segments []Line, fn func(srcIdx, destIdx int, ptfn func() Pt) bool)

FindPolygonIntersects calls the provided function with the indexes of the lines from the segments slice that intersect with each other. If the function returns false, it will stop iteration. To find the intersection point call the ptfn that is passed to the call back. The function assumes that the the segments are consecutive.

func MakeValid added in v0.4.0

func MakeValid(plygs ...[]Line) (polygons [][][]Pt, err error)

func Min added in v0.7.0

func Min(x, y uint) uint

Minimum of uints

func NewEventQueue added in v0.4.0

func NewEventQueue(segments []Line) []event

Code adapted from http://geomalgorithms.com/a09-_intersect-3.html#simple_Polygon()

func PointPairs added in v0.4.0

func PointPairs(pts []Pt) ([][2]Pt, error)

func RadToDeg

func RadToDeg(rad float64) float64

func XYOrder added in v0.4.0

func XYOrder(pt1, pt2 Pt) int

func YXorder added in v0.4.0

func YXorder(pt1, pt2 Pt) int

Types

type ByXY added in v0.4.0

type ByXY []Pt

func (ByXY) Len added in v0.4.0

func (t ByXY) Len() int

func (ByXY) Less added in v0.4.0

func (t ByXY) Less(i, j int) bool

func (ByXY) Swap added in v0.4.0

func (t ByXY) Swap(i, j int)

type ByXYLine added in v0.4.0

type ByXYLine []Line

func (ByXYLine) Len added in v0.4.0

func (t ByXYLine) Len() int

func (ByXYLine) Less added in v0.4.0

func (t ByXYLine) Less(i, j int) bool

func (ByXYLine) Swap added in v0.4.0

func (t ByXYLine) Swap(i, j int)

type EdgeMap added in v0.4.0

type EdgeMap struct {
	Keys     []Pt
	Map      map[Pt]map[Pt]bool
	Segments []Line
	BBox     [4]Pt
	// contains filtered or unexported fields
}

func (*EdgeMap) Dump added in v0.4.0

func (em *EdgeMap) Dump()

func (*EdgeMap) FindTriangles added in v0.4.0

func (em *EdgeMap) FindTriangles() (*TriangleGraph, error)

func (*EdgeMap) SubKeys added in v0.4.0

func (em *EdgeMap) SubKeys(pt Pt) (skeys []Pt, ok bool)

func (*EdgeMap) Triangulate added in v0.4.0

func (em *EdgeMap) Triangulate()

func (*EdgeMap) Triangulate1 added in v0.4.0

func (em *EdgeMap) Triangulate1()

type Eventer added in v0.4.0

type Eventer interface {
	Point() *Pt
	Edge() int
}

type Label added in v0.4.0

type Label uint8

label is the he label for the triangle. Is in "inside" or "outside". TODO: gdey — would be make more sense to just have a bool here? IsInside or somthing like that?

const (
	Unknown Label = iota
	Outside
	Inside
)

func (Label) String added in v0.4.0

func (l Label) String() string

type Line added in v0.4.0

type Line [2]Pt

func NewLine added in v0.4.0

func NewLine(x1, y1, x2, y2 float64) Line

func NewLineFloat64 added in v0.6.0

func NewLineFloat64(ln [2][2]float64) Line

func NewLineWith2Float64 added in v0.6.0

func NewLineWith2Float64(ln [2][2]float64) Line

NewLineWith2Float64 is a transistional function till I have had a change to move over the geom package and covert the maths functions to use it or they have migrated over to it. TODO: gdey – remove this function one the transition is over.

func NewLinesFloat64 added in v0.6.0

func NewLinesFloat64(ln ...[2][2]float64) (lns []Line)

func NewSegments added in v0.4.0

func NewSegments(f []float64) (lines []Line, err error)

func (Line) Clamp added in v0.4.0

func (l Line) Clamp(pt Pt) (p Pt)

Clamp will return a point that is on the line based on pt. It will do this by restricting each of the coordinates to the line.

func (Line) DeltaX added in v0.4.0

func (l Line) DeltaX() float64

DeltaX returns the difference between the x coordinates of point2 and point1.

func (Line) DeltaY added in v0.4.0

func (l Line) DeltaY() float64

DeltaY returns the difference between the y coordinates of point2 and point1.

func (Line) DistanceFromPoint added in v0.4.0

func (l Line) DistanceFromPoint(pt Pt) float64

InsideEx will return true if the given point is consider to be on the inside of the line, for the given winding order. The inside region excludes the line. For clockwise the inside edge for a line heading in the upward direction is any point to the right of the line. For clockwise the inside edge for a line heading in the downward direction is any point to the left of the line. For clockwise the inside edge for a line heading in the rightward direction is any point to the bottom of the line. For clockwise the inside edge for a line heading in the leftward direction is any point above the line.

func (l Line) InsideEx(w WindingOrder, pt Pt) bool { insideX, insideY := true, true clockwise = w.IsClockwise()

deltaX := l[1].X - l[0].X
deltaY := l[1].Y - l[0].Y

// Dealing with a horizontal line.
if deltaX == 0 {
     ptDelta := l[0].X - pt.X
     if clockwise {

     }
}

switch {
case w.IsClockwise() && deltaX > 0: // right ward.
	goody =

}

}

DistanceFromPoint will return the perpendicular distance from the point.

func (Line) DoesIntersect added in v0.4.0

func (s1 Line) DoesIntersect(s2 Line) bool

=================================== LINE methods ================================================= //

func (Line) ExInBetween added in v0.4.0

func (l Line) ExInBetween(pt Pt) bool

func (Line) InBetween added in v0.4.0

func (l Line) InBetween(pt Pt) bool

InBetween will check to see if the given point lies on the line provided between the endpoints.

func (Line) IntersectsLines added in v0.4.0

func (l Line) IntersectsLines(lines []Line, fn func(idx int) bool)

IntersectsLines call fn with line, and intersect point that the line intersects with. from the given set of lines that intersect this line and their intersect points.

func (Line) IsHorizontal added in v0.4.0

func (l Line) IsHorizontal() bool

func (Line) IsLeft added in v0.4.0

func (l Line) IsLeft(pt Pt) float64

IsLeft tests if point P2 is Left|On|Right of the line P0 to P1.

returns: >0 for left, 0 for on, and <0 for  right of the line.

func (Line) IsVertical added in v0.4.0

func (l Line) IsVertical() bool

func (Line) LeftRightMostAsLine added in v0.4.0

func (l1 Line) LeftRightMostAsLine() Line

LeftRightMostAsLine returns the left most and right most points as a line going from the left to the right.

func (Line) LeftRightMostPts added in v0.4.0

func (l Line) LeftRightMostPts() (Pt, Pt)

LeftRightMostPt returns the left and right most points of the vertexes of the line.

func (Line) SlopeIntercept added in v0.4.0

func (l Line) SlopeIntercept() (m, b float64, defined bool)

SlopeIntercept will find the slop (if there is one) and the intercept of the line. If there isn't a slope because the line is verticle, the defined will be false.

func (Line) XYOrderedPtsIdx added in v0.4.0

func (l Line) XYOrderedPtsIdx() (left, right int)

type PointList added in v0.4.0

type PointList struct {
	Head *PointNode
	Tail *PointNode
	// contains filtered or unexported fields
}

func NewPointList added in v0.4.0

func NewPointList(line Line) PointList

func (PointList) AsRing added in v0.4.0

func (pl PointList) AsRing() (r Ring)

func (*PointList) IsComplete added in v0.4.0

func (pl *PointList) IsComplete() bool

func (*PointList) TryAddLine added in v0.4.0

func (pl *PointList) TryAddLine(l Line) (ok bool)

type PointNode added in v0.4.0

type PointNode struct {
	Pt   Pt
	Next *PointNode
}

type Pointer added in v0.4.0

type Pointer interface {
	Point() Pt
}

type Pt added in v0.4.0

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

Pt describes a 2d Point.

func Intersect added in v0.4.0

func Intersect(l1, l2 Line) (pt Pt, ok bool)

Intersect find the intersection point (x,y) between two lines if there is one. Ok will be true if it found an intersection point, and false if it did not.

func NewPoints added in v0.4.0

func NewPoints(f []float64) (pts []Pt, err error)

func (Pt) Coords added in v0.4.0

func (pt Pt) Coords() []float64

func (Pt) Delta added in v0.4.0

func (pt Pt) Delta(pt2 Pt) (d Pt)

func (*Pt) GoString added in v0.4.0

func (pt *Pt) GoString() string

func (Pt) IsEqual added in v0.4.0

func (pt Pt) IsEqual(pt2 Pt) bool

func (Pt) Round added in v0.4.0

func (pt Pt) Round() Pt

func (Pt) String added in v0.4.0

func (pt Pt) String() string

func (Pt) Truncate added in v0.4.0

func (pt Pt) Truncate() Pt

func (Pt) XCoord added in v0.4.0

func (pt Pt) XCoord() float64

func (Pt) YCoord added in v0.4.0

func (pt Pt) YCoord() float64

type Rectangle added in v0.4.0

type Rectangle [2][2]float64

func (Rectangle) Contains added in v0.4.0

func (r Rectangle) Contains(pt Pt) bool

type Ring added in v0.4.0

type Ring []Pt

Ring defines a set of points that are all connected. The last point and the first point should not be duplicated.

type Triangle added in v0.4.0

type Triangle [3]Pt

func NewTriangle added in v0.4.0

func NewTriangle(pt1, pt2, pt3 Pt) (tri Triangle)

Will create a new Triangle and sort the points.k

func (*Triangle) Area added in v0.4.0

func (t *Triangle) Area() float64

func (*Triangle) Center added in v0.4.0

func (t *Triangle) Center() Pt

func (*Triangle) Edge added in v0.4.0

func (t *Triangle) Edge(n int) Line

func (*Triangle) EdgeIdx added in v0.4.0

func (t *Triangle) EdgeIdx(pt1, pt2 Pt) int

func (*Triangle) Edges added in v0.4.0

func (t *Triangle) Edges() [3]Line

func (*Triangle) Equal added in v0.4.0

func (t *Triangle) Equal(t1 *Triangle) bool

func (*Triangle) EqualAnyPt added in v0.4.0

func (t *Triangle) EqualAnyPt(pts ...Pt) bool

func (*Triangle) FindEdge added in v0.4.0

func (t *Triangle) FindEdge(e Line) (idx int, err error)

func (*Triangle) Key added in v0.4.0

func (t *Triangle) Key() string

func (*Triangle) LREdge added in v0.4.0

func (t *Triangle) LREdge(n int) Line

func (*Triangle) LREdges added in v0.4.0

func (t *Triangle) LREdges() [3]Line

func (*Triangle) Len added in v0.4.0

func (t *Triangle) Len() int

func (*Triangle) Less added in v0.4.0

func (t *Triangle) Less(i, j int) bool

func (*Triangle) Point added in v0.4.0

func (t *Triangle) Point(i int) Pt

func (*Triangle) Points added in v0.4.0

func (t *Triangle) Points() []Pt

func (*Triangle) Swap added in v0.4.0

func (t *Triangle) Swap(i, j int)

If t is nil, we want to panic, as this this a programming bug.

type TriangleEdge added in v0.4.0

type TriangleEdge struct {
	Node          *TriangleNode
	IsConstrained bool
}

func (*TriangleEdge) Dump added in v0.4.0

func (te *TriangleEdge) Dump()

type TriangleGraph added in v0.4.0

type TriangleGraph struct {
	// contains filtered or unexported fields
}

func NewTriangleGraph added in v0.4.0

func NewTriangleGraph(tri []*TriangleNode, bbox [4]Pt) (tg *TriangleGraph)

func (*TriangleGraph) Inside added in v0.4.0

func (tg *TriangleGraph) Inside() []*TriangleNode

func (*TriangleGraph) Outside added in v0.4.0

func (tg *TriangleGraph) Outside() []*TriangleNode

func (*TriangleGraph) Rings added in v0.4.0

func (tg *TriangleGraph) Rings() (rings [][]Line)

func (*TriangleGraph) Triangles added in v0.4.0

func (tg *TriangleGraph) Triangles() []*TriangleNode

func (*TriangleGraph) TrianglesAsMP added in v0.4.0

func (tg *TriangleGraph) TrianglesAsMP() (mp [][][]Pt)

type TriangleNode added in v0.4.0

type TriangleNode struct {
	Triangle
	// Edge 0 has pt's 0 and 1.
	// Edge 1 has pt's 1 and 2.
	// Edge 2 has pt's 0 and 2.
	Neighbors [3]TriangleEdge
	Label     Label
}

func (*TriangleNode) Dump added in v0.4.0

func (tn *TriangleNode) Dump()

func (*TriangleNode) LabelAs added in v0.4.0

func (tn *TriangleNode) LabelAs(l Label, force bool) (unlabled []*TriangleNode)

type WindingOrder added in v0.4.0

type WindingOrder uint8

WindingOrder the direction the line strings.

const (
	Clockwise WindingOrder = iota
	CounterClockwise
)

func WindingOrderOf added in v0.4.0

func WindingOrderOf(sub []float64) WindingOrder

func WindingOrderOfLine added in v0.4.0

func WindingOrderOfLine(l tegola.LineString) WindingOrder

func WindingOrderOfPts added in v0.4.0

func WindingOrderOfPts(pts []Pt) WindingOrder

func (WindingOrder) IsClockwise added in v0.4.0

func (w WindingOrder) IsClockwise() bool

func (WindingOrder) IsCounterClockwise added in v0.4.0

func (w WindingOrder) IsCounterClockwise() bool

func (WindingOrder) Not added in v0.4.0

func (w WindingOrder) Not() WindingOrder

func (WindingOrder) String added in v0.4.0

func (w WindingOrder) String() string

type XYOrderedEventPtr added in v0.4.0

type XYOrderedEventPtr []event

func (XYOrderedEventPtr) Len added in v0.4.0

func (a XYOrderedEventPtr) Len() int

func (XYOrderedEventPtr) Less added in v0.4.0

func (a XYOrderedEventPtr) Less(i, j int) bool

func (XYOrderedEventPtr) Swap added in v0.4.0

func (a XYOrderedEventPtr) Swap(i, j int)

Directories

Path Synopsis
internal
Package webmercator does the translation to and from WebMercator and WGS84 Gotten from: http://wiki.openstreetmap.org/wiki/Mercator#C.23
Package webmercator does the translation to and from WebMercator and WGS84 Gotten from: http://wiki.openstreetmap.org/wiki/Mercator#C.23

Jump to

Keyboard shortcuts

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