pkg

package
v0.0.0-...-9f2c538 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EarthRadius = 6378137
	Epsilon     = 1e-6
)

Variables

View Source
var (
	ErrNodeExists       = errors.New("node already exists")
	ErrEdgeExists       = errors.New("edge already exists")
	ErrNodeNotFound     = errors.New("node not found")
	ErrEdgeNotFound     = errors.New("edge not found")
	ErrNodeNotReachable = errors.New("node not reachable")
)

Functions

This section is empty.

Types

type Edge

type Edge struct {
	ID     string  `json:"id"`
	Start  string  `json:"start"`
	End    string  `json:"end"`
	Speed  float64 `json:"speed"`
	Poly   []Point `json:"polygon"`
	Length float64 `json:"length"`
}

func NewEdge

func NewEdge(id string, start, end *Node, speed float64, poly []Point) (edge *Edge)

func (*Edge) LengthFrom

func (e *Edge) LengthFrom(point Point) float64

func (*Edge) LengthTo

func (e *Edge) LengthTo(point Point) (length float64)

type Graph

type Graph struct {
	Nodes map[string]*Node `json:"nodes"`
	Edges map[string]*Edge `json:"edges"`
	Seg   *Segment2D       `json:"-"`
}

func NewGraph

func NewGraph() (graph *Graph)

func (*Graph) AddEdge

func (g *Graph) AddEdge(id string, start, end *Node, speed float64, poly []Point) (*Edge, error)

func (*Graph) AddNode

func (g *Graph) AddNode(id string, position Point) (*Node, error)

func (*Graph) GetBestPath

func (g *Graph) GetBestPath(start, end *Node, maxDuration float64, reverse bool) ([]*Edge, error)

func (*Graph) GetDistance

func (g *Graph) GetDistance(start, end *Node, maxDuration float64, reverse bool) (float64, error)

func (*Graph) GetEdge

func (g *Graph) GetEdge(id string) (*Edge, error)

func (*Graph) GetNode

func (g *Graph) GetNode(id string) (*Node, error)

type Heap

type Heap struct {
	Objects []interface{}
	Less    func(a, b interface{}) bool
}

func NewHeap

func NewHeap(less func(a, b interface{}) bool) *Heap

func (*Heap) Length

func (h *Heap) Length() int

func (*Heap) Peek

func (h *Heap) Peek() interface{}

func (*Heap) Pop

func (h *Heap) Pop() interface{}

func (*Heap) Push

func (h *Heap) Push(obj interface{})

type Node

type Node struct {
	ID       string                 `json:"id"`
	Position Point                  `json:"position"`
	InEdges  map[*Node]*Edge        `json:"-"`
	OutEdges map[*Node]*Edge        `json:"-"`
	Data     map[bool]*dijkstraData `json:"-"`
}

type Point

type Point struct {
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
}

func (*Point) ClosestPointOnEdge

func (p *Point) ClosestPointOnEdge(edge *Edge) (closestPoint Point)

func (*Point) ClosestPointOnSegment

func (p *Point) ClosestPointOnSegment(a, b Point) Point

func (*Point) Distance

func (p *Point) Distance(other Point) float64

func (*Point) DistanceToEdge

func (p *Point) DistanceToEdge(edge *Edge) float64

func (*Point) IsOnSegment

func (p *Point) IsOnSegment(a, b Point) bool

func (*Point) Move

func (p *Point) Move(dx, dy float64) Point

func (*Point) MoveTowards

func (a *Point) MoveTowards(b Point, d float64) Point

type Segment2D

type Segment2D struct {
	Start float64
	End   float64
	Seg   *segment
	Left  *Segment2D
	Right *Segment2D
}

func NewSegment2D

func NewSegment2D(nodes []*SegmentNode) *Segment2D

func (*Segment2D) Get

func (s *Segment2D) Get(point Point, distance float64) []*Edge

func (*Segment2D) GetInterval

func (s *Segment2D) GetInterval(l1, r1, l2, r2 float64) []*Edge

type SegmentNode

type SegmentNode struct {
	Point Point
	Edge  *Edge
}

Jump to

Keyboard shortcuts

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