Fixed a bug in MatrixCellChain placement

This commit is contained in:
Weird Constructor 2022-07-24 08:12:59 +02:00
parent a559d689eb
commit b98f978ab5

View file

@ -29,8 +29,7 @@ use std::collections::HashMap;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct MatrixChainLink { struct MatrixChainLink {
cell: Cell, cell: Cell,
x: i32, dir: CellDir,
y: i32,
params: Vec<(ParamId, SAtom)>, params: Vec<(ParamId, SAtom)>,
} }
@ -60,7 +59,6 @@ pub struct MatrixCellChain {
chain: Vec<MatrixChainLink>, chain: Vec<MatrixChainLink>,
error: Option<ChainError>, error: Option<ChainError>,
dir: CellDir, dir: CellDir,
pos: (i32, i32),
param_idx: usize, param_idx: usize,
} }
@ -80,7 +78,6 @@ impl MatrixCellChain {
dir, dir,
chain: vec![], chain: vec![],
error: None, error: None,
pos: (0, 0),
param_idx: 0, param_idx: 0,
} }
} }
@ -156,12 +153,7 @@ impl MatrixCellChain {
/// ///
/// This also sets the current parameter cell. /// This also sets the current parameter cell.
pub fn add_link(&mut self, cell: Cell) { pub fn add_link(&mut self, cell: Cell) {
self.chain.push(MatrixChainLink { x: self.pos.0, y: self.pos.1, cell, params: vec![] }); self.chain.push(MatrixChainLink { dir: self.dir, cell, params: vec![] });
let offs = self.dir.as_offs(self.pos.0 as usize);
self.pos.0 += offs.0;
self.pos.1 += offs.1;
self.param_idx = self.chain.len() - 1; self.param_idx = self.chain.len() - 1;
} }
@ -227,10 +219,10 @@ impl MatrixCellChain {
let mut last_unused = HashMap::new(); let mut last_unused = HashMap::new();
let mut pos = (at_x, at_y);
for link in self.chain.iter() { for link in self.chain.iter() {
let (x, y) = (link.x, link.y); let (x, y) = pos;
let x = (x + (at_x as i32)) as usize;
let y = (y + (at_y as i32)) as usize;
let mut cell = link.cell.clone(); let mut cell = link.cell.clone();
@ -251,6 +243,10 @@ impl MatrixCellChain {
println!("PLACE: ({},{}) {:?}", x, y, cell); println!("PLACE: ({},{}) {:?}", x, y, cell);
matrix.place(x, y, cell); matrix.place(x, y, cell);
let offs = link.dir.as_offs(pos.0);
pos.0 = (pos.0 as i32 + offs.0) as usize;
pos.1 = (pos.1 as i32 + offs.1) as usize;
} }
for link in self.chain.iter() { for link in self.chain.iter() {