general refactor: omit unnecessary clones

This commit is contained in:
Alain Emilia Anna Zscheile 2024-10-05 00:34:21 +02:00
parent efca1178f8
commit 224dd0c3bd
5 changed files with 24 additions and 57 deletions

View File

@ -110,7 +110,7 @@ impl<M: AccessMesadata> Autorouter<M> {
&self, &self,
selection: &BandSelection, selection: &BandSelection,
) -> Result<RemoveBandsExecutionStepper, AutorouterError> { ) -> Result<RemoveBandsExecutionStepper, AutorouterError> {
RemoveBandsExecutionStepper::new(selection) RemoveBandsExecutionStepper::new(selection.clone())
} }
pub fn undo_remove_bands(&mut self, _selection: &BandSelection) { pub fn undo_remove_bands(&mut self, _selection: &BandSelection) {

View File

@ -22,11 +22,7 @@ impl<M: AccessMesadata> EvalImmut<Autorouter<M>, f64> for MeasureLength {
let mut length = 0.0; let mut length = 0.0;
for selector in self.0.selectors() { for selector in self.0.selectors() {
let band = autorouter let band = autorouter.board.bandname_band(&selector.band).unwrap().0;
.board
.bandname_band(selector.band.clone())
.unwrap()
.0;
length += band.ref_(autorouter.board.layout().drawing()).length(); length += band.ref_(autorouter.board.layout().drawing()).length();
} }

View File

@ -3,12 +3,7 @@
//! to remove selected bands, and implements necessary traits for working //! to remove selected bands, and implements necessary traits for working
//! with navigation meshes, traces, and obstacles. //! with navigation meshes, traces, and obstacles.
use crate::{ use crate::board::mesadata::AccessMesadata;
board::mesadata::AccessMesadata,
drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape,
router::{navmesh::Navmesh, trace::TraceStepper},
};
use super::{ use super::{
invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles}, invoker::{GetGhosts, GetMaybeNavmesh, GetMaybeTrace, GetObstacles},
@ -23,7 +18,7 @@ pub struct RemoveBandsExecutionStepper {
} }
impl RemoveBandsExecutionStepper { impl RemoveBandsExecutionStepper {
pub fn new(selection: &BandSelection) -> Result<Self, AutorouterError> { pub fn new(selection: BandSelection) -> Result<Self, AutorouterError> {
Ok(Self { Ok(Self {
selection: selection.clone(), selection: selection.clone(),
done: false, done: false,
@ -38,40 +33,18 @@ impl RemoveBandsExecutionStepper {
self.done = true; self.done = true;
for selector in self.selection.selectors() { for selector in self.selection.selectors() {
let band = autorouter let band = autorouter.board.bandname_band(&selector.band).unwrap().0;
.board
.bandname_band(selector.band.clone())
.unwrap()
.0;
autorouter.board.layout_mut().remove_band(band); autorouter.board.layout_mut().remove_band(band);
} }
Ok(())
} else {
Ok(())
} }
Ok(())
} }
} }
impl GetMaybeNavmesh for RemoveBandsExecutionStepper { impl GetMaybeNavmesh for RemoveBandsExecutionStepper {}
fn maybe_navmesh(&self) -> Option<&Navmesh> {
None
}
}
impl GetMaybeTrace for RemoveBandsExecutionStepper { impl GetMaybeTrace for RemoveBandsExecutionStepper {}
fn maybe_trace(&self) -> Option<&TraceStepper> {
None
}
}
impl GetGhosts for RemoveBandsExecutionStepper { impl GetGhosts for RemoveBandsExecutionStepper {}
fn ghosts(&self) -> &[PrimitiveShape] {
&[]
}
}
impl GetObstacles for RemoveBandsExecutionStepper { impl GetObstacles for RemoveBandsExecutionStepper {}
fn obstacles(&self) -> &[PrimitiveIndex] {
&[]
}
}

View File

@ -63,7 +63,7 @@ impl PinSelection {
}; };
if let (Some(pinname), Some(layername)) = ( if let (Some(pinname), Some(layername)) = (
board.node_pinname(node), board.node_pinname(&node),
board.layout().rules().layer_layername(layer), board.layout().rules().layer_layername(layer),
) { ) {
Some(PinSelector { Some(PinSelector {
@ -125,11 +125,9 @@ impl BandSelection {
_ => return None, _ => return None,
}; };
Some(BandSelector { board
band: board .band_bandname(&board.layout().drawing().collect().loose_band_uid(loose))
.band_bandname(board.layout().drawing().collect().loose_band_uid(loose))? .map(|band| BandSelector { band: band.clone() })
.clone(),
})
} }
fn select(&mut self, selector: BandSelector) { fn select(&mut self, selector: BandSelector) {

View File

@ -86,7 +86,7 @@ impl<M: AccessMesadata> Board<M> {
) -> FixedDotIndex { ) -> FixedDotIndex {
let dot = self.layout.add_poly_fixed_dot_infringably(weight, poly); let dot = self.layout.add_poly_fixed_dot_infringably(weight, poly);
if let Some(pin) = self.node_pinname(GenericNode::Compound(poly.into())) { if let Some(pin) = self.node_pinname(&GenericNode::Compound(poly.into())) {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(dot.into()), pin.to_string()); .insert(GenericNode::Primitive(dot.into()), pin.to_string());
} }
@ -128,7 +128,7 @@ impl<M: AccessMesadata> Board<M> {
.layout .layout
.add_poly_fixed_seg_infringably(from, to, weight, poly); .add_poly_fixed_seg_infringably(from, to, weight, poly);
if let Some(pin) = self.node_pinname(GenericNode::Compound(poly.into())) { if let Some(pin) = self.node_pinname(&GenericNode::Compound(poly.into())) {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(seg.into()), pin.to_string()); .insert(GenericNode::Primitive(seg.into()), pin.to_string());
} }
@ -176,18 +176,18 @@ impl<M: AccessMesadata> Board<M> {
} }
/// Returns the pin name associated with a given node. /// Returns the pin name associated with a given node.
pub fn node_pinname(&self, node: NodeIndex) -> Option<&String> { pub fn node_pinname(&self, node: &NodeIndex) -> Option<&String> {
self.node_to_pinname.get(&node) self.node_to_pinname.get(node)
} }
/// Returns the band name associated with a given band. /// Returns the band name associated with a given band.
pub fn band_bandname(&self, band: BandUid) -> Option<&BandName> { pub fn band_bandname(&self, band: &BandUid) -> Option<&BandName> {
self.band_bandname.get_by_left(&band) self.band_bandname.get_by_left(band)
} }
/// Returns the unique id associated with a given band name. /// Returns the unique id associated with a given band name.
pub fn bandname_band(&self, bandname: BandName) -> Option<&BandUid> { pub fn bandname_band(&self, bandname: &BandName) -> Option<&BandUid> {
self.band_bandname.get_by_right(&bandname) self.band_bandname.get_by_right(bandname)
} }
/// Creates band between the two nodes /// Creates band between the two nodes
@ -198,11 +198,11 @@ impl<M: AccessMesadata> Board<M> {
band: BandUid, band: BandUid,
) { ) {
let source_pinname = self let source_pinname = self
.node_pinname(GenericNode::Primitive(source.into())) .node_pinname(&GenericNode::Primitive(source.into()))
.unwrap() .unwrap()
.to_string(); .to_string();
let target_pinname = self let target_pinname = self
.node_pinname(GenericNode::Primitive(target.into())) .node_pinname(&GenericNode::Primitive(target.into()))
.unwrap() .unwrap()
.to_string(); .to_string();
self.band_bandname self.band_bandname