Skip to content

Commit e627451

Browse files
committed
bugfix: wires with swapped start/end points should be equivalent
Lexicographically order the wire endpoints before inserting into a circuit, swap if necessary so that start < end.
1 parent 29c199c commit e627451

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/circuit.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ impl Circuit {
155155
}
156156

157157
fn insert_wire(&mut self, start: IVec2, end: IVec2) -> bool {
158+
// Lexicographically order the start/end points to ensure "backwards" duplicates
159+
// get caught.
160+
if <[i32; 2]>::from(start) > <[i32; 2]>::from(end) {
161+
return self.insert_wire(end, start);
162+
}
163+
158164
// Either a wire's start and end X coordinates need to be the same,
159165
// or their Y coordinates need to be the same, but not both.
160166
// (If both, then the wire would be zero-length, which is not useful.)
@@ -221,7 +227,6 @@ impl Circuit {
221227
if *slot == Some(wire_id) {
222228
removed = true;
223229
*slot = None;
224-
break;
225230
}
226231
}
227232
assert!(removed);

0 commit comments

Comments
 (0)