Skip to content

Commit d1998ce

Browse files
authored
Merge pull request #23 from nicolube/fix/negative-sr
Allow negative I/J offsets in step-and-repeat.
2 parents 4c1a05b + dd77097 commit d1998ce

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static RE_INTERPOLATION: Lazy<Regex> =
5757
static RE_MOVE_OR_FLASH: Lazy<Regex> = lazy_regex!(r"X?(-?[0-9]+)?Y?(-?[0-9]+)?D(0)?[2-3]*");
5858
static RE_IMAGE_NAME: Lazy<Regex> = lazy_regex!(r"%IN(.*)\*%");
5959
static RE_STEP_REPEAT: Lazy<Regex> =
60-
lazy_regex!(r"%SRX([0-9]+)Y([0-9]+)I(\d+\.?\d*)J(\d+\.?\d*)\*%");
60+
lazy_regex!(r"%SRX([0-9]+)Y([0-9]+)I(-?\d+\.?\d*)J(-?\d+\.?\d*)\*%");
6161
static RE_MACRO_UNSIGNED_INTEGER: Lazy<Regex> =
6262
lazy_regex!(r"^(?:(?P<value>[0-9]+)|(?P<variable>\$[0-9]+)|(?P<expression>.*))$");
6363
static RE_MACRO_BOOLEAN: Lazy<Regex> =

tests/component_tests.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ fn test_load_scaling_zero() {
780780
));
781781
}
782782

783-
/// Test Step and Repeat command (%SR*%)
783+
/// Test Step and Repeat command (%SR*%), including negative I/J offsets.
784784
#[test]
785785
fn step_and_repeat() {
786786
// given
@@ -800,7 +800,11 @@ fn step_and_repeat() {
800800
X-1000Y-30000D01*
801801
%SR*%
802802
803-
M02*
803+
%SRX12Y6I-3.33J-8.120*%
804+
X0Y0D01*
805+
%SR*%
806+
807+
M02*
804808
",
805809
);
806810

@@ -825,6 +829,17 @@ fn step_and_repeat() {
825829
Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat(
826830
StepAndRepeat::Close
827831
))),
832+
Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat(
833+
StepAndRepeat::Open {
834+
repeat_x: 12,
835+
repeat_y: 6,
836+
distance_x: -3.33,
837+
distance_y: -8.12,
838+
}
839+
))),
840+
Ok(Command::ExtendedCode(ExtendedCode::StepAndRepeat(
841+
StepAndRepeat::Close
842+
))),
828843
]
829844
)
830845
}

0 commit comments

Comments
 (0)