drawing,layout,board: categorize methods as possibly infringing and not

This commit is contained in:
Mikolaj Wielgus 2024-06-11 23:57:47 +02:00
parent 9e65a28c3d
commit f91dadf4d3
4 changed files with 262 additions and 221 deletions

View File

@ -36,68 +36,70 @@ impl<M: MesadataTrait> Board<M> {
} }
} }
pub fn add_fixed_dot( pub fn add_fixed_dot_infringably(
&mut self, &mut self,
weight: FixedDotWeight, weight: FixedDotWeight,
maybe_pin: Option<String>, maybe_pin: Option<String>,
) -> Result<FixedDotIndex, Infringement> { ) -> FixedDotIndex {
let dot = self.layout.add_fixed_dot(weight)?; let dot = self.layout.add_fixed_dot_infringably(weight);
if let Some(ref pin) = maybe_pin { if let Some(ref pin) = maybe_pin {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(dot.into()), pin.clone()); .insert(GenericNode::Primitive(dot.into()), pin.clone());
} }
Ok(dot) dot
} }
pub fn add_zone_fixed_dot( pub fn add_zone_fixed_dot_infringably(
&mut self, &mut self,
weight: FixedDotWeight, weight: FixedDotWeight,
zone: GenericIndex<ZoneWeight>, zone: GenericIndex<ZoneWeight>,
) -> Result<FixedDotIndex, Infringement> { ) -> FixedDotIndex {
let dot = self.layout.add_zone_fixed_dot(weight, zone)?; let dot = self.layout.add_zone_fixed_dot_infringably(weight, zone);
if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.into())) { if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.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());
} }
Ok(dot) dot
} }
pub fn add_fixed_seg( pub fn add_fixed_seg_infringably(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,
to: FixedDotIndex, to: FixedDotIndex,
weight: FixedSegWeight, weight: FixedSegWeight,
maybe_pin: Option<String>, maybe_pin: Option<String>,
) -> Result<FixedSegIndex, Infringement> { ) -> FixedSegIndex {
let seg = self.layout.add_fixed_seg(from, to, weight)?; let seg = self.layout.add_fixed_seg_infringably(from, to, weight);
if let Some(pin) = maybe_pin { if let Some(pin) = maybe_pin {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(seg.into()), pin.to_string()); .insert(GenericNode::Primitive(seg.into()), pin.to_string());
} }
Ok(seg) seg
} }
pub fn add_zone_fixed_seg( pub fn add_zone_fixed_seg_infringably(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,
to: FixedDotIndex, to: FixedDotIndex,
weight: FixedSegWeight, weight: FixedSegWeight,
zone: GenericIndex<ZoneWeight>, zone: GenericIndex<ZoneWeight>,
) -> Result<FixedSegIndex, Infringement> { ) -> FixedSegIndex {
let seg = self.layout.add_zone_fixed_seg(from, to, weight, zone)?; let seg = self
.layout
.add_zone_fixed_seg_infringably(from, to, weight, zone);
if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.into())) { if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.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());
} }
Ok(seg) seg
} }
pub fn add_zone( pub fn add_zone(
@ -145,7 +147,7 @@ impl<M: MesadataTrait> Board<M> {
if let Some(apex) = self.layout.zone(zone).maybe_apex() { if let Some(apex) = self.layout.zone(zone).maybe_apex() {
apex apex
} else { } else {
self.add_zone_fixed_dot( self.add_zone_fixed_dot_infringably(
FixedDotWeight { FixedDotWeight {
circle: Circle { circle: Circle {
pos: self.layout.zone(zone).shape().center(), pos: self.layout.zone(zone).shape().center(),
@ -156,7 +158,6 @@ impl<M: MesadataTrait> Board<M> {
}, },
zone, zone,
) )
.unwrap()
} }
} }

View File

@ -148,14 +148,16 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
} }
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn add_fixed_dot_infringably( pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> {
&mut self, self.add_dot_with_infringables(weight, Some(&[]))
weight: FixedDotWeight, }
) -> Result<FixedDotIndex, Infringement> {
self.add_dot_with_infringables(weight, None) #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn add_fixed_dot_infringably(&mut self, weight: FixedDotWeight) -> FixedDotIndex {
self.add_dot_infringably(weight)
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
@ -168,23 +170,44 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
where where
GenericIndex<W>: Into<PrimitiveIndex> + Copy, GenericIndex<W>: Into<PrimitiveIndex> + Copy,
{ {
let dot = self.geometry_with_rtree.add_dot(weight); let dot = self.add_dot_infringably(weight);
self.fail_and_remove_if_infringes_except(dot.into(), infringables)?; self.fail_and_remove_if_infringes_except(dot.into(), infringables)?;
Ok(dot) Ok(dot)
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))] #[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))] fn add_dot_infringably<W: DotWeightTrait<PrimitiveWeight> + GetLayer>(
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))] &mut self,
pub fn add_fixed_seg_infringably( weight: W,
) -> GenericIndex<W>
where
GenericIndex<W>: Into<PrimitiveIndex> + Copy,
{
self.geometry_with_rtree.add_dot(weight)
}
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn add_fixed_seg(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,
to: FixedDotIndex, to: FixedDotIndex,
weight: FixedSegWeight, weight: FixedSegWeight,
) -> Result<FixedSegIndex, Infringement> { ) -> Result<FixedSegIndex, Infringement> {
self.add_seg_with_infringables(from.into(), to.into(), weight, None) self.add_seg_with_infringables(from.into(), to.into(), weight, Some(&[]))
}
#[debug_ensures(self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))]
pub fn add_fixed_seg_infringably(
&mut self,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
) -> FixedSegIndex {
self.add_seg_infringably(from.into(), to.into(), weight)
} }
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
@ -229,12 +252,24 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
where where
GenericIndex<W>: Into<PrimitiveIndex> + Copy, GenericIndex<W>: Into<PrimitiveIndex> + Copy,
{ {
let seg = self.geometry_with_rtree.add_seg(from, to, weight); let seg = self.add_seg_infringably(from, to, weight);
self.fail_and_remove_if_infringes_except(seg.into(), infringables)?; self.fail_and_remove_if_infringes_except(seg.into(), infringables)?;
Ok(seg) Ok(seg)
} }
fn add_seg_infringably<W: SegWeightTrait<PrimitiveWeight> + GetLayer>(
&mut self,
from: DotIndex,
to: DotIndex,
weight: W,
) -> GenericIndex<W>
where
GenericIndex<W>: Into<PrimitiveIndex>,
{
self.geometry_with_rtree.add_seg(from, to, weight)
}
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))] #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count() + 1))]
#[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 3) #[debug_ensures(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 3)
|| self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 4))] || self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 4))]

