mirror of https://codeberg.org/topola/topola.git
refactor(drawing::collect): turn Collect into a trait
This commit is contained in:
parent
90544c12ed
commit
bcb0c4ad5c
|
|
@ -11,7 +11,7 @@ use petgraph::graph::EdgeIndex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
board::mesadata::AccessMesadata,
|
board::mesadata::AccessMesadata,
|
||||||
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex},
|
drawing::{band::BandTermsegIndex, collect::Collect, graph::PrimitiveIndex},
|
||||||
geometry::primitive::PrimitiveShape,
|
geometry::primitive::PrimitiveShape,
|
||||||
layout::LayoutEdit,
|
layout::LayoutEdit,
|
||||||
router::{navcord::NavcordStepper, navmesh::Navmesh, route::RouteStepper, Router},
|
router::{navcord::NavcordStepper, navmesh::Navmesh, route::RouteStepper, Router},
|
||||||
|
|
@ -118,7 +118,6 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<LayoutEdit>, AutorouteContinu
|
||||||
.board
|
.board
|
||||||
.layout()
|
.layout()
|
||||||
.drawing()
|
.drawing()
|
||||||
.collect()
|
|
||||||
.loose_band_uid(band_termseg.into());
|
.loose_band_uid(band_termseg.into());
|
||||||
|
|
||||||
autorouter
|
autorouter
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,10 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
board::{mesadata::AccessMesadata, BandName, Board, ResolvedSelector},
|
board::{mesadata::AccessMesadata, BandName, Board, ResolvedSelector},
|
||||||
drawing::graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
drawing::{
|
||||||
|
collect::Collect,
|
||||||
|
graph::{GetLayer, MakePrimitive, PrimitiveIndex},
|
||||||
|
},
|
||||||
geometry::{
|
geometry::{
|
||||||
shape::{AccessShape, Shape},
|
shape::{AccessShape, Shape},
|
||||||
GenericNode,
|
GenericNode,
|
||||||
|
|
@ -123,10 +126,7 @@ impl BandSelector {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::try_from_uid(
|
Self::try_from_uid(board, &board.layout().drawing().loose_band_uid(loose))
|
||||||
board,
|
|
||||||
&board.layout().drawing().collect().loose_band_uid(loose),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn try_from_uid(
|
pub fn try_from_uid(
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ use crate::{
|
||||||
drawing::{
|
drawing::{
|
||||||
band::BandUid,
|
band::BandUid,
|
||||||
bend::{BendIndex, BendWeight},
|
bend::{BendIndex, BendWeight},
|
||||||
|
collect::Collect,
|
||||||
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight},
|
dot::{DotIndex, DotWeight, FixedDotIndex, FixedDotWeight},
|
||||||
graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight},
|
graph::{GetLayer, GetMaybeNet, PrimitiveIndex, PrimitiveWeight},
|
||||||
seg::{FixedSegIndex, FixedSegWeight, SegIndex, SegWeight},
|
seg::{FixedSegIndex, FixedSegWeight, SegIndex, SegWeight},
|
||||||
|
|
@ -90,7 +91,7 @@ impl<'a> ResolvedSelector<'a> {
|
||||||
Some(ResolvedSelector::Pin { pin_name, layer })
|
Some(ResolvedSelector::Pin { pin_name, layer })
|
||||||
} else if let Some(loose) = loose {
|
} else if let Some(loose) = loose {
|
||||||
Some(ResolvedSelector::Band {
|
Some(ResolvedSelector::Band {
|
||||||
band_uid: board.layout().drawing().collect().loose_band_uid(loose),
|
band_uid: board.layout().drawing().loose_band_uid(loose),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::{AccessBendWeight, GetOffset, GetWidth, SetOffset},
|
geometry::{GetOffset, GetWidth, SetOffset},
|
||||||
graph::{GenericIndex, GetPetgraphIndex},
|
graph::{GenericIndex, GetPetgraphIndex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,25 +15,84 @@ use super::{
|
||||||
Drawing,
|
Drawing,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
pub trait Collect {
|
||||||
pub struct Collect<'a, CW, R> {
|
fn loose_band_uid(&self, start_loose: LooseIndex) -> BandUid;
|
||||||
drawing: &'a Drawing<CW, R>,
|
|
||||||
|
fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex>;
|
||||||
|
|
||||||
|
fn bend_outer_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex>;
|
||||||
|
|
||||||
|
fn wraparounded_bows(&self, around: GearIndex) -> Vec<PrimitiveIndex>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, CW, R> Collect<'a, CW, R> {
|
impl<CW: Copy, R: AccessRules> Collect for Drawing<CW, R> {
|
||||||
pub fn new(drawing: &'a Drawing<CW, R>) -> Self {
|
fn loose_band_uid(&self, start_loose: LooseIndex) -> BandUid {
|
||||||
Self { drawing }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
|
||||||
pub fn loose_band_uid(&self, start_loose: LooseIndex) -> BandUid {
|
|
||||||
BandUid::new(
|
BandUid::new(
|
||||||
self.loose_band_first_seg(start_loose),
|
self.loose_band_first_seg(start_loose),
|
||||||
self.loose_band_last_seg(start_loose),
|
self.loose_band_last_seg(start_loose),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
|
let mut v: Vec<PrimitiveIndex> = vec![];
|
||||||
|
v.push(bend.into());
|
||||||
|
|
||||||
|
let joints = self.primitive(bend).joints();
|
||||||
|
v.push(joints.0.into());
|
||||||
|
v.push(joints.1.into());
|
||||||
|
|
||||||
|
if let Some(seg0) = self.primitive(joints.0).seg() {
|
||||||
|
v.push(seg0.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(seg1) = self.primitive(joints.1).seg() {
|
||||||
|
v.push(seg1.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bend_outer_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
||||||
|
let mut v = vec![];
|
||||||
|
let mut gear = bend;
|
||||||
|
|
||||||
|
while let Some(outer) = self.primitive(gear).outer() {
|
||||||
|
v.append(&mut self.bend_bow(outer));
|
||||||
|
gear = outer;
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wraparounded_bows(&self, around: GearIndex) -> Vec<PrimitiveIndex> {
|
||||||
|
let mut v = vec![];
|
||||||
|
let mut gear = around;
|
||||||
|
|
||||||
|
while let Some(bend) = gear.ref_(self).next_gear() {
|
||||||
|
let primitive = self.primitive(bend);
|
||||||
|
|
||||||
|
v.push(bend.into());
|
||||||
|
|
||||||
|
let joints = primitive.joints();
|
||||||
|
v.push(joints.0.into());
|
||||||
|
v.push(joints.1.into());
|
||||||
|
|
||||||
|
v.push(self.primitive(joints.0).seg().unwrap().into());
|
||||||
|
v.push(self.primitive(joints.1).seg().unwrap().into());
|
||||||
|
|
||||||
|
gear = bend.into();
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait CollectPrivate {
|
||||||
|
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> BandTermsegIndex;
|
||||||
|
fn loose_band_last_seg(&self, start_loose: LooseIndex) -> BandTermsegIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<CW: Copy, R: AccessRules> CollectPrivate for Drawing<CW, R> {
|
||||||
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> BandTermsegIndex {
|
fn loose_band_first_seg(&self, start_loose: LooseIndex) -> BandTermsegIndex {
|
||||||
if let LooseIndex::LoneSeg(seg) = start_loose {
|
if let LooseIndex::LoneSeg(seg) = start_loose {
|
||||||
return BandTermsegIndex::Straight(seg);
|
return BandTermsegIndex::Straight(seg);
|
||||||
|
|
@ -43,7 +102,7 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
||||||
let mut prev = None;
|
let mut prev = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(next_loose) = self.drawing.loose(loose).prev_loose(prev) {
|
if let Some(next_loose) = self.loose(loose).prev_loose(prev) {
|
||||||
prev = Some(loose);
|
prev = Some(loose);
|
||||||
loose = next_loose;
|
loose = next_loose;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -61,7 +120,7 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
||||||
let mut next = None;
|
let mut next = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(prev_loose) = self.drawing.loose(loose).next_loose(next) {
|
if let Some(prev_loose) = self.loose(loose).next_loose(next) {
|
||||||
next = Some(loose);
|
next = Some(loose);
|
||||||
loose = prev_loose;
|
loose = prev_loose;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -69,57 +128,4 @@ impl<'a, CW: Copy, R: AccessRules> Collect<'a, CW, R> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bend_bow(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
|
||||||
let mut v: Vec<PrimitiveIndex> = vec![];
|
|
||||||
v.push(bend.into());
|
|
||||||
|
|
||||||
let joints = self.drawing.primitive(bend).joints();
|
|
||||||
v.push(joints.0.into());
|
|
||||||
v.push(joints.1.into());
|
|
||||||
|
|
||||||
if let Some(seg0) = self.drawing.primitive(joints.0).seg() {
|
|
||||||
v.push(seg0.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(seg1) = self.drawing.primitive(joints.1).seg() {
|
|
||||||
v.push(seg1.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bend_outer_bows(&self, bend: LooseBendIndex) -> Vec<PrimitiveIndex> {
|
|
||||||
let mut v = vec![];
|
|
||||||
let mut gear = bend;
|
|
||||||
|
|
||||||
while let Some(outer) = self.drawing.primitive(gear).outer() {
|
|
||||||
v.append(&mut self.bend_bow(outer));
|
|
||||||
gear = outer;
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn wraparounded_bows(&self, around: GearIndex) -> Vec<PrimitiveIndex> {
|
|
||||||
let mut v = vec![];
|
|
||||||
let mut gear = around;
|
|
||||||
|
|
||||||
while let Some(bend) = gear.ref_(self.drawing).next_gear() {
|
|
||||||
let primitive = self.drawing.primitive(bend);
|
|
||||||
|
|
||||||
v.push(bend.into());
|
|
||||||
|
|
||||||
let joints = primitive.joints();
|
|
||||||
v.push(joints.0.into());
|
|
||||||
v.push(joints.1.into());
|
|
||||||
|
|
||||||
v.push(self.drawing.primitive(joints.0).seg().unwrap().into());
|
|
||||||
v.push(self.drawing.primitive(joints.1).seg().unwrap().into());
|
|
||||||
|
|
||||||
gear = bend.into();
|
|
||||||
}
|
|
||||||
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -571,20 +571,20 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
||||||
recorder,
|
recorder,
|
||||||
joints.0.into(),
|
joints.0.into(),
|
||||||
from,
|
from,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
self.move_dot_with_infringables(
|
self.move_dot_with_infringables(
|
||||||
recorder,
|
recorder,
|
||||||
joints.1.into(),
|
joints.1.into(),
|
||||||
to,
|
to,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.shift_bend_with_infringables(
|
self.shift_bend_with_infringables(
|
||||||
recorder,
|
recorder,
|
||||||
rail.into(),
|
rail.into(),
|
||||||
offset,
|
offset,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Update offsets in case the rule conditions changed.
|
// Update offsets in case the rule conditions changed.
|
||||||
|
|
@ -616,20 +616,20 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
||||||
recorder,
|
recorder,
|
||||||
joints.0.into(),
|
joints.0.into(),
|
||||||
from,
|
from,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
self.move_dot_with_infringables(
|
self.move_dot_with_infringables(
|
||||||
recorder,
|
recorder,
|
||||||
joints.1.into(),
|
joints.1.into(),
|
||||||
to,
|
to,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
self.shift_bend_with_infringables(
|
self.shift_bend_with_infringables(
|
||||||
recorder,
|
recorder,
|
||||||
rail.into(),
|
rail.into(),
|
||||||
offset,
|
offset,
|
||||||
Some(&self.collect().bend_outer_bows(rail)),
|
Some(&self.bend_outer_bows(rail)),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1109,10 +1109,6 @@ impl<CW: Copy, R: AccessRules> Drawing<CW, R> {
|
||||||
Guide::new(self)
|
Guide::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect(&self) -> Collect<CW, R> {
|
|
||||||
Collect::new(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W, CW, R> {
|
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W, CW, R> {
|
||||||
GenericPrimitive::new(index, self)
|
GenericPrimitive::new(index, self)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
rules::AccessRules,
|
rules::AccessRules,
|
||||||
Drawing,
|
Drawing,
|
||||||
},
|
},
|
||||||
geometry::{AccessSegWeight, GetWidth},
|
geometry::GetWidth,
|
||||||
graph::{GenericIndex, GetPetgraphIndex},
|
graph::{GenericIndex, GetPetgraphIndex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue