connector_routing/lib.rs
1//! # Connector routing
2//!
3//! Global connector routing: route many connectors at once around rectangular obstacles
4//! (diagram nodes, schematic parts, cabinets in a cable plan), minimising length, bends,
5//! crossings and overlaps, and place the final segments apart from each other.
6//!
7//! All geometry is exact integer arithmetic ([`Point`] coordinates within
8//! [`MAX_COORD`]); there are no floating-point robustness issues and results are
9//! reproducible. The crate is `no_std` and needs only `alloc`.
10//!
11//! ## Orthogonal routing
12//!
13//! ```mermaid
14//! flowchart LR
15//! S[Scene: obstacles, ports, OVG] --> A[route: one connector]
16//! S --> G[global::route_all: PathFinder]
17//! G --> C[crossing::reduce_crossings]
18//! C --> N[nudge::nudge]
19//! P[pipeline::draw] --> S
20//! ```
21//!
22//! - [`Scene`]: obstacles and [`Port`]s with their orthogonal visibility graph
23//! (Wybrow, Marriott and Stuckey 2009), updated incrementally as obstacles and ports
24//! change. [`incremental`] reports which committed routes a change affects.
25//! - [`route`](fn@route): the optimal route of one connector under an [`Objective`] (length and
26//! bends, exact lexicographic orders available), by A* over `(vertex, heading)`; the
27//! 1-bend visibility graph of Marriott et al. (2014) is available as [`Search::OneBend`].
28//! - [`global::route_all`]: many connectors with `PathFinder` negotiated congestion over
29//! channel capacities, rip-up and reroute, and crossing penalties.
30//! - [`crossing`]: required crossings between routes, crossing reduction, and the
31//! crossing points of finished routes for drawing hops.
32//! - [`nudge`]: ordering of shared segments and exact separation by difference
33//! constraints (no LP); the constraints are exported for layout engines.
34//! - [`pipeline::draw`]: the pipeline of arXiv 2309.01671 from boxes and edges to a
35//! drawing, port assignment included.
36//! - [`hyperedge`]: nets with more than two ports as rectilinear Steiner trees
37//! (Wybrow et al. 2012).
38//! - [`check`]: independent validation of routes.
39//!
40//! ## Any-angle routing
41//!
42//! - [`sleeve`]: sleeve routing through an exact constrained Delaunay triangulation
43//! with the funnel algorithm (arXiv 2605.17498).
44//! - [`polyline`]: incremental shortest poly-line routing over the visibility graph
45//! (Wybrow et al. 2005).
46//!
47//! ## Features
48//!
49//! - `multi-objective`: `pareto::front`, the Pareto front of one connector over
50//! length, bends and crossings (NAMOA*dr from `multiobjective-search`).
51//!
52//! ## Example
53//!
54//! ```
55//! use connector_routing::{Connector, DirSet, Point, Port, Rect, Scene, check, global, nudge};
56//!
57//! let mut scene = Scene::new();
58//! let boxes = [Rect::new(0, 0, 20, 10), Rect::new(60, 0, 80, 10), Rect::new(30, -30, 50, 40)];
59//! for b in boxes {
60//! scene.add_obstacle(b)?;
61//! }
62//!
63//! // Two connectors from the left box to the right box, around the box in between.
64//! let a = scene.add_port(Port::new(Point::new(20, 3), DirSet::RIGHT))?;
65//! let b = scene.add_port(Port::new(Point::new(60, 3), DirSet::LEFT))?;
66//! let c = scene.add_port(Port::new(Point::new(20, 7), DirSet::RIGHT))?;
67//! let d = scene.add_port(Port::new(Point::new(60, 7), DirSet::LEFT))?;
68//! let connectors = [Connector { source: a, target: b }, Connector { source: c, target: d }];
69//!
70//! let routing = global::route_all(&scene, &connectors, &global::Config::default())?;
71//! let nudged = nudge::nudge(scene.graph(), &boxes, &routing.routes, &nudge::Config::default());
72//! for route in &nudged.routes {
73//! assert!(check::orthogonal(route, &boxes).is_ok());
74//! }
75//!
76//! assert_eq!(nudged.overlaps, 0);
77//! # Ok::<(), connector_routing::Error>(())
78//! ```
79//!
80//! See `docs/design.md` for the models, the deviations from the papers found by
81//! testing, and the paper table.
82//!
83//! Repository: <https://github.com/sunsided/connector-routing>
84
85#![no_std]
86#![forbid(unsafe_code)]
87
88extern crate alloc;
89
90pub mod check;
91pub mod crossing;
92mod error;
93mod geom;
94pub mod global;
95mod graph;
96pub mod hyperedge;
97pub mod incremental;
98mod nets;
99pub mod nudge;
100#[cfg(feature = "multi-objective")]
101pub mod pareto;
102pub mod pipeline;
103pub mod polyline;
104mod route;
105mod scene;
106mod search;
107pub mod sleeve;
108
109/// Doctests for the code examples in README.md (not part of the API).
110#[cfg(doctest)]
111#[doc = include_str!("../README.md")]
112mod readme_doctests {}
113
114pub use error::Error;
115pub use geom::{Axis, DirSet, Direction, MAX_COORD, Point, Rect, Side};
116pub use graph::{RoutingGraph, VertexId};
117pub use nets::Net;
118pub use route::{Route, simplify};
119pub use scene::{ObstacleId, Port, PortId, Scene};
120pub use search::{
121 EdgeCosts, Endpoints, Objective, PlainCosts, Search, Weights, cost_of, endpoints, min_bends,
122 route, route_vertices,
123};
124
125/// A connector to route between two ports.
126#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
127pub struct Connector<P> {
128 /// The port the connector starts at.
129 pub source: P,
130 /// The port the connector ends at.
131 pub target: P,
132}