fix(specctra/design): handle polygon seg between first and last dot properly

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-04-17 12:49:41 +02:00
parent 122ff0122f
commit a56628e250
2 changed files with 25 additions and 16 deletions

View File

@ -47,6 +47,7 @@ default = ["disable_contracts"]
disable_contracts = ["contracts-try/disable_contracts"] disable_contracts = ["contracts-try/disable_contracts"]
[dependencies] [dependencies]
approx = "0.5"
bimap.workspace = true bimap.workspace = true
contracts-try = "0.7" contracts-try = "0.7"
derive-getters.workspace = true derive-getters.workspace = true

View File

@ -638,7 +638,7 @@ impl SpecctraDesign {
board: &mut Board<SpecctraMesadata>, board: &mut Board<SpecctraMesadata>,
place: PointWithRotation, place: PointWithRotation,
pin: PointWithRotation, pin: PointWithRotation,
coords: &[structure::Point], mut coords: &[structure::Point],
width: f64, width: f64,
layer: usize, layer: usize,
maybe_net: Option<usize>, maybe_net: Option<usize>,
@ -647,7 +647,7 @@ impl SpecctraDesign {
let mut nodes = Vec::with_capacity(coords.len() * 2 - 1); let mut nodes = Vec::with_capacity(coords.len() * 2 - 1);
// 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.add_fixed_dot_infringably( let first_index = board.add_fixed_dot_infringably(
recorder, recorder,
FixedDotWeight(GeneralDotWeight { FixedDotWeight(GeneralDotWeight {
circle: Circle { circle: Circle {
@ -659,10 +659,23 @@ impl SpecctraDesign {
}), }),
None, None,
); );
nodes.push(prev_index.into()); nodes.push(first_index.into());
let mut prev_index = first_index;
if approx::abs_diff_eq!(coords[0].x, coords.last().unwrap().x)
&& approx::abs_diff_eq!(coords[0].y, coords.last().unwrap().y)
{
coords = &coords[..coords.len() - 1];
}
let seg_weight = FixedSegWeight(GeneralSegWeight {
width,
layer,
maybe_net,
});
// 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[1..] {
let index = board.add_fixed_dot_infringably( let index = board.add_fixed_dot_infringably(
recorder, recorder,
FixedDotWeight(GeneralDotWeight { FixedDotWeight(GeneralDotWeight {
@ -680,24 +693,19 @@ impl SpecctraDesign {
// add a seg between the current and previous coords // add a seg between the current and previous coords
nodes.push( nodes.push(
board board
.add_fixed_seg_infringably( .add_fixed_seg_infringably(recorder, prev_index, index, seg_weight, None)
recorder,
prev_index,
index,
FixedSegWeight(GeneralSegWeight {
width,
layer,
maybe_net,
}),
None,
)
.into(), .into(),
); );
prev_index = index; prev_index = index;
} }
// assumption: the last coord and the first coord are equal // add a seg between the last and first coords
nodes.push(
board
.add_fixed_seg_infringably(recorder, prev_index, first_index, seg_weight, None)
.into(),
);
board.add_poly_with_nodes( board.add_poly_with_nodes(
recorder, recorder,