SILICON
Loading...
Searching...
No Matches
wireRouting.cpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "wireRouting.hpp"
19
20#include <algorithm>
21#include <array>
22#include <bit>
23#include <cmath>
24#include <cstddef>
25#include <deque>
26#include <map>
27#include <set>
28#include <span>
29#include <stdexcept>
30#include <utility>
31#include <vector>
32
33#include <libavoid/libavoid.h>
34#include <libavoid/qtgeomtypes.h>
35
36namespace SILICON::core {
37
38namespace {
39
40 QPointF nearestPointOutside(const QPointF point, const QRectF& rect)
41 {
42 const QRectF normalized = rect.normalized();
43 if (!normalized.contains(point))
44 return point;
45
46 struct Candidate {
47 QPointF point;
48 qreal distanceSquared;
49 };
50
51 const std::array candidates = {
52 Candidate{QPointF(normalized.left(), point.y()),
53 (point.x() - normalized.left()) * (point.x() - normalized.left())},
54 Candidate{QPointF(normalized.right(), point.y()),
55 (point.x() - normalized.right()) * (point.x() - normalized.right())},
56 Candidate{QPointF(point.x(), normalized.top()),
57 (point.y() - normalized.top()) * (point.y() - normalized.top())},
58 Candidate{QPointF(point.x(), normalized.bottom()),
59 (point.y() - normalized.bottom()) * (point.y() - normalized.bottom())},
60 };
61
62 const auto closest =
63 std::ranges::min_element(candidates, {}, &Candidate::distanceSquared);
64 return closest->point;
65 }
66
67} // namespace
68
69void configureOrthogonalRouter(Avoid::Router& router, const qreal gridSize)
70{
71 Q_ASSERT(gridSize > 0);
72
73 // A shared run between different logical nets is ambiguous. Give it a prohibitive
74 // cost and nudge overlapping connectors by at least one complete grid lane so
75 // snapping cannot collapse them back onto the same coordinates.
76 router.setRoutingPenalty(Avoid::segmentPenalty, 500.0);
77 router.setRoutingPenalty(Avoid::fixedSharedPathPenalty, 1'000'000.0);
78 router.setRoutingPenalty(Avoid::idealNudgingDistance, gridSize);
79
80 router.setRoutingOption(Avoid::nudgeOrthogonalSegmentsConnectedToShapes, true);
81 router.setRoutingOption(Avoid::improveHyperedgeRoutesMovingJunctions, false);
82 router.setRoutingOption(Avoid::penaliseOrthogonalSharedPathsAtConnEnds, true);
83 router.setRoutingOption(Avoid::nudgeOrthogonalTouchingColinearSegments, true);
84 router.setRoutingOption(Avoid::nudgeSharedPathsWithCommonEndPoint, true);
85}
86
87std::vector<QPointF> extractOrthogonalRoute(Avoid::ConnRef& connector,
88 const qreal gridSize)
89{
90 Q_ASSERT(gridSize > 0);
91
92 // Vendored libavoid guarantees that its post-processed orthogonal display route is
93 // still terminal-complete and orthogonal. Quantize it to the editor grid and remove
94 // redundant vertices in one place for every routing workflow.
95 const auto& route = connector.displayRoute();
96 if (route.size() < 2)
97 return {};
98
99 auto snapCoordinate = [gridSize](const qreal value) {
100 return std::round(value / gridSize) * gridSize;
101 };
102
103 std::vector<QPointF> points;
104 points.reserve(route.size());
105 for (std::size_t i = 0; i < route.size(); ++i) {
106 const QPointF point = Avoid::toQPointF(route.at(i));
107 points.emplace_back(snapCoordinate(point.x()), snapCoordinate(point.y()));
108 }
109
110 points = canonicalizeOrthogonalRoute(std::move(points));
111 Q_ASSERT(isOrthogonalRoute(points));
112 return points;
113}
114
115bool isOrthogonalRoute(const std::span<const QPointF> points)
116{
117 for (std::size_t i = 1; i < points.size(); ++i) {
118 if (points[i - 1].x() != points[i].x() && points[i - 1].y() != points[i].y())
119 return false;
120 }
121 return true;
122}
123
124bool orthogonalRouteSelfIntersects(const std::span<const QPointF> points)
125{
126 Q_ASSERT(isOrthogonalRoute(points));
127
128 for (std::size_t i = 1; i < points.size(); ++i) {
129 const QPointF& a = points[i - 1];
130 const QPointF& b = points[i];
131 if (a == b)
132 continue;
133
134 bool adjacent = true;
135 for (std::size_t j = i + 1; j < points.size(); ++j) {
136 const QPointF& c = points[j - 1];
137 const QPointF& d = points[j];
138 if (c == d)
139 continue;
140 const bool sharesVertex = adjacent;
141 adjacent = false;
142
143 const bool firstHorizontal = a.y() == b.y();
144 const bool secondHorizontal = c.y() == d.y();
145 if (firstHorizontal == secondHorizontal) {
146 const qreal firstAxis = firstHorizontal ? a.y() : a.x();
147 const qreal secondAxis = secondHorizontal ? c.y() : c.x();
148 if (firstAxis != secondAxis)
149 continue;
150 const qreal overlapStart = firstHorizontal
151 ? std::max(std::min(a.x(), b.x()), std::min(c.x(), d.x()))
152 : std::max(std::min(a.y(), b.y()), std::min(c.y(), d.y()));
153 const qreal overlapEnd = firstHorizontal
154 ? std::min(std::max(a.x(), b.x()), std::max(c.x(), d.x()))
155 : std::min(std::max(a.y(), b.y()), std::max(c.y(), d.y()));
156 if (overlapStart < overlapEnd || (!sharesVertex && overlapStart == overlapEnd))
157 return true;
158 } else {
159 const QPointF& h1 = firstHorizontal ? a : c;
160 const QPointF& h2 = firstHorizontal ? b : d;
161 const QPointF& v1 = firstHorizontal ? c : a;
162 const QPointF& v2 = firstHorizontal ? d : b;
163 if (!sharesVertex && v1.x() >= std::min(h1.x(), h2.x())
164 && v1.x() <= std::max(h1.x(), h2.x())
165 && h1.y() >= std::min(v1.y(), v2.y())
166 && h1.y() <= std::max(v1.y(), v2.y()))
167 return true;
168 }
169 }
170 }
171 return false;
172}
173
175 const std::span<const QPointF> route, const std::span<const QRectF> obstacles)
176{
177 for (std::size_t i = 1; i < route.size(); ++i) {
178 const auto& a = route[i - 1];
179 const auto& b = route[i];
180 for (const auto& obstacle : obstacles) {
181 const QRectF rect = obstacle.normalized();
182 if (a.y() == b.y() && a.y() > rect.top() && a.y() < rect.bottom()
183 && std::max(std::min(a.x(), b.x()), rect.left())
184 < std::min(std::max(a.x(), b.x()), rect.right()))
185 return true;
186 if (a.x() == b.x() && a.x() > rect.left() && a.x() < rect.right()
187 && std::max(std::min(a.y(), b.y()), rect.top())
188 < std::min(std::max(a.y(), b.y()), rect.bottom()))
189 return true;
190 }
191 }
192 return false;
193}
194
195bool pointOnOrthogonalRoute(const QPointF point, const std::span<const QPointF> route)
196{
197 if (route.empty())
198 return false;
199 if (route.size() == 1)
200 return point == route.front();
201
202 auto inRange = [](const qreal value, const qreal first, const qreal second) {
203 const auto [minimum, maximum] = std::minmax(first, second);
204 return value >= minimum && value <= maximum;
205 };
206 for (std::size_t i = 1; i < route.size(); ++i) {
207 const QPointF& first = route[i - 1];
208 const QPointF& second = route[i];
209 if (first.y() == second.y() && point.y() == first.y()
210 && inRange(point.x(), first.x(), second.x()))
211 return true;
212 if (first.x() == second.x() && point.x() == first.x()
213 && inRange(point.y(), first.y(), second.y()))
214 return true;
215 }
216 return false;
217}
218
219bool orthogonalRoutesTouch(const std::span<const QPointF> first,
220 const std::span<const QPointF> second)
221{
222 return (!first.empty()
223 && (pointOnOrthogonalRoute(first.front(), second)
224 || pointOnOrthogonalRoute(first.back(), second)))
225 || (!second.empty()
226 && (pointOnOrthogonalRoute(second.front(), first)
227 || pointOnOrthogonalRoute(second.back(), first)));
228}
229
230bool orthogonalRoutesShareSegment(const std::span<const QPointF> first,
231 const std::span<const QPointF> second)
232{
233 auto segmentsOverlap = [](const QPointF& a, const QPointF& b, const QPointF& c,
234 const QPointF& d) {
235 const bool firstHorizontal = a.y() == b.y();
236 const bool secondHorizontal = c.y() == d.y();
237 if (firstHorizontal != secondHorizontal)
238 return false;
239
240 if (firstHorizontal) {
241 if (a.y() != c.y())
242 return false;
243 const auto firstMin = std::min(a.x(), b.x());
244 const auto firstMax = std::max(a.x(), b.x());
245 const auto secondMin = std::min(c.x(), d.x());
246 const auto secondMax = std::max(c.x(), d.x());
247 return std::max(firstMin, secondMin) < std::min(firstMax, secondMax);
248 }
249
250 if (a.x() != c.x())
251 return false;
252 const auto firstMin = std::min(a.y(), b.y());
253 const auto firstMax = std::max(a.y(), b.y());
254 const auto secondMin = std::min(c.y(), d.y());
255 const auto secondMax = std::max(c.y(), d.y());
256 return std::max(firstMin, secondMin) < std::min(firstMax, secondMax);
257 };
258
259 for (std::size_t i = 1; i < first.size(); ++i) {
260 for (std::size_t j = 1; j < second.size(); ++j) {
261 if (segmentsOverlap(first[i - 1], first[i], second[j - 1], second[j]))
262 return true;
263 }
264 }
265 return false;
266}
267
268bool orthogonalRoutesIntersect(const std::span<const QPointF> first,
269 const std::span<const QPointF> second)
270{
271 auto segmentsCreateJunction = [&](const QPointF& a, const QPointF& b, const QPointF& c,
272 const QPointF& d) {
273 const bool firstHorizontal = a.y() == b.y();
274 const bool secondHorizontal = c.y() == d.y();
275 if (firstHorizontal && secondHorizontal) {
276 return a.y() == c.y()
277 && std::max(std::min(a.x(), b.x()), std::min(c.x(), d.x()))
278 <= std::min(std::max(a.x(), b.x()), std::max(c.x(), d.x()));
279 }
280 if (!firstHorizontal && !secondHorizontal) {
281 return a.x() == c.x()
282 && std::max(std::min(a.y(), b.y()), std::min(c.y(), d.y()))
283 <= std::min(std::max(a.y(), b.y()), std::max(c.y(), d.y()));
284 }
285
286 const QPointF& horizontalStart = firstHorizontal ? a : c;
287 const QPointF& horizontalEnd = firstHorizontal ? b : d;
288 const QPointF& verticalStart = firstHorizontal ? c : a;
289 const QPointF& verticalEnd = firstHorizontal ? d : b;
290 const QPointF intersection(verticalStart.x(), horizontalStart.y());
291 const bool liesOnBoth =
292 intersection.x() >= std::min(horizontalStart.x(), horizontalEnd.x())
293 && intersection.x() <= std::max(horizontalStart.x(), horizontalEnd.x())
294 && intersection.y() >= std::min(verticalStart.y(), verticalEnd.y())
295 && intersection.y() <= std::max(verticalStart.y(), verticalEnd.y());
296 if (!liesOnBoth)
297 return false;
298 return intersection == first.front() || intersection == first.back()
299 || intersection == second.front() || intersection == second.back();
300 };
301
302 for (std::size_t i = 1; i < first.size(); ++i) {
303 for (std::size_t j = 1; j < second.size(); ++j) {
304 if (segmentsCreateJunction(first[i - 1], first[i], second[j - 1], second[j]))
305 return true;
306 }
307 }
308 return false;
309}
310
311std::size_t orthogonalRouteCrossingCount(const std::span<const QPointF> first,
312 const std::span<const QPointF> second)
313{
314 std::size_t crossings = 0;
315 for (std::size_t i = 1; i < first.size(); ++i) {
316 for (std::size_t j = 1; j < second.size(); ++j) {
317 const QPointF& a = first[i - 1];
318 const QPointF& b = first[i];
319 const QPointF& c = second[j - 1];
320 const QPointF& d = second[j];
321 const bool firstHorizontal = a.y() == b.y();
322 const bool secondHorizontal = c.y() == d.y();
323 if (firstHorizontal == secondHorizontal)
324 continue;
325
326 const QPointF& horizontalStart = firstHorizontal ? a : c;
327 const QPointF& horizontalEnd = firstHorizontal ? b : d;
328 const QPointF& verticalStart = firstHorizontal ? c : a;
329 const QPointF& verticalEnd = firstHorizontal ? d : b;
330 if (verticalStart.x() > std::min(horizontalStart.x(), horizontalEnd.x())
331 && verticalStart.x() < std::max(horizontalStart.x(), horizontalEnd.x())
332 && horizontalStart.y() > std::min(verticalStart.y(), verticalEnd.y())
333 && horizontalStart.y() < std::max(verticalStart.y(), verticalEnd.y()))
334 ++crossings;
335 }
336 }
337 return crossings;
338}
339
340std::size_t
342 const std::vector<std::vector<QPointF>>& routes)
343{
344 enum Direction : unsigned int {
345 Left = 1U << 0,
346 Right = 1U << 1,
347 Up = 1U << 2,
348 Down = 1U << 3,
349 };
350
351 unsigned int directions = 0;
352 for (const auto& route : routes) {
353 for (std::size_t i = 1; i < route.size(); ++i) {
354 const QPointF& first = route[i - 1];
355 const QPointF& second = route[i];
356 if (first.y() == second.y() && point.y() == first.y()) {
357 const qreal minimum = std::min(first.x(), second.x());
358 const qreal maximum = std::max(first.x(), second.x());
359 if (point.x() < minimum || point.x() > maximum)
360 continue;
361 if (point.x() > minimum)
362 directions |= Left;
363 if (point.x() < maximum)
364 directions |= Right;
365 } else if (first.x() == second.x() && point.x() == first.x()) {
366 const qreal minimum = std::min(first.y(), second.y());
367 const qreal maximum = std::max(first.y(), second.y());
368 if (point.y() < minimum || point.y() > maximum)
369 continue;
370 if (point.y() > minimum)
371 directions |= Up;
372 if (point.y() < maximum)
373 directions |= Down;
374 }
375 }
376 }
377 return std::popcount(directions);
378}
379
380std::vector<QPointF> canonicalizeOrthogonalRoute(std::vector<QPointF> points)
381{
382 points.erase(std::ranges::unique(points).begin(), points.end());
383 for (std::size_t i = 1; i + 1 < points.size();) {
384 const QPointF& previous = points[i - 1];
385 const QPointF& current = points[i];
386 const QPointF& next = points[i + 1];
387 const bool vertical = previous.x() == current.x() && current.x() == next.x();
388 const bool horizontal = previous.y() == current.y() && current.y() == next.y();
389 const bool between = vertical
390 ? (current.y() - previous.y()) * (current.y() - next.y()) <= 0
391 : (current.x() - previous.x()) * (current.x() - next.x()) <= 0;
392 if ((vertical || horizontal) && between) {
393 points.erase(points.begin() + static_cast<std::ptrdiff_t>(i));
394 continue;
395 }
396 ++i;
397 }
398 return points;
399}
400
401std::vector<std::vector<QPointF>>
402mergeOrthogonalRoutes(const std::vector<std::vector<QPointF>>& routes,
403 const std::function<bool()>& progress)
404{
405 using Point = std::pair<int, int>;
406 using Edge = std::pair<Point, Point>;
407
408 auto pointKey = [](const QPointF& point) {
409 return Point{static_cast<int>(point.x()), static_cast<int>(point.y())};
410 };
411 auto edgeKey = [](Point a, Point b) {
412 if (b < a)
413 std::swap(a, b);
414 return Edge{a, b};
415 };
416 auto pointOnSegment = [](const Point& point, const Edge& segment) {
417 const auto& [a, b] = segment;
418 if (a.first == b.first)
419 return point.first == a.first && point.second >= std::min(a.second, b.second)
420 && point.second <= std::max(a.second, b.second);
421 return point.second == a.second && point.first >= std::min(a.first, b.first)
422 && point.first <= std::max(a.first, b.first);
423 };
424
425 std::vector<Edge> sourceSegments;
426 std::set<Point> terminals;
427 for (const auto& route : routes) {
428 if (progress && !progress())
429 return {};
430 if (route.size() > 1 && route.front() == route.back())
431 throw std::invalid_argument("A wire route must have distinct endpoints");
432 if (route.size() >= 2) {
433 terminals.insert(pointKey(route.front()));
434 terminals.insert(pointKey(route.back()));
435 }
436 for (std::size_t i = 1; i < route.size(); ++i) {
437 const Point a = pointKey(route[i - 1]);
438 const Point b = pointKey(route[i]);
439 if (a != b)
440 sourceSegments.push_back(edgeKey(a, b));
441 }
442 }
443
444 std::set<Edge> edges;
445 for (std::size_t i = 0; i < sourceSegments.size(); ++i) {
446 if (progress && !progress())
447 return {};
448 const Edge& segment = sourceSegments[i];
449 std::set<Point> cuts = {segment.first, segment.second};
450
451 for (std::size_t j = 0; j < sourceSegments.size(); ++j) {
452 if (progress && j % 256 == 0 && !progress())
453 return {};
454 if (i == j)
455 continue;
456 const Edge& other = sourceSegments[j];
457 if (pointOnSegment(other.first, segment))
458 cuts.insert(other.first);
459 if (pointOnSegment(other.second, segment))
460 cuts.insert(other.second);
461
462 const bool vertical = segment.first.first == segment.second.first;
463 const bool otherVertical = other.first.first == other.second.first;
464 if (vertical != otherVertical) {
465 const Point intersection = vertical
466 ? Point{segment.first.first, other.first.second}
467 : Point{other.first.first, segment.first.second};
468 if (pointOnSegment(intersection, segment) && pointOnSegment(intersection, other))
469 cuts.insert(intersection);
470 }
471 }
472
473 std::vector<Point> ordered(cuts.begin(), cuts.end());
474 if (segment.first.first == segment.second.first) {
475 std::ranges::sort(ordered, {}, [](const Point& point) { return point.second; });
476 }
477 for (std::size_t j = 1; j < ordered.size(); ++j)
478 edges.insert(edgeKey(ordered[j - 1], ordered[j]));
479 }
480
481 // Independently routed branches can meet again and form redundant cycles.
482 // Keep a spanning forest before extracting paths, preserving every terminal
483 // and connection without ever constructing a closed path.
484 std::map<Point, Point> parents;
485 for (const auto& [a, b] : edges) {
486 parents.emplace(a, a);
487 parents.emplace(b, b);
488 }
489 auto root = [&parents](Point point) {
490 while (parents.at(point) != point) {
491 parents.at(point) = parents.at(parents.at(point));
492 point = parents.at(point);
493 }
494 return point;
495 };
496 std::erase_if(edges, [&](const Edge& edge) {
497 const Point first = root(edge.first);
498 const Point second = root(edge.second);
499 if (first == second)
500 return true;
501 parents.at(second) = first;
502 return false;
503 });
504
505 std::map<Point, std::set<Point>> adjacency;
506 for (const auto& [a, b] : edges) {
507 adjacency[a].insert(b);
508 adjacency[b].insert(a);
509 }
510
511 // Retraced portions and removed cycle edges can leave dangling geometry.
512 // Retain only branches needed to connect terminals: an artificial leaf
513 // would become an electrical endpoint and could short a crossing net.
514 std::deque<Point> leaves;
515 for (const auto& [point, neighbors] : adjacency)
516 if (neighbors.size() == 1 && !terminals.contains(point))
517 leaves.push_back(point);
518 while (!leaves.empty()) {
519 const Point point = leaves.front();
520 leaves.pop_front();
521 auto& neighbors = adjacency.at(point);
522 if (neighbors.size() != 1)
523 continue;
524 const Point neighbor = *neighbors.begin();
525 neighbors.clear();
526 adjacency.at(neighbor).erase(point);
527 edges.erase(edgeKey(point, neighbor));
528 if (adjacency.at(neighbor).size() == 1 && !terminals.contains(neighbor))
529 leaves.push_back(neighbor);
530 }
531
532 std::set<Edge> visited;
533 std::vector<std::vector<QPointF>> result;
534 auto appendPath = [&](const Point& start, const Point& firstNeighbor) {
535 std::vector<QPointF> path = {QPointF(start.first, start.second)};
536 Point previous = start;
537 Point current = firstNeighbor;
538 visited.insert(edgeKey(previous, current));
539
540 while (true) {
541 path.emplace_back(current.first, current.second);
542 if (adjacency.at(current).size() != 2 || terminals.contains(current))
543 break;
544 const auto& neighbors = adjacency.at(current);
545 const Point next = *std::ranges::find_if(
546 neighbors, [&](const Point& candidate) { return candidate != previous; });
547 const Edge nextEdge = edgeKey(current, next);
548 if (visited.contains(nextEdge))
549 break;
550 previous = current;
551 current = next;
552 visited.insert(nextEdge);
553 }
554 result.push_back(canonicalizeOrthogonalRoute(std::move(path)));
555 };
556
557 for (const auto& [point, neighbors] : adjacency) {
558 if (progress && !progress())
559 return {};
560 if (neighbors.size() == 2 && !terminals.contains(point))
561 continue;
562 for (const Point& neighbor : neighbors) {
563 if (!visited.contains(edgeKey(point, neighbor)))
564 appendPath(point, neighbor);
565 }
566 }
567 if (visited.size() != edges.size())
568 throw std::logic_error("Wire route merging left an unvisited cycle");
569 return result;
570}
571
572std::vector<QPointF> routeOrthogonalWire(const QPointF start, const QPointF end,
573 const std::vector<QRectF>& obstacleRects,
574 const qreal gridSize)
575{
576 if (start == end)
577 return {start};
578
579 Avoid::Router router(Avoid::OrthogonalRouting);
580 configureOrthogonalRouter(router, gridSize);
581
582 QPointF routedStart = start;
583 QPointF routedEnd = end;
584
585 for (const QRectF& obstacleRect : obstacleRects) {
586 const QRectF normalized = obstacleRect.normalized();
587 routedStart = nearestPointOutside(routedStart, normalized);
588 routedEnd = nearestPointOutside(routedEnd, normalized);
589 }
590
591 std::vector<Avoid::Rectangle> obstacles;
592 obstacles.reserve(obstacleRects.size());
593
594 for (const QRectF& obstacleRect : obstacleRects) {
595 const QRectF normalized = obstacleRect.normalized();
596 if (normalized.isEmpty())
597 continue;
598
599 obstacles.push_back(Avoid::rectangleFromQRectF(normalized));
600 }
601
602 std::vector<Avoid::ShapeRef*> shapeRefs;
603 shapeRefs.reserve(obstacles.size());
604 unsigned int nextId = 1;
605
606 for (auto& obstacle : obstacles) {
607 shapeRefs.push_back(new Avoid::ShapeRef(&router, obstacle, nextId++));
608 }
609
610 auto* connector =
611 new Avoid::ConnRef(&router, Avoid::ConnEnd(Avoid::pointFromQPointF(routedStart)),
612 Avoid::ConnEnd(Avoid::pointFromQPointF(routedEnd)), nextId);
613 connector->setRoutingType(Avoid::ConnType_Orthogonal);
614
615 if (!router.processTransaction())
616 return {};
617
618 auto routedPoints = extractOrthogonalRoute(*connector, gridSize);
619
620 if (routedPoints.empty())
621 return {};
622
623 // Snapping a projected terminal can place it back on the actual port. In that
624 // case the port is already reached; adding the projection would double back.
625 if (routedPoints.front() != routedStart && routedPoints.front() != start)
626 routedPoints.insert(routedPoints.begin(), routedStart);
627
628 if (routedPoints.front() != start)
629 routedPoints.insert(routedPoints.begin(), start);
630
631 if (routedPoints.back() != routedEnd && routedPoints.back() != end)
632 routedPoints.push_back(routedEnd);
633
634 if (routedPoints.back() != end)
635 routedPoints.push_back(end);
636
637 return canonicalizeOrthogonalRoute(std::move(routedPoints));
638}
639
640} // namespace SILICON::core
std::vector< QPointF > canonicalizeOrthogonalRoute(std::vector< QPointF > points)
Removes consecutive duplicates and redundant collinear interior points.
bool orthogonalRouteCrossesObstacleInterior(const std::span< const QPointF > route, const std::span< const QRectF > obstacles)
bool orthogonalRoutesTouch(const std::span< const QPointF > first, const std::span< const QPointF > second)
Returns whether an endpoint of either route lies on the other route.
std::size_t orthogonalRouteCrossingCount(const std::span< const QPointF > first, const std::span< const QPointF > second)
Counts strict, perpendicular interior crossings between two routes.
void configureOrthogonalRouter(Avoid::Router &router, const qreal gridSize)
Applies SILICON's shared orthogonal-routing policy to a libavoid router.
std::size_t orthogonalRouteIncidentArmCount(const QPointF point, const std::vector< std::vector< QPointF > > &routes)
Counts the distinct orthogonal arms incident to point.
std::vector< QPointF > extractOrthogonalRoute(Avoid::ConnRef &connector, const qreal gridSize)
Extracts, grid-snaps, and canonicalizes a libavoid display route.
std::vector< QPointF > routeOrthogonalWire(const QPointF start, const QPointF end, const std::vector< QRectF > &obstacleRects, const qreal gridSize)
bool orthogonalRouteSelfIntersects(const std::span< const QPointF > points)
Detects crossings, touches, or retraced portions within one route.
bool orthogonalRoutesIntersect(const std::span< const QPointF > first, const std::span< const QPointF > second)
Returns true when two routes overlap or form an ambiguous endpoint junction.
bool pointOnOrthogonalRoute(const QPointF point, const std::span< const QPointF > route)
Returns whether point lies on an orthogonal polyline.
bool isOrthogonalRoute(const std::span< const QPointF > points)
Returns whether every consecutive route segment is axis-aligned.
bool orthogonalRoutesShareSegment(const std::span< const QPointF > first, const std::span< const QPointF > second)
Returns true when two orthogonal polylines share a positive-length segment.
std::vector< std::vector< QPointF > > mergeOrthogonalRoutes(const std::vector< std::vector< QPointF > > &routes, const std::function< bool()> &progress)
Unions several routes of one net into maximal terminal-to-junction paths.
Json directions(std::initializer_list< std::pair< std::string_view, std::string_view > > values)
Definition helpers.hpp:36