route

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package route routes a rendering's edges orthogonally around its boxes with libavoid, the router the diagram panel bundles, run as WebAssembly in-process, and straightens the result as the panel does, so both draw the same routes.

Index

Constants

View Source
const (
	Gap               = 32.0
	PortSize          = 10.0
	Clearance         = Gap / 2
	Nudging           = 8.0
	MinJog            = 16.0
	ExclusivePinLimit = 12
)

The panel's routing constants: a GAP between slots, PORT_SIZE for a port square.

View Source
const WasmPathEnv = "OPENSYSML_LIBAVOID_WASM"

WasmPathEnv names the environment variable that points at a libavoid WebAssembly module to route with instead of the embedded one.

Variables

View Source
var ErrUnavailable = errors.New("libavoid: no router in this build")

ErrUnavailable is what Routes returns in a build without the router: the js and wasip1 builds, which leave routing to the drawing program.

Functions

This section is empty.

Types

type Box

type Box struct {
	X, Y, Width, Height float64
}

Box is an axis-aligned rectangle given by its top-left corner and size.

type Edge

type Edge struct {
	Index    int
	From, To string
	FromPort string
	ToPort   string
}

Edge is a connector to route between two shapes, optionally at named ports.

type Obstacle

type Obstacle struct {
	Routing Box
	Raw     Box
}

Obstacle holds a shape's routing-clearance bounds and its raw interior.

func RoutingObstacle

func RoutingObstacle(shape Shape) Obstacle

RoutingObstacle builds the routing geometry shared by libavoid and route simplification.

type PinPosition

type PinPosition struct {
	ID    string
	Named bool
	Side  Side
	X, Y  float64
}

PinPosition is a libavoid pin as proportions (0..1) of the shape's routing box.

func RoutingPinPositions

func RoutingPinPositions(shape *Shape) []PinPosition

RoutingPinPositions computes bounded libavoid portions for a shape's generic and named pins.

type Point

type Point struct {
	X, Y float64
}

Point is a position on the canvas.

func CompactRoute

func CompactRoute(route []Point) []Point

CompactRoute removes zero-length and same-direction collinear points from an orthogonal route.

func PortCenter

func PortCenter(box Box, port Port) Point

PortCenter is the point on the border where a port sits.

func PortFace

func PortFace(box Box, port Port) Point

PortFace is the outer face of the port square straddling the border.

type Port

type Port struct {
	ID     string
	Side   Side
	Offset float64
	Flush  bool
}

Port is a connection point on a shape's border at Offset (0..1) along Side; a Flush port sits on the border itself with no square straddling it.

type Route

type Route struct {
	Index  int
	Points []Point
}

Route is the orthogonal polyline found for the edge at Index.

func Routes

func Routes(shapes []Shape, edges []Edge, bounds *Box) ([]Route, error)

Routes is the orthogonal route of each edge the router found a path for, from its source to its target with every bend between, under the edge's Index; an edge whose ends are not among the shapes has none. Routes stay inside bounds when given. The js and wasip1 builds return ErrUnavailable.

func StraightenJogs

func StraightenJogs(routes []Route, obstacles []obstacle, ends map[int][2]string, bounds *Box) []Route

StraightenJogs straightens short Z-jogs without losing clearance or adding wire crossings; obstacles and ends are keyed by shape ID and edge index.

type Shape

type Shape struct {
	ID    string
	Box   Box
	Ports []Port
}

Shape is an obstacle connectors route around and attach to.

type Side

type Side string

Side is a border of a box.

const (
	North Side = "north"
	East  Side = "east"
	South Side = "south"
	West  Side = "west"
)

The four sides of a box.

func (Side) Vertical

func (s Side) Vertical() bool

Vertical reports whether the side is the top or bottom border, along which an offset runs horizontally.

Jump to

Keyboard shortcuts

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