View File

@ -378,16 +378,14 @@ impl DsnDesign {
r, r,
}; };
board board.add_fixed_dot_infringably(
.add_fixed_dot( FixedDotWeight {
FixedDotWeight { circle,
circle, layer,
layer, maybe_net: Some(net),
maybe_net: Some(net), },
}, maybe_pin.clone(),
maybe_pin.clone(), );
)
.unwrap();
} }
fn add_rect( fn add_rect(
@ -414,107 +412,91 @@ impl DsnDesign {
); );
// Corners. // Corners.
let dot_1_1 = board let dot_1_1 = board.add_zone_fixed_dot_infringably(
.add_zone_fixed_dot( FixedDotWeight {
FixedDotWeight { circle: Circle {
circle: Circle { pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y1),
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y1), r: 0.5,
r: 0.5,
},
layer,
maybe_net: Some(net),
}, },
zone, layer,
) maybe_net: Some(net),
.unwrap(); },
let dot_2_1 = board zone,
.add_zone_fixed_dot( );
FixedDotWeight { let dot_2_1 = board.add_zone_fixed_dot_infringably(
circle: Circle { FixedDotWeight {
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y1), circle: Circle {
r: 0.5, pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y1),
}, r: 0.5,
layer,
maybe_net: Some(net),
}, },
zone, layer,
) maybe_net: Some(net),
.unwrap(); },
let dot_2_2 = board zone,
.add_zone_fixed_dot( );
FixedDotWeight { let dot_2_2 = board.add_zone_fixed_dot_infringably(
circle: Circle { FixedDotWeight {
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y2), circle: Circle {
r: 0.5, pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x2, y2),
}, r: 0.5,
layer,
maybe_net: Some(net),
}, },
zone, layer,
) maybe_net: Some(net),
.unwrap(); },
let dot_1_2 = board zone,
.add_zone_fixed_dot( );
FixedDotWeight { let dot_1_2 = board.add_zone_fixed_dot_infringably(
circle: Circle { FixedDotWeight {
pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y2), circle: Circle {
r: 0.5, pos: Self::pos(place_pos, place_rot, pin_pos, pin_rot, x1, y2),
}, r: 0.5,
layer,
maybe_net: Some(net),
}, },
zone, layer,
) maybe_net: Some(net),
.unwrap(); },
zone,
);
// Sides. // Sides.
board board.add_zone_fixed_seg_infringably(
.add_zone_fixed_seg( dot_1_1,
dot_1_1, dot_2_1,
dot_2_1, FixedSegWeight {
FixedSegWeight { width: 1.0,
width: 1.0, layer,
layer, maybe_net: Some(net),
maybe_net: Some(net), },
}, zone,
zone, );
) board.add_zone_fixed_seg_infringably(
.unwrap(); dot_2_1,
board dot_2_2,
.add_zone_fixed_seg( FixedSegWeight {
dot_2_1, width: 1.0,
dot_2_2, layer,
FixedSegWeight { maybe_net: Some(net),
width: 1.0, },
layer, zone,
maybe_net: Some(net), );
}, board.add_zone_fixed_seg_infringably(
zone, dot_2_2,
) dot_1_2,
.unwrap(); FixedSegWeight {
board width: 1.0,
.add_zone_fixed_seg( layer,
dot_2_2, maybe_net: Some(net),
dot_1_2, },
FixedSegWeight { zone,
width: 1.0, );
layer, board.add_zone_fixed_seg_infringably(
maybe_net: Some(net), dot_1_2,
}, dot_1_1,
zone, FixedSegWeight {
) width: 1.0,
.unwrap(); layer,
board maybe_net: Some(net),
.add_zone_fixed_seg( },
dot_1_2, zone,
dot_1_1, );
FixedSegWeight {
width: 1.0,
layer,
maybe_net: Some(net),
},
zone,
)
.unwrap();
} }
fn add_path( fn add_path(
@ -538,19 +520,17 @@ impl DsnDesign {
coords[0].x as f64, coords[0].x as f64,
coords[0].y as f64, coords[0].y as f64,
); );
let mut prev_index = board let mut prev_index = board.add_fixed_dot_infringably(
.add_fixed_dot( FixedDotWeight {
FixedDotWeight { circle: Circle {
circle: Circle { pos: prev_pos,
pos: prev_pos, r: width / 2.0,
r: width / 2.0,
},
layer,
maybe_net: Some(net),
}, },
maybe_pin.clone(), layer,
) maybe_net: Some(net),
.unwrap(); },
maybe_pin.clone(),
);
// iterate through path coords starting from the second // iterate through path coords starting from the second
for coord in coords.iter().skip(1) { for coord in coords.iter().skip(1) {
@ -567,33 +547,29 @@ impl DsnDesign {
continue; continue;
} }
let index = board let index = board.add_fixed_dot_infringably(
.add_fixed_dot( FixedDotWeight {
FixedDotWeight { circle: Circle {
circle: Circle { pos,
pos, r: width / 2.0,
r: width / 2.0,
},
layer,
maybe_net: Some(net),
}, },
maybe_pin.clone(), layer,
) maybe_net: Some(net),
.unwrap(); },
maybe_pin.clone(),
);
// add a seg between the current and previous coords // add a seg between the current and previous coords
let _ = board let _ = board.add_fixed_seg_infringably(
.add_fixed_seg( prev_index,
prev_index, index,
index, FixedSegWeight {
FixedSegWeight { width,
width, layer,
layer, maybe_net: Some(net),
maybe_net: Some(net), },
}, maybe_pin.clone(),
maybe_pin.clone(), );
)
.unwrap();
prev_index = index; prev_index = index;
prev_pos = pos; prev_pos = pos;
@ -622,8 +598,30 @@ impl DsnDesign {
); );
// add the first coordinate in the wire path as a dot and save its index // add the first coordinate in the wire path as a dot and save its index
let mut prev_index = board let mut prev_index = board.add_zone_fixed_dot_infringably(
.add_zone_fixed_dot( FixedDotWeight {
circle: Circle {
pos: Self::pos(
place_pos,
place_rot,
pin_pos,
pin_rot,
coords[0].x as f64,
coords[0].y as f64,
),
r: width / 2.0,
},
layer,
maybe_net: Some(net),
},
// TODO: This manual retagging shouldn't be necessary, `.into()` should suffice.
//GenericIndex::new(zone.node_index()).into(),
zone,
);
// iterate through path coords starting from the second
for coord in coords.iter().skip(1) {
let index = board.add_zone_fixed_dot_infringably(
FixedDotWeight { FixedDotWeight {
circle: Circle { circle: Circle {
pos: Self::pos( pos: Self::pos(
@ -631,59 +629,31 @@ impl DsnDesign {
place_rot, place_rot,
pin_pos, pin_pos,
pin_rot, pin_rot,
coords[0].x as f64, coord.x as f64,
coords[0].y as f64, coord.y as f64,
), )
.into(),
r: width / 2.0, r: width / 2.0,
}, },
layer, layer,
maybe_net: Some(net), maybe_net: Some(net),
}, },
// TODO: This manual retagging shouldn't be necessary, `.into()` should suffice. // TODO: This manual retagging shouldn't be necessary, `.into()` should suffice.
//GenericIndex::new(zone.node_index()).into(),
zone, zone,
) );
.unwrap();
// iterate through path coords starting from the second
for coord in coords.iter().skip(1) {
let index = board
.add_zone_fixed_dot(
FixedDotWeight {
circle: Circle {
pos: Self::pos(
place_pos,
place_rot,
pin_pos,
pin_rot,
coord.x as f64,
coord.y as f64,
)
.into(),
r: width / 2.0,
},
layer,
maybe_net: Some(net),
},
// TODO: This manual retagging shouldn't be necessary, `.into()` should suffice.
zone,
)
.unwrap();
// add a seg between the current and previous coords // add a seg between the current and previous coords
let _ = board let _ = board.add_zone_fixed_seg_infringably(
.add_zone_fixed_seg( prev_index,
prev_index, index,
index, FixedSegWeight {
FixedSegWeight { width,
width, layer,
layer, maybe_net: Some(net),
maybe_net: Some(net), },
}, // TODO: This manual retagging shouldn't be necessary, `.into()` should suffice.
// TODO: This manual retagging shouldn't be necessary, `.into()` should suffice. zone,
zone, );
)
.unwrap();
prev_index = index; prev_index = index;
} }

View File

@ -90,6 +90,10 @@ impl<R: RulesTrait> Layout<R> {
} }
pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> { pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> {
self.drawing.add_fixed_dot(weight)
}
pub fn add_fixed_dot_infringably(&mut self, weight: FixedDotWeight) -> FixedDotIndex {
self.drawing.add_fixed_dot_infringably(weight) self.drawing.add_fixed_dot_infringably(weight)
} }
@ -107,6 +111,16 @@ impl<R: RulesTrait> Layout<R> {
maybe_dot maybe_dot
} }
pub fn add_zone_fixed_dot_infringably(
&mut self,
weight: FixedDotWeight,
zone: GenericIndex<ZoneWeight>,
) -> FixedDotIndex {
let dot = self.drawing.add_fixed_dot_infringably(weight);
self.drawing.add_to_compound(dot, zone.into());
dot
}
pub fn add_fixed_seg( pub fn add_fixed_seg(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,
@ -116,6 +130,15 @@ impl<R: RulesTrait> Layout<R> {
self.drawing.add_fixed_seg(from, to, weight) self.drawing.add_fixed_seg(from, to, weight)
} }
pub fn add_fixed_seg_infringably(
&mut self,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
) -> FixedSegIndex {
self.drawing.add_fixed_seg_infringably(from, to, weight)
}
pub fn add_zone_fixed_seg( pub fn add_zone_fixed_seg(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,
@ -132,6 +155,18 @@ impl<R: RulesTrait> Layout<R> {
maybe_seg maybe_seg
} }
pub fn add_zone_fixed_seg_infringably(
&mut self,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
zone: GenericIndex<ZoneWeight>,
) -> FixedSegIndex {
let seg = self.add_fixed_seg_infringably(from, to, weight);
self.drawing.add_to_compound(seg, zone.into());
seg
}
pub fn add_lone_loose_seg( pub fn add_lone_loose_seg(
&mut self, &mut self,
from: FixedDotIndex, from: FixedDotIndex,