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,
weight: FixedDotWeight,
maybe_pin: Option<String>,
) -> Result<FixedDotIndex, Infringement> {
let dot = self.layout.add_fixed_dot(weight)?;
) -> FixedDotIndex {
let dot = self.layout.add_fixed_dot_infringably(weight);
if let Some(ref pin) = maybe_pin {
self.node_to_pinname
.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,
weight: FixedDotWeight,
zone: GenericIndex<ZoneWeight>,
) -> Result<FixedDotIndex, Infringement> {
let dot = self.layout.add_zone_fixed_dot(weight, zone)?;
) -> FixedDotIndex {
let dot = self.layout.add_zone_fixed_dot_infringably(weight, zone);
if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.into())) {
self.node_to_pinname
.insert(GenericNode::Primitive(dot.into()), pin.to_string());
}
Ok(dot)
dot
}
pub fn add_fixed_seg(
pub fn add_fixed_seg_infringably(
&mut self,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
maybe_pin: Option<String>,
) -> Result<FixedSegIndex, Infringement> {
let seg = self.layout.add_fixed_seg(from, to, weight)?;
) -> FixedSegIndex {
let seg = self.layout.add_fixed_seg_infringably(from, to, weight);
if let Some(pin) = maybe_pin {
self.node_to_pinname
.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,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
zone: GenericIndex<ZoneWeight>,
) -> Result<FixedSegIndex, Infringement> {
let seg = self.layout.add_zone_fixed_seg(from, to, weight, zone)?;
) -> FixedSegIndex {
let seg = self
.layout
.add_zone_fixed_seg_infringably(from, to, weight, zone);
if let Some(pin) = self.node_pinname(GenericNode::Compound(zone.into())) {
self.node_to_pinname
.insert(GenericNode::Primitive(seg.into()), pin.to_string());
}
Ok(seg)
seg
}
pub fn add_zone(
@ -145,7 +147,7 @@ impl<M: MesadataTrait> Board<M> {
if let Some(apex) = self.layout.zone(zone).maybe_apex() {
apex
} else {
self.add_zone_fixed_dot(
self.add_zone_fixed_dot_infringably(
FixedDotWeight {
circle: Circle {
pos: self.layout.zone(zone).shape().center(),
@ -156,7 +158,6 @@ impl<M: MesadataTrait> Board<M> {
},
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(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().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,
) -> Result<FixedDotIndex, Infringement> {
self.add_dot_with_infringables(weight, None)
pub fn add_fixed_dot(&mut self, weight: FixedDotWeight) -> Result<FixedDotIndex, Infringement> {
self.add_dot_with_infringables(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()))]
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))]
@ -168,23 +170,44 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
where
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)?;
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(ret.is_ok() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count() + 2))]
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().node_count() == old(self.geometry_with_rtree.graph().node_count()))]
#[debug_ensures(ret.is_err() -> self.geometry_with_rtree.graph().edge_count() == old(self.geometry_with_rtree.graph().edge_count()))]
pub fn add_fixed_seg_infringably(
#[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()))]
fn add_dot_infringably<W: DotWeightTrait<PrimitiveWeight> + GetLayer>(
&mut self,
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,
from: FixedDotIndex,
to: FixedDotIndex,
weight: FixedSegWeight,
) -> 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))]
@ -229,12 +252,24 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
where
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)?;
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().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))]

View File

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