fixed rotation issues + updated readme
This commit is contained in:
+7
-10
@@ -42,7 +42,7 @@ pub fn parse(data: &[u8]) -> Result<Vec<StitchCommand>, Error> {
|
||||
break;
|
||||
}
|
||||
let dx = data[i] as i8 as i16;
|
||||
let dy = data[i + 1] as i8 as i16;
|
||||
let dy = -(data[i + 1] as i8 as i16);
|
||||
commands.push(StitchCommand::Jump { dx, dy });
|
||||
i += 2;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ pub fn parse(data: &[u8]) -> Result<Vec<StitchCommand>, Error> {
|
||||
}
|
||||
} else {
|
||||
let dx = b1 as i8 as i16;
|
||||
let dy = b2 as i8 as i16;
|
||||
let dy = -(b2 as i8 as i16);
|
||||
commands.push(StitchCommand::Stitch { dx, dy });
|
||||
i += 2;
|
||||
}
|
||||
@@ -88,8 +88,8 @@ mod tests {
|
||||
fn parse_simple_stitches() {
|
||||
let data = [0x0A, 0x14, 0x05, 0x03];
|
||||
let cmds = parse(&data).unwrap();
|
||||
assert!(matches!(cmds[0], StitchCommand::Stitch { dx: 10, dy: 20 }));
|
||||
assert!(matches!(cmds[1], StitchCommand::Stitch { dx: 5, dy: 3 }));
|
||||
assert!(matches!(cmds[0], StitchCommand::Stitch { dx: 10, dy: -20 }));
|
||||
assert!(matches!(cmds[1], StitchCommand::Stitch { dx: 5, dy: -3 }));
|
||||
assert!(matches!(cmds[2], StitchCommand::End));
|
||||
}
|
||||
|
||||
@@ -98,10 +98,7 @@ mod tests {
|
||||
// -10 as i8 = 0xF6, -20 as i8 = 0xEC
|
||||
let data = [0xF6, 0xEC];
|
||||
let cmds = parse(&data).unwrap();
|
||||
assert!(matches!(
|
||||
cmds[0],
|
||||
StitchCommand::Stitch { dx: -10, dy: -20 }
|
||||
));
|
||||
assert!(matches!(cmds[0], StitchCommand::Stitch { dx: -10, dy: 20 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -110,14 +107,14 @@ mod tests {
|
||||
let cmds = parse(&data).unwrap();
|
||||
assert!(matches!(cmds[0], StitchCommand::Stitch { .. }));
|
||||
assert!(matches!(cmds[1], StitchCommand::ColorChange));
|
||||
assert!(matches!(cmds[2], StitchCommand::Stitch { dx: 5, dy: 3 }));
|
||||
assert!(matches!(cmds[2], StitchCommand::Stitch { dx: 5, dy: -3 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_jump() {
|
||||
let data = [0x80, 0x04, 0x0A, 0x14];
|
||||
let cmds = parse(&data).unwrap();
|
||||
assert!(matches!(cmds[0], StitchCommand::Jump { dx: 10, dy: 20 }));
|
||||
assert!(matches!(cmds[0], StitchCommand::Jump { dx: 10, dy: -20 }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user