mirror of https://codeberg.org/topola/topola.git
refactor(layout): Poly & Via only use Drawing (instead of Layout), so only pass that
This commit is contained in:
parent
0cbd3c398a
commit
9bb0d34bc8
|
|
@ -343,11 +343,11 @@ impl<R: AccessRules> Layout<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn poly(&self, index: GenericIndex<PolyWeight>) -> Poly<R> {
|
pub fn poly(&self, index: GenericIndex<PolyWeight>) -> Poly<R> {
|
||||||
Poly::new(index, self)
|
Poly::new(index, self.drawing())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn via(&self, index: GenericIndex<ViaWeight>) -> Via<R> {
|
pub fn via(&self, index: GenericIndex<ViaWeight>) -> Via<R> {
|
||||||
Via::new(index, self)
|
Via::new(index, self.drawing())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,11 @@ use crate::{
|
||||||
primitive::GetLimbs,
|
primitive::GetLimbs,
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
seg::SegIndex,
|
seg::SegIndex,
|
||||||
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::GetPos,
|
geometry::GetPos,
|
||||||
graph::{GenericIndex, GetPetgraphIndex},
|
graph::{GenericIndex, GetPetgraphIndex},
|
||||||
layout::{CompoundWeight, Layout},
|
layout::CompoundWeight,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -34,31 +35,28 @@ pub trait GetMaybeApex {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Poly<'a, R> {
|
pub struct Poly<'a, R> {
|
||||||
pub index: GenericIndex<PolyWeight>,
|
pub index: GenericIndex<PolyWeight>,
|
||||||
layout: &'a Layout<R>,
|
drawing: &'a Drawing<CompoundWeight, R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: AccessRules> Poly<'a, R> {
|
impl<'a, R: AccessRules> Poly<'a, R> {
|
||||||
pub fn new(index: GenericIndex<PolyWeight>, layout: &'a Layout<R>) -> Self {
|
pub fn new(index: GenericIndex<PolyWeight>, drawing: &'a Drawing<CompoundWeight, R>) -> Self {
|
||||||
Self { index, layout }
|
Self { index, drawing }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_apex(&self, dot: FixedDotIndex) -> bool {
|
fn is_apex(&self, dot: FixedDotIndex) -> bool {
|
||||||
!self
|
!self
|
||||||
.layout
|
.drawing
|
||||||
.drawing()
|
|
||||||
.primitive(dot)
|
.primitive(dot)
|
||||||
.segs()
|
.segs()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|seg| matches!(seg, SegIndex::Fixed(..)))
|
.any(|seg| matches!(seg, SegIndex::Fixed(..)))
|
||||||
&& self.layout.drawing().primitive(dot).bends().is_empty()
|
&& self.drawing.primitive(dot).bends().is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: AccessRules> GetLayer for Poly<'a, R> {
|
impl<'a, R: AccessRules> GetLayer for Poly<'a, R> {
|
||||||
fn layer(&self) -> usize {
|
fn layer(&self) -> usize {
|
||||||
if let CompoundWeight::Poly(weight) =
|
if let CompoundWeight::Poly(weight) = self.drawing.compound_weight(self.index.into()) {
|
||||||
self.layout.drawing().compound_weight(self.index.into())
|
|
||||||
{
|
|
||||||
weight.layer()
|
weight.layer()
|
||||||
} else {
|
} else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
|
@ -68,10 +66,7 @@ impl<'a, R: AccessRules> GetLayer for Poly<'a, R> {
|
||||||
|
|
||||||
impl<'a, R: AccessRules> GetMaybeNet for Poly<'a, R> {
|
impl<'a, R: AccessRules> GetMaybeNet for Poly<'a, R> {
|
||||||
fn maybe_net(&self) -> Option<usize> {
|
fn maybe_net(&self) -> Option<usize> {
|
||||||
self.layout
|
self.drawing.compound_weight(self.index.into()).maybe_net()
|
||||||
.drawing()
|
|
||||||
.compound_weight(self.index.into())
|
|
||||||
.maybe_net()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,8 +74,7 @@ impl<'a, R: AccessRules> MakePolygon for Poly<'a, R> {
|
||||||
fn shape(&self) -> Polygon {
|
fn shape(&self) -> Polygon {
|
||||||
Polygon::new(
|
Polygon::new(
|
||||||
LineString::from(
|
LineString::from(
|
||||||
self.layout
|
self.drawing
|
||||||
.drawing()
|
|
||||||
.geometry()
|
.geometry()
|
||||||
.compound_members(self.index.into())
|
.compound_members(self.index.into())
|
||||||
.filter_map(|primitive_node| {
|
.filter_map(|primitive_node| {
|
||||||
|
|
@ -91,13 +85,7 @@ impl<'a, R: AccessRules> MakePolygon for Poly<'a, R> {
|
||||||
if self.is_apex(dot) {
|
if self.is_apex(dot) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(
|
Some(self.drawing.geometry().dot_weight(dot.into()).pos())
|
||||||
self.layout
|
|
||||||
.drawing()
|
|
||||||
.geometry()
|
|
||||||
.dot_weight(dot.into())
|
|
||||||
.pos(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<Point>>(),
|
.collect::<Vec<Point>>(),
|
||||||
|
|
@ -109,8 +97,7 @@ impl<'a, R: AccessRules> MakePolygon for Poly<'a, R> {
|
||||||
|
|
||||||
impl<'a, R: AccessRules> GetMaybeApex for Poly<'a, R> {
|
impl<'a, R: AccessRules> GetMaybeApex for Poly<'a, R> {
|
||||||
fn maybe_apex(&self) -> Option<FixedDotIndex> {
|
fn maybe_apex(&self) -> Option<FixedDotIndex> {
|
||||||
self.layout
|
self.drawing
|
||||||
.drawing()
|
|
||||||
.geometry()
|
.geometry()
|
||||||
.compound_members(self.index.into())
|
.compound_members(self.index.into())
|
||||||
.find_map(|primitive_node| {
|
.find_map(|primitive_node| {
|
||||||
|
|
|
||||||
|
|
@ -11,39 +11,35 @@ use crate::{
|
||||||
graph::{GetMaybeNet, IsInLayer},
|
graph::{GetMaybeNet, IsInLayer},
|
||||||
primitive::MakePrimitiveShape,
|
primitive::MakePrimitiveShape,
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::primitive::{DotShape, PrimitiveShape},
|
geometry::primitive::{DotShape, PrimitiveShape},
|
||||||
graph::{GenericIndex, GetPetgraphIndex},
|
graph::{GenericIndex, GetPetgraphIndex},
|
||||||
layout::{CompoundWeight, Layout},
|
layout::CompoundWeight,
|
||||||
math::Circle,
|
math::Circle,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Via<'a, R> {
|
pub struct Via<'a, R> {
|
||||||
pub index: GenericIndex<ViaWeight>,
|
pub index: GenericIndex<ViaWeight>,
|
||||||
layout: &'a Layout<R>,
|
drawing: &'a Drawing<CompoundWeight, R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R> Via<'a, R> {
|
impl<'a, R> Via<'a, R> {
|
||||||
pub fn new(index: GenericIndex<ViaWeight>, layout: &'a Layout<R>) -> Self {
|
pub fn new(index: GenericIndex<ViaWeight>, drawing: &'a Drawing<CompoundWeight, R>) -> Self {
|
||||||
Self { index, layout }
|
Self { index, drawing }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: AccessRules> GetMaybeNet for Via<'a, R> {
|
impl<'a, R: AccessRules> GetMaybeNet for Via<'a, R> {
|
||||||
fn maybe_net(&self) -> Option<usize> {
|
fn maybe_net(&self) -> Option<usize> {
|
||||||
self.layout
|
self.drawing.compound_weight(self.index.into()).maybe_net()
|
||||||
.drawing()
|
|
||||||
.compound_weight(self.index.into())
|
|
||||||
.maybe_net()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: AccessRules> MakePrimitiveShape for Via<'a, R> {
|
impl<'a, R: AccessRules> MakePrimitiveShape for Via<'a, R> {
|
||||||
fn shape(&self) -> PrimitiveShape {
|
fn shape(&self) -> PrimitiveShape {
|
||||||
if let CompoundWeight::Via(weight) =
|
if let CompoundWeight::Via(weight) = self.drawing.compound_weight(self.index.into()) {
|
||||||
self.layout.drawing().compound_weight(self.index.into())
|
|
||||||
{
|
|
||||||
weight.shape()
|
weight.shape()
|
||||||
} else {
|
} else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue