mirror of https://codeberg.org/topola/topola.git
overlay: make ratlines between centers of pads instead of teir dots
This commit is contained in:
parent
68df579308
commit
5ce35a5357
|
|
@ -10,7 +10,10 @@ use crate::{
|
||||||
rules::GetConditions,
|
rules::GetConditions,
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
geometry::{
|
||||||
|
primitive::{PrimitiveShape, PrimitiveShapeTrait},
|
||||||
|
shape::ShapeTrait,
|
||||||
|
},
|
||||||
math::{self, Circle, NoTangents},
|
math::{self, Circle, NoTangents},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
use geo::{Contains, Point, Polygon};
|
use geo::{Centroid, Contains, Point, Polygon};
|
||||||
|
|
||||||
use crate::geometry::shape::ShapeTrait;
|
use crate::geometry::shape::ShapeTrait;
|
||||||
|
|
||||||
|
|
@ -9,6 +9,10 @@ pub struct PolyShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeTrait for PolyShape {
|
impl ShapeTrait for PolyShape {
|
||||||
|
fn center(&self) -> Point {
|
||||||
|
self.polygon.centroid().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn contains_point(&self, p: Point) -> bool {
|
fn contains_point(&self, p: Point) -> bool {
|
||||||
self.polygon.contains(&p)
|
self.polygon.contains(&p)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,9 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait PrimitiveShapeTrait {
|
pub trait PrimitiveShapeTrait: ShapeTrait {
|
||||||
fn priority(&self) -> u64;
|
fn priority(&self) -> u64;
|
||||||
fn inflate(&self, margin: f64) -> PrimitiveShape;
|
fn inflate(&self, margin: f64) -> PrimitiveShape;
|
||||||
fn center(&self) -> Point;
|
|
||||||
fn intersects(&self, other: &PrimitiveShape) -> bool;
|
fn intersects(&self, other: &PrimitiveShape) -> bool;
|
||||||
fn envelope(&self, margin: f64) -> AABB<[f64; 2]>;
|
fn envelope(&self, margin: f64) -> AABB<[f64; 2]>;
|
||||||
fn width(&self) -> f64;
|
fn width(&self) -> f64;
|
||||||
|
|
@ -53,6 +52,10 @@ pub struct DotShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeTrait for DotShape {
|
impl ShapeTrait for DotShape {
|
||||||
|
fn center(&self) -> Point {
|
||||||
|
self.c.pos
|
||||||
|
}
|
||||||
|
|
||||||
fn contains_point(&self, p: Point) -> bool {
|
fn contains_point(&self, p: Point) -> bool {
|
||||||
p.euclidean_distance(&self.c.pos) <= self.c.r
|
p.euclidean_distance(&self.c.pos) <= self.c.r
|
||||||
}
|
}
|
||||||
|
|
@ -72,10 +75,6 @@ impl PrimitiveShapeTrait for DotShape {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn center(&self) -> Point {
|
|
||||||
self.c.pos
|
|
||||||
}
|
|
||||||
|
|
||||||
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
||||||
if self.priority() < other.priority() {
|
if self.priority() < other.priority() {
|
||||||
return other.intersects(&PrimitiveShape::from(*self));
|
return other.intersects(&PrimitiveShape::from(*self));
|
||||||
|
|
@ -153,6 +152,10 @@ impl SegShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeTrait for SegShape {
|
impl ShapeTrait for SegShape {
|
||||||
|
fn center(&self) -> Point {
|
||||||
|
(self.from + self.to) / 2.0
|
||||||
|
}
|
||||||
|
|
||||||
fn contains_point(&self, p: Point) -> bool {
|
fn contains_point(&self, p: Point) -> bool {
|
||||||
self.polygon().contains(&p)
|
self.polygon().contains(&p)
|
||||||
}
|
}
|
||||||
|
|
@ -171,10 +174,6 @@ impl PrimitiveShapeTrait for SegShape {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn center(&self) -> Point {
|
|
||||||
(self.from + self.to) / 2.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
||||||
if self.priority() < other.priority() {
|
if self.priority() < other.priority() {
|
||||||
return other.intersects(&PrimitiveShape::from(*self));
|
return other.intersects(&PrimitiveShape::from(*self));
|
||||||
|
|
@ -268,6 +267,11 @@ impl BendShape {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeTrait for BendShape {
|
impl ShapeTrait for BendShape {
|
||||||
|
fn center(&self) -> Point {
|
||||||
|
let sum = (self.from - self.c.pos) + (self.to - self.c.pos);
|
||||||
|
self.c.pos + (sum / sum.euclidean_distance(&point! {x: 0.0, y: 0.0})) * self.c.r
|
||||||
|
}
|
||||||
|
|
||||||
fn contains_point(&self, p: Point) -> bool {
|
fn contains_point(&self, p: Point) -> bool {
|
||||||
let d = p.euclidean_distance(&self.c.pos);
|
let d = p.euclidean_distance(&self.c.pos);
|
||||||
self.between_ends(p) && d >= self.inner_circle().r && d <= self.outer_circle().r
|
self.between_ends(p) && d >= self.inner_circle().r && d <= self.outer_circle().r
|
||||||
|
|
@ -291,11 +295,6 @@ impl PrimitiveShapeTrait for BendShape {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn center(&self) -> Point {
|
|
||||||
let sum = (self.from - self.c.pos) + (self.to - self.c.pos);
|
|
||||||
self.c.pos + (sum / sum.euclidean_distance(&point! {x: 0.0, y: 0.0})) * self.c.r
|
|
||||||
}
|
|
||||||
|
|
||||||
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
fn intersects(&self, other: &PrimitiveShape) -> bool {
|
||||||
if self.priority() < other.priority() {
|
if self.priority() < other.priority() {
|
||||||
return other.intersects(&PrimitiveShape::from(*self));
|
return other.intersects(&PrimitiveShape::from(*self));
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use crate::geometry::{
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
pub trait ShapeTrait {
|
pub trait ShapeTrait {
|
||||||
|
fn center(&self) -> Point;
|
||||||
fn contains_point(&self, p: Point) -> bool;
|
fn contains_point(&self, p: Point) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
|
use enum_dispatch::enum_dispatch;
|
||||||
use geo::Point;
|
use geo::Point;
|
||||||
use petgraph::{
|
use petgraph::{
|
||||||
data::FromElements,
|
data::FromElements,
|
||||||
stable_graph::StableUnGraph,
|
stable_graph::{NodeIndex, StableUnGraph},
|
||||||
visit::{self, EdgeRef, NodeIndexable},
|
visit::{self, EdgeRef, NodeIndexable},
|
||||||
};
|
};
|
||||||
use spade::{HasPosition, InsertionError, Point2};
|
use spade::{HasPosition, InsertionError, Point2};
|
||||||
|
|
@ -13,19 +14,30 @@ use crate::{
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
},
|
},
|
||||||
geometry::primitive::PrimitiveShapeTrait,
|
geometry::{compound::CompoundManagerTrait, shape::ShapeTrait},
|
||||||
layout::Layout,
|
graph::{GenericIndex, GetNodeIndex},
|
||||||
|
layout::{
|
||||||
|
zone::{MakePolyShape, ZoneWeight},
|
||||||
|
Layout,
|
||||||
|
},
|
||||||
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeWeight},
|
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeWeight},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[enum_dispatch(GetNodeIndex)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub enum RatsnestVertexIndex {
|
||||||
|
FixedDot(FixedDotIndex),
|
||||||
|
Zone(GenericIndex<ZoneWeight>),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct VertexWeight {
|
pub struct VertexWeight {
|
||||||
vertex: FixedDotIndex,
|
vertex: RatsnestVertexIndex,
|
||||||
pub pos: Point,
|
pub pos: Point,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GetVertexIndex<FixedDotIndex> for VertexWeight {
|
impl GetVertexIndex<RatsnestVertexIndex> for VertexWeight {
|
||||||
fn vertex_index(&self) -> FixedDotIndex {
|
fn vertex_index(&self) -> RatsnestVertexIndex {
|
||||||
self.vertex
|
self.vertex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,19 +63,29 @@ impl Ratsnest {
|
||||||
Triangulation::new(layout.drawing().geometry().graph().node_bound());
|
Triangulation::new(layout.drawing().geometry().graph().node_bound());
|
||||||
|
|
||||||
for node in layout.drawing().primitive_nodes() {
|
for node in layout.drawing().primitive_nodes() {
|
||||||
let center = node.primitive(layout.drawing()).shape().center();
|
|
||||||
|
|
||||||
match node {
|
match node {
|
||||||
PrimitiveIndex::FixedDot(dot) => {
|
PrimitiveIndex::FixedDot(dot) => {
|
||||||
triangulation.add_vertex(VertexWeight {
|
if layout.compounds(dot).next().is_none() {
|
||||||
vertex: dot,
|
triangulation.add_vertex(VertexWeight {
|
||||||
pos: center,
|
vertex: RatsnestVertexIndex::FixedDot(dot),
|
||||||
})?;
|
pos: node.primitive(layout.drawing()).shape().center(),
|
||||||
|
})?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for zone in layout.zones() {
|
||||||
|
triangulation.add_vertex(VertexWeight {
|
||||||
|
vertex: RatsnestVertexIndex::Zone(zone),
|
||||||
|
pos: layout
|
||||||
|
.compound_weight(zone)
|
||||||
|
.shape(&layout.drawing(), zone)
|
||||||
|
.center(),
|
||||||
|
})?
|
||||||
|
}
|
||||||
|
|
||||||
this.graph =
|
this.graph =
|
||||||
StableUnGraph::from_elements(petgraph::algo::min_spanning_tree(&triangulation));
|
StableUnGraph::from_elements(petgraph::algo::min_spanning_tree(&triangulation));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use petgraph::visit::{self, NodeIndexable};
|
||||||
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
use petgraph::{stable_graph::NodeIndex, visit::EdgeRef};
|
||||||
use spade::{HasPosition, InsertionError, Point2};
|
use spade::{HasPosition, InsertionError, Point2};
|
||||||
|
|
||||||
|
use crate::geometry::shape::ShapeTrait;
|
||||||
use crate::{
|
use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
bend::{FixedBendIndex, LooseBendIndex},
|
bend::{FixedBendIndex, LooseBendIndex},
|
||||||
|
|
@ -16,7 +17,6 @@ use crate::{
|
||||||
rules::RulesTrait,
|
rules::RulesTrait,
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::primitive::PrimitiveShapeTrait,
|
|
||||||
graph::GetNodeIndex,
|
graph::GetNodeIndex,
|
||||||
layout::Layout,
|
layout::Layout,
|
||||||
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
|
triangulation::{GetVertexIndex, Triangulation, TriangulationEdgeReference},
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,18 @@ use petgraph::visit::EdgeRef;
|
||||||
use spade::InsertionError;
|
use spade::InsertionError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::drawing::{
|
|
||||||
dot::FixedDotIndex,
|
|
||||||
graph::{MakePrimitive, PrimitiveIndex},
|
|
||||||
primitive::MakePrimitiveShape,
|
|
||||||
rules::RulesTrait,
|
|
||||||
};
|
|
||||||
use crate::geometry::primitive::PrimitiveShapeTrait;
|
use crate::geometry::primitive::PrimitiveShapeTrait;
|
||||||
use crate::layout::connectivity::BandIndex;
|
use crate::layout::connectivity::BandIndex;
|
||||||
use crate::layout::Layout;
|
use crate::layout::Layout;
|
||||||
|
use crate::{
|
||||||
|
drawing::{
|
||||||
|
dot::FixedDotIndex,
|
||||||
|
graph::{MakePrimitive, PrimitiveIndex},
|
||||||
|
primitive::MakePrimitiveShape,
|
||||||
|
rules::RulesTrait,
|
||||||
|
},
|
||||||
|
geometry::shape::ShapeTrait,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::router::{
|
use crate::router::{
|
||||||
astar::{astar, AstarStrategy, PathTracker},
|
astar::{astar, AstarStrategy, PathTracker},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue