Show the displacement of a single shape move
This commit is contained in:
parent
28b7f10f6e
commit
4789638e22
3 changed files with 94 additions and 27 deletions
12
docs/cli.md
12
docs/cli.md
|
|
@ -54,15 +54,17 @@ Text reports start with the result. The headline includes cell counts for
|
||||||
reports with more than three changed cells, incomplete comparisons, or omitted
|
reports with more than three changed cells, incomplete comparisons, or omitted
|
||||||
changes. The `Cells:` section lists removals with `-`, additions with `+`, and
|
changes. The `Cells:` section lists removals with `-`, additions with `+`, and
|
||||||
modifications with `*`. Modified cells show counts of rectangles, polygons, and
|
modifications with `*`. Modified cells show counts of rectangles, polygons, and
|
||||||
boxes changed, moved, added, or removed on each layer. Repeated reference
|
boxes changed, moved, added, or removed on each layer. When the only displayed
|
||||||
additions or removals to the same target appear as a count. When both occur for
|
shape change on a layer is a move, the row shows its displacement in database
|
||||||
one target, they share a row. A complete set of edits to a target also shows
|
units. Repeated reference additions or removals to the same target appear as a
|
||||||
|
count. When both occur for one target, they share a row. A complete set of edits
|
||||||
|
to a target also shows
|
||||||
the total direct placements when there are unchanged placements, for example
|
the total direct placements when there are unchanged placements, for example
|
||||||
`leaf · -3 refs, +6 refs · placements 10 -> 13`.
|
`leaf · -3 refs, +6 refs · placements 10 -> 13`.
|
||||||
|
|
||||||
An unchanged layer name appears inline when the layer occurs on one displayed
|
An unchanged layer name appears inline when the layer occurs on one displayed
|
||||||
row, as in `1/0 (WG): 1 rectangle moved`. A layer on several displayed rows
|
row, as in `1/0 (WG): rectangle moved by (20, -5) dbu`. A layer on several
|
||||||
gets one legend entry. Object details use `-` for removals, `+` for additions,
|
displayed rows gets one legend entry. Object details use `-` for removals, `+` for additions,
|
||||||
and `~` for likely replacements. Identical unmatched objects share a row
|
and `~` for likely replacements. Identical unmatched objects share a row
|
||||||
with a count such as `+ 12× 1/0: path …`. Unmatched paths with five or more
|
with a count such as `+ 12× 1/0: path …`. Unmatched paths with five or more
|
||||||
vertices show their width, vertex count, and vertex bounds in one line.
|
vertices show their width, vertex count, and vertex bounds in one line.
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,10 @@ struct ShapeCounts {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeCounts {
|
impl ShapeCounts {
|
||||||
|
fn total(&self) -> usize {
|
||||||
|
self.rectangles + self.polygons + self.boxes
|
||||||
|
}
|
||||||
|
|
||||||
fn add(&mut self, object: &ObjectChange, replacement: Option<&ObjectChange>) {
|
fn add(&mut self, object: &ObjectChange, replacement: Option<&ObjectChange>) {
|
||||||
let is_rectangle =
|
let is_rectangle =
|
||||||
|object: &ObjectChange| XY::closed_rectangle(object_xy(object)).is_some();
|
|object: &ObjectChange| XY::closed_rectangle(object_xy(object)).is_some();
|
||||||
|
|
@ -188,6 +192,7 @@ struct LayerPolygonChanges {
|
||||||
moved: ShapeCounts,
|
moved: ShapeCounts,
|
||||||
removed: ShapeCounts,
|
removed: ShapeCounts,
|
||||||
added: ShapeCounts,
|
added: ShapeCounts,
|
||||||
|
displacement: Option<[i64; 2]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -196,15 +201,18 @@ pub(super) struct PolygonChanges(BTreeMap<Option<Layer>, LayerPolygonChanges>);
|
||||||
impl PolygonChanges {
|
impl PolygonChanges {
|
||||||
pub fn replacement(&mut self, old: &ObjectChange, new: &ObjectChange) {
|
pub fn replacement(&mut self, old: &ObjectChange, new: &ObjectChange) {
|
||||||
let counts = self.0.entry(old.layer).or_default();
|
let counts = self.0.entry(old.layer).or_default();
|
||||||
let moved = old.properties == new.properties
|
let displacement = if old.properties == new.properties {
|
||||||
&& translation(object_xy(old), object_xy(new)).is_some()
|
translation(object_xy(old), object_xy(new))
|
||||||
&& field_changes(old, new).all(|(tag, _, _)| tag == RTAG_XY);
|
.filter(|_| field_changes(old, new).all(|(tag, _, _)| tag == RTAG_XY))
|
||||||
let shapes = if moved {
|
|
||||||
&mut counts.moved
|
|
||||||
} else {
|
} else {
|
||||||
&mut counts.changed
|
None
|
||||||
};
|
};
|
||||||
shapes.add(old, Some(new));
|
if let Some(shift) = displacement {
|
||||||
|
counts.displacement = Some(shift);
|
||||||
|
counts.moved.add(old, Some(new));
|
||||||
|
} else {
|
||||||
|
counts.changed.add(old, Some(new));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unmatched(&mut self, object: &ObjectChange, removed: bool) {
|
pub fn unmatched(&mut self, object: &ObjectChange, removed: bool) {
|
||||||
|
|
@ -226,13 +234,31 @@ impl PolygonChanges {
|
||||||
} else {
|
} else {
|
||||||
out.push_str("unknown layer: ");
|
out.push_str("unknown layer: ");
|
||||||
}
|
}
|
||||||
let mut separator = "";
|
let groups = [
|
||||||
for (action, shapes) in [
|
|
||||||
("changed", &counts.changed),
|
("changed", &counts.changed),
|
||||||
("moved", &counts.moved),
|
("moved", &counts.moved),
|
||||||
("removed", &counts.removed),
|
("removed", &counts.removed),
|
||||||
("added", &counts.added),
|
("added", &counts.added),
|
||||||
] {
|
];
|
||||||
|
if let Some([dx, dy]) = counts.displacement
|
||||||
|
&& groups
|
||||||
|
.iter()
|
||||||
|
.map(|(_, shapes)| shapes.total())
|
||||||
|
.sum::<usize>()
|
||||||
|
== 1
|
||||||
|
{
|
||||||
|
let shape = if counts.moved.rectangles == 1 {
|
||||||
|
"rectangle"
|
||||||
|
} else if counts.moved.boxes == 1 {
|
||||||
|
"box"
|
||||||
|
} else {
|
||||||
|
"polygon"
|
||||||
|
};
|
||||||
|
writeln!(out, "{shape} moved by ({dx}, {dy}) dbu").unwrap();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let mut separator = "";
|
||||||
|
for (action, shapes) in groups {
|
||||||
let terms = [
|
let terms = [
|
||||||
(shapes.rectangles, "rectangle", "rectangles"),
|
(shapes.rectangles, "rectangle", "rectangles"),
|
||||||
(shapes.polygons, "polygon", "polygons"),
|
(shapes.polygons, "polygon", "polygons"),
|
||||||
|
|
|
||||||
|
|
@ -1759,7 +1759,7 @@ fn replacement_explanations_are_unique_and_keep_full_evidence() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn polygon_diff_reports_moves_and_other_changes_without_individual_geometry() {
|
fn polygon_diff_reports_single_displacements_and_groups_bulk_moves() {
|
||||||
let before = layout(&[("CHIP", vec![with_property(square(), "old")])]);
|
let before = layout(&[("CHIP", vec![with_property(square(), "old")])]);
|
||||||
let before = Document::parse(&before).unwrap();
|
let before = Document::parse(&before).unwrap();
|
||||||
for (shape, label) in [
|
for (shape, label) in [
|
||||||
|
|
@ -1787,26 +1787,65 @@ fn polygon_diff_reports_moves_and_other_changes_without_individual_geometry() {
|
||||||
assert!(!text.contains("xy="));
|
assert!(!text.contains("xy="));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let moved_triangle = polygon(&[[2, -1], [12, -1], [2, 9], [2, -1]]);
|
||||||
|
let moved_square = polygon(&[[2, -1], [12, -1], [12, 9], [2, 9], [2, -1]]);
|
||||||
|
let named_layout = |mut objects: Vec<Vec<u8>>| {
|
||||||
|
objects.extend([label((900, 7), LAYER_SENTINEL), label((900, 7), "1:0:WG")]);
|
||||||
|
layout(&[("CHIP", objects)])
|
||||||
|
};
|
||||||
for (shape, shifted, name) in [
|
for (shape, shifted, name) in [
|
||||||
|
(triangle(), moved_triangle, "polygon"),
|
||||||
|
(square(), moved_square.clone(), "rectangle"),
|
||||||
(
|
(
|
||||||
triangle(),
|
ring(
|
||||||
polygon(&[[2, -1], [12, -1], [2, 9], [2, -1]]),
|
RTAG_BOX,
|
||||||
"polygon",
|
RTAG_BOXTYPE,
|
||||||
),
|
1,
|
||||||
(
|
&[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]],
|
||||||
square(),
|
),
|
||||||
polygon(&[[2, -1], [12, -1], [12, 9], [2, 9], [2, -1]]),
|
ring(
|
||||||
"rectangle",
|
RTAG_BOX,
|
||||||
|
RTAG_BOXTYPE,
|
||||||
|
1,
|
||||||
|
&[[2, -1], [12, -1], [12, 9], [2, 9], [2, -1]],
|
||||||
|
),
|
||||||
|
"box",
|
||||||
),
|
),
|
||||||
] {
|
] {
|
||||||
let before = layout(&[("CHIP", vec![shape])]);
|
let before = named_layout(vec![shape]);
|
||||||
let after = layout(&[("CHIP", vec![shifted])]);
|
let after = named_layout(vec![shifted]);
|
||||||
let diff = Comparison::between(
|
let diff = Comparison::between(
|
||||||
&Document::parse(&before).unwrap(),
|
&Document::parse(&before).unwrap(),
|
||||||
&Document::parse(&after).unwrap(),
|
&Document::parse(&after).unwrap(),
|
||||||
);
|
);
|
||||||
assert!(diff.text(100).contains(&format!(" 1/0: 1 {name} moved\n")));
|
assert!(
|
||||||
|
diff.text(100)
|
||||||
|
.contains(&format!(" 1/0 (WG): {name} moved by (2, -1) dbu\n"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let before = named_layout(vec![square()]);
|
||||||
|
let after = named_layout(vec![
|
||||||
|
moved_square,
|
||||||
|
ring(
|
||||||
|
RTAG_BOX,
|
||||||
|
RTAG_BOXTYPE,
|
||||||
|
1,
|
||||||
|
&[[20, 0], [30, 0], [30, 10], [20, 10], [20, 0]],
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
let diff = Comparison::between(
|
||||||
|
&Document::parse(&before).unwrap(),
|
||||||
|
&Document::parse(&after).unwrap(),
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
diff.text(100)
|
||||||
|
.contains(" 1/0 (WG): 1 rectangle moved · 1 box added\n")
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
diff.text(2)
|
||||||
|
.contains(" 1/0 (WG): rectangle moved by (2, -1) dbu\n")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue