nc-gcode-interpreter 0.4.1__tar.gz → 0.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/CHANGELOG.md +54 -0
  2. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/Cargo.lock +1 -1
  3. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/Cargo.toml +1 -1
  4. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/PKG-INFO +1 -1
  5. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/README.md +1 -1
  6. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/__init__.py +59 -16
  7. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/_internal.pyi +2 -1
  8. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_batch_variables.py +1 -1
  9. nc_gcode_interpreter-0.4.3/python/tests/test_frame_scale_mirror.py +244 -0
  10. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_frames.py +3 -3
  11. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_groups.py +2 -2
  12. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_start_inputs.py +2 -2
  13. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_unsupported.py +18 -9
  14. nc_gcode_interpreter-0.4.3/python/tests/test_work_offsets.py +183 -0
  15. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/flatten.rs +47 -0
  16. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/frame.rs +95 -21
  17. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/grammar.pest +3 -2
  18. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/interpret_rules.rs +272 -85
  19. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/lib.rs +34 -1
  20. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/line_driver.rs +15 -3
  21. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/main.rs +1 -0
  22. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/output.rs +15 -1
  23. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/start.rs +29 -21
  24. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/state.rs +280 -69
  25. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/subprogram.rs +9 -1
  26. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/vm.rs +3 -2
  27. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/tests/syntax_compatibility.rs +25 -1
  28. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/.github/workflows/benchmark.yml +0 -0
  29. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/.github/workflows/build-and-release.yml +0 -0
  30. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/.gitignore +0 -0
  31. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/CONTRIBUTING.md +0 -0
  32. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/Development.md +0 -0
  33. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/LICENSE +0 -0
  34. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/TODO.md +0 -0
  35. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/benches/extensions.rs +0 -0
  36. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/benches/fixtures.rs +0 -0
  37. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/benches/workloads.rs +0 -0
  38. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/build.rs +0 -0
  39. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/build_backend/nc_build_backend.py +0 -0
  40. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/docs/resumable-interpretation-design.md +0 -0
  41. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/docs/sinumerik-execution-model.md +0 -0
  42. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/actual_position.csv +0 -0
  43. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/actual_position.mpf +0 -0
  44. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/arc.csv +0 -0
  45. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/arc.mpf +0 -0
  46. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/arrays.csv +0 -0
  47. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/arrays.mpf +0 -0
  48. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/axis_index_assignment.csv +0 -0
  49. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/axis_index_assignment.mpf +0 -0
  50. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/basic_math.csv +0 -0
  51. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/basic_math.mpf +0 -0
  52. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/case.csv +0 -0
  53. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/case.mpf +0 -0
  54. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/case_insensitive_variables.csv +0 -0
  55. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/case_insensitive_variables.mpf +0 -0
  56. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/custom_vars.csv +0 -0
  57. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/custom_vars.mpf +0 -0
  58. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/def_string.csv +0 -0
  59. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/def_string.mpf +0 -0
  60. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/defaults.csv +0 -0
  61. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/defaults.def +0 -0
  62. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/defaults.mpf +0 -0
  63. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/defaults_start.json +0 -0
  64. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/edge_cases.csv +0 -0
  65. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/edge_cases.mpf +0 -0
  66. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo.mpf +0 -0
  67. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo_flattened.csv +0 -0
  68. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo_raw.csv +0 -0
  69. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/for_loop.csv +0 -0
  70. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/for_loop.mpf +0 -0
  71. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/function_calls.csv +0 -0
  72. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/function_calls.mpf +0 -0
  73. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/goto.csv +0 -0
  74. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/goto.mpf +0 -0
  75. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/if_statement.csv +0 -0
  76. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/if_statement.mpf +0 -0
  77. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/increment.csv +0 -0
  78. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/increment.mpf +0 -0
  79. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/logic_operators.csv +0 -0
  80. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/logic_operators.mpf +0 -0
  81. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/loop.csv +0 -0
  82. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/loop.mpf +0 -0
  83. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/multiple_m_codes.csv +0 -0
  84. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/multiple_m_codes.mpf +0 -0
  85. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/precedence.csv +0 -0
  86. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/precedence.mpf +0 -0
  87. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/r_param.csv +0 -0
  88. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/r_param.mpf +0 -0
  89. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/repeat.csv +0 -0
  90. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/repeat.mpf +0 -0
  91. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/rot.csv +0 -0
  92. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/rot.mpf +0 -0
  93. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/simple.csv +0 -0
  94. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/simple.mpf +0 -0
  95. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/spline.csv +0 -0
  96. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/spline.mpf +0 -0
  97. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/tool.csv +0 -0
  98. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/tool.mpf +0 -0
  99. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans.csv +0 -0
  100. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans.mpf +0 -0
  101. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans2.csv +0 -0
  102. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans2.mpf +0 -0
  103. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans_ic.csv +0 -0
  104. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans_ic.mpf +0 -0
  105. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans_reset.csv +0 -0
  106. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trans_reset.mpf +0 -0
  107. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trig.csv +0 -0
  108. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/trig.mpf +0 -0
  109. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/variables.csv +0 -0
  110. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/examples/variables.mpf +0 -0
  111. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/ggroups/generate_g_commands.py +0 -0
  112. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/pyproject.toml +0 -0
  113. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/example/minimal.py +0 -0
  114. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/example/streaming.py +0 -0
  115. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/cli.py +0 -0
  116. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/ggroups.json +0 -0
  117. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/py.typed +0 -0
  118. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/viz.py +0 -0
  119. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/nc_source.py +0 -0
  120. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_arithmetic_functions.py +0 -0
  121. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_batches.py +0 -0
  122. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_bspline_pl.py +0 -0
  123. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_build_backend.py +0 -0
  124. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_compare_benchmarks.py +0 -0
  125. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_diagnostics.py +0 -0
  126. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_expected_output.py +0 -0
  127. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_feed_check.py +0 -0
  128. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_feed_group.py +0 -0
  129. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_field_defects.py +0 -0
  130. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_flags.py +0 -0
  131. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_flatten.py +0 -0
  132. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_frame_columns.py +0 -0
  133. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_group_enum.py +0 -0
  134. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_vocabulary.py +0 -0
  135. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_jumps.py +0 -0
  136. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_preset.py +0 -0
  137. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_real_comparisons.py +0 -0
  138. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_stage1.py +0 -0
  139. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_streaming.py +0 -0
  140. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_string_operations.py +0 -0
  141. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_structured_errors.py +0 -0
  142. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/python/tests/test_subprograms.py +0 -0
  143. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/rustfmt.toml +0 -0
  144. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/scripts/benchmark.py +0 -0
  145. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/scripts/compare_benchmarks.py +0 -0
  146. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/errors.rs +0 -0
  147. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/interpreter.rs +0 -0
  148. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/line_driver/experiments.rs +0 -0
  149. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/modal_groups.rs +0 -0
  150. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/structure_scan.rs +0 -0
  151. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/src/types.rs +0 -0
  152. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/tests/cli.rs +0 -0
  153. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/tests/performance_contract.rs +0 -0
  154. {nc_gcode_interpreter-0.4.1 → nc_gcode_interpreter-0.4.3}/uv.lock +0 -0
@@ -4,6 +4,60 @@ Notable changes to **nc-gcode-interpreter**. The format loosely follows
4
4
  [Keep a Changelog](https://keepachangelog.com/); versions are git tags,
5
5
  released to PyPI.
6
6
 
7
+ ## [v0.4.3] - 2026-12-05
8
+
9
+ ### Added
10
+
11
+ - `nc_to_dataframe` and `nc_to_batches` take a `work_offsets` table (#139)
12
+ that maps G54 to G57 and G505 to G599 to a pose in G500, and then report
13
+ X, Y, Z and the `frame_*` columns in G500. Selecting an offset holds the
14
+ machine position, so partial-axis moves, `IC` increments, programmable
15
+ frames and flattened arcs and helices follow the active offset. G53, G153,
16
+ SUPA, G74 and G75 suppress the offset and the programmable frame for their
17
+ block only. Selecting an offset the table does not define raises an error
18
+ naming the block. A Boolean `xyz_in_g500` column marks the resolved rows.
19
+ `nc_to_rows` and the command-line tools do not take the table.
20
+ - `dataframe_to_nc` writes a frame with `xyz_in_g500` as G500 and G90 moves,
21
+ so the exported program reproduces the same positions. It refuses curved
22
+ motions that were not flattened and any A, B or C column.
23
+
24
+ ## [v0.4.2] - 2026-11-28
25
+
26
+ ### Added
27
+
28
+ - Numeric literals accept the Siemens exponent notation `<mantissa>EX<exponent>`
29
+ (#117), for example `X=-.1EX-3`, `R1=1.874EX8` and `8.2EX-3`, in every place
30
+ a literal is accepted. A plain `E` exponent stays an error.
31
+ - `SCALE`/`ASCALE` and `MIRROR`/`AMIRROR` with arguments are interpreted for
32
+ the geometry axes X, Y, Z (#134). They chain onto the programmable frame as
33
+ machine XYZ = R * S * M * local XYZ + t, so an `ATRANS` after a scale is
34
+ scaled and an `AMIRROR` of a mirrored axis switches the mirror off (the
35
+ toggle behaviour of MD10612 = 0). The `rotation` in the final state and the
36
+ `frame_r11` to `frame_r33` columns hold the rotation with the scale and
37
+ mirror factors folded in. A circular arc is accepted under a frame that
38
+ keeps it a circle with the same direction (its `I`/`J`/`K` and `CR` are
39
+ scaled); an in-plane mirror or unequal in-plane factors under an arc raise
40
+ an error, as does a rotation chained after unequal scale factors.
41
+ - `SCALE`/`ASCALE` also scale every other configured axis, such as an
42
+ extruder axis `E` (#134; manual 3.12.2.6 scales all path, synchronized and
43
+ positioning axes): machine = factor * local + t, `ASCALE` multiplies the
44
+ factor, an `ATRANS` after it is scaled and an absolute frame instruction
45
+ resets it. The factors are in the final state as `axis_scale`, which
46
+ `start` accepts.
47
+ - `ROTS`/`AROTS`/`CROTS` with one solid angle, which is the same rotation as
48
+ `ROT`/`AROT` about that axis (#134). Two solid angles still raise an error,
49
+ because the manuals describe that form in two ways that give different
50
+ rotations.
51
+ - `start['rotation']` accepts a rotation with scale and mirror factors, so a
52
+ final state with an active `SCALE` or `MIRROR` can be resumed.
53
+
54
+ ### Changed
55
+
56
+ - `TOFRAME`, `TOROT` (with their `X`/`Y`/`Z` variants) and `PAROT` raise an
57
+ "unsupported statement" error (#134). They were accepted without effect
58
+ before, so the blocks after them were read in the wrong frame without a
59
+ warning. `TOROTOF` and `PAROTOF` are still accepted.
60
+
7
61
  ## [v0.4.1] - 2026-11-24
8
62
 
9
63
  ### Added
@@ -506,7 +506,7 @@ checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
506
506
 
507
507
  [[package]]
508
508
  name = "nc-gcode-interpreter"
509
- version = "0.4.1"
509
+ version = "0.4.3"
510
510
  dependencies = [
511
511
  "arrow-array",
512
512
  "arrow-data",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "nc-gcode-interpreter"
3
- version = "0.4.1"
3
+ version = "0.4.3"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nc-gcode-interpreter
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -11,7 +11,7 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
11
11
  ### Supported G-code Features
12
12
 
13
13
  - **G Group Commands**: Recognizes G-code groups and modal G-code commands.
14
- - **Programmable frames**: `TRANS`/`ATRANS` work offsets and `ROT`/`AROT` rotations (`X.. Y.. Z..` RPY angles or `RPL=` in the active plane) for the geometry axes X, Y, Z; output coordinates are machine coordinates with the frame applied, and the final state reports the `translation` and `rotation`.
14
+ - **Programmable frames**: `TRANS`/`ATRANS` work offsets, `ROT`/`AROT` rotations (`X.. Y.. Z..` RPY angles or `RPL=` in the active plane), `SCALE`/`ASCALE` factors for every configured axis, and `MIRROR`/`AMIRROR` for the geometry axes X, Y, Z; output coordinates are machine coordinates with the frame applied, and the final state reports the `translation`, the `rotation` (with the X, Y, Z scale and mirror folded in) and the `axis_scale` of the other axes. `ROTS`/`AROTS`/`CROTS` take one solid angle; two solid angles, `TOFRAME`, `TOROT` and `PAROT` raise an error.
15
15
  - **Looping Constructs**: Handles loops using `WHILE`, `FOR`, `REPEAT ... UNTIL` and `LOOP ... ENDLOOP` statements.
16
16
  - **Variable Handling**: Supports definition and manipulation of local variables.
17
17
  - **Conditional Logic**: Implements conditional execution with `IF`, `ELSE`, and `ENDIF`.
@@ -135,6 +135,7 @@ def nc_to_dataframe(
135
135
  required_subprograms: "Iterable[str] | None" = None,
136
136
  stop_on_setal: bool = False,
137
137
  include_frame: bool = False,
138
+ work_offsets: dict[str, list[float]] | None = None,
138
139
  ) -> tuple[pl.DataFrame, dict]:
139
140
  """
140
141
  Parses Sinumerik-flavored NC G-code and converts it into a Polars DataFrame along with the final state.
@@ -167,7 +168,8 @@ def nc_to_dataframe(
167
168
  start: Mapping | None, optional
168
169
  The machine state at program start, in the shape of the returned state
169
170
  dict, so a returned state can be passed back. Keys: ``axes`` and
170
- ``translation`` (dict[str, float]), ``rotation`` (3x3), ``symbol_table``
171
+ ``translation`` (dict[str, float]), ``rotation`` (3x3), ``axis_scale``
172
+ (SCALE factor per non-geometry axis, dict[str, float]), ``symbol_table``
171
173
  (dict[str, float]), ``string_table`` (dict[str, str]), ``g_groups``
172
174
  (modal G group column to code, e.g. ``{"gg01_motion": "G1"}``),
173
175
  ``feed`` (float; pass the control's default feed SD42110
@@ -206,11 +208,29 @@ def nc_to_dataframe(
206
208
  across a jump, matching the streaming `nc_to_rows`. Never
207
209
  forward-filled; `dataframe_to_nc` ignores it. Default False (column
208
210
  absent, output schema unchanged).
211
+ work_offsets: dict, optional
212
+ Map settable work offsets (G54-G57, G505-G599) to [X, Y, Z, rot X,
213
+ rot Y, rot Z] in G500, in program length units and frame RPY degrees.
214
+ Supplying a table resolves XYZ and frame columns in G500. G500 is
215
+ identity and a non-zero G500 entry is refused; when the control's
216
+ $P_UIFR[0] carries values, pass inv(T_G500) @ T_Gn for each offset.
217
+ The translation is the sum of the coarse and fine parts (TR + FI);
218
+ settable SCALE and MIRROR are not represented. A program that writes
219
+ $P_UIFR does not change what the table selects. A selected offset
220
+ missing from the table raises an error. The Boolean column
221
+ ``xyz_in_g500`` records the XYZ coordinate system while
222
+ ``gg08_work_offset`` continues to report the selected offset.
223
+ ``nc_to_dataframe`` and ``nc_to_batches`` take the table;
224
+ ``nc_to_rows`` and the command-line tools do not.
209
225
  include_frame: bool, optional
210
- If True, add the programmable frame (TRANS/ATRANS, ROT/AROT) that is
211
- active on each row as twelve Float64 columns: `frame_r11` to
212
- `frame_r33`, the rotation R row by row, and `frame_tx`, `frame_ty`,
213
- `frame_tz`, the translation t, in machine XYZ = R * local XYZ + t.
226
+ If True, add the programmable frame (TRANS, ROT, SCALE, MIRROR and
227
+ their additive forms) that is active on each row as twelve Float64
228
+ columns: `frame_r11` to `frame_r33`, the linear part R row by row, and
229
+ `frame_tx`, `frame_ty`, `frame_tz`, the translation t, in machine XYZ
230
+ = R * local XYZ + t. R is the rotation with the scale and mirror
231
+ factors folded in, so it is a pure rotation only while no SCALE or
232
+ MIRROR is active. With ``work_offsets`` the columns hold the
233
+ selected offset times the programmable frame, in G500.
214
234
  The values are written on the first row and on the first row after
215
235
  each change, and forward-filled like the axis columns; with
216
236
  `disable_forward_fill` the other rows are null. Programmed A/B/C
@@ -223,6 +243,9 @@ def nc_to_dataframe(
223
243
  A tuple containing:
224
244
  - A Polars DataFrame representing the parsed G-code.
225
245
  - A nested dictionary representing the final state after execution.
246
+ With ``work_offsets`` its translation and rotation are the
247
+ programmable frame relative to the selected offset, as ``start``
248
+ expects.
226
249
 
227
250
  Raises:
228
251
  -------
@@ -275,10 +298,11 @@ def nc_to_dataframe(
275
298
  # No row is read before the run ends, so a provider call need not wait for one.
276
299
  defer_rows=True,
277
300
  include_frame=include_frame,
301
+ work_offsets=work_offsets,
278
302
  )
279
303
  # pl.DataFrame wraps each Arrow record batch via __arrow_c_array__ (polars
280
304
  # >= 1.3), no pyarrow needed. Exhaust the iterator before reading .state.
281
- frames: list[pl.DataFrame] = [_batch_frame(batch) for batch in it]
305
+ frames: list[pl.DataFrame] = [_batch_frame(batch, work_offsets is not None) for batch in it]
282
306
  state = it.state
283
307
  if not frames:
284
308
  # A program with no output rows (e.g. only variable assignments) yields
@@ -369,7 +393,7 @@ _G_GROUP_CATEGORIES: dict[str, pl.Series] = {
369
393
  }
370
394
 
371
395
 
372
- def _batch_frame(batch: Any) -> pl.DataFrame:
396
+ def _batch_frame(batch: Any, xyz_in_g500: bool) -> pl.DataFrame:
373
397
  """Wrap one Arrow batch from Rust, with every G-group column as its Enum.
374
398
 
375
399
  Rust sends each G-group column as UInt8 indices into the group's commands
@@ -377,7 +401,9 @@ def _batch_frame(batch: Any) -> pl.DataFrame:
377
401
  Enum, since polars 2 no longer casts integers to an Enum.
378
402
  """
379
403
  frame = pl.DataFrame(batch)
380
- columns = [_G_GROUP_CATEGORIES[name].gather(frame[name]) for name in frame.columns if name in _G_GROUP_CATEGORIES]
404
+ columns: list[pl.Series | pl.Expr] = [_G_GROUP_CATEGORIES[name].gather(frame[name]) for name in frame.columns if name in _G_GROUP_CATEGORIES]
405
+ if xyz_in_g500:
406
+ columns.append(pl.lit(True).alias("xyz_in_g500"))
381
407
  return frame.with_columns(columns) if columns else frame
382
408
 
383
409
 
@@ -428,7 +454,7 @@ def sanitize_dataframe(
428
454
 
429
455
  # Value columns: anything that is not a known string/list column.
430
456
  value_columns = [
431
- c for c in df.columns if c not in string_columns and c not in ("M", "N")
457
+ c for c in df.columns if c not in string_columns and c not in ("M", "N", "xyz_in_g500")
432
458
  ]
433
459
 
434
460
  # Cast to the canonical dtypes.
@@ -452,6 +478,7 @@ def sanitize_dataframe(
452
478
  *known_axes,
453
479
  *sorted(c for c in value_columns if c not in known_axes and c not in block_addresses),
454
480
  *block_addresses,
481
+ "xyz_in_g500",
455
482
  "T",
456
483
  "M",
457
484
  "non_returning_function_call",
@@ -498,6 +525,16 @@ def dataframe_to_nc(df: pl.DataFrame, file_path: str | Path):
498
525
  >>> df = pl.DataFrame({'X': [10, 20], 'Y': [0, 0], 'Z': [0, 0]})
499
526
  >>> dataframe_to_nc(df, 'output.MPF')
500
527
  """
528
+ if "xyz_in_g500" in df.columns:
529
+ if df["xyz_in_g500"].null_count() or not df["xyz_in_g500"].all():
530
+ raise ValueError("Cannot export mixed XYZ coordinate systems")
531
+ if "gg01_motion" in df.columns and not df["gg01_motion"].drop_nulls().is_in(["G0", "G1"]).all():
532
+ raise ValueError("Flatten curved motions before exporting G500 coordinates")
533
+ if {"A", "B", "C"} & set(df.columns):
534
+ raise ValueError("G500 XYZ export requires orienting A/B/C in the output frame")
535
+ df = df.drop("xyz_in_g500", "flattened", strict=False).with_columns(
536
+ pl.lit("G500").alias("gg08_work_offset"), pl.lit("G90").alias("gg14_wp_measure_mode")
537
+ )
501
538
  df = sanitize_dataframe(df)
502
539
  # Python prototype of df to nc conversion code
503
540
  float_cols = [col for col in df.columns if df[col].dtype == pl.Float64]
@@ -603,8 +640,8 @@ def nc_to_rows(
603
640
 
604
641
  Errors raise ``ValueError`` from ``next()`` when reached. After the
605
642
  iterator is exhausted, its ``state`` attribute holds the final
606
- interpreter state (axes, symbol_table, translation, rotation, string_table,
607
- g_groups, feed, tool, transformation, fgroup, fgref).
643
+ interpreter state (axes, symbol_table, translation, rotation, axis_scale,
644
+ string_table, g_groups, feed, tool, transformation, fgroup, fgref).
608
645
 
609
646
  Example:
610
647
  --------
@@ -645,19 +682,20 @@ class _BatchIterator:
645
682
  no Python list of primitives materialized. ``pl.DataFrame`` wraps that
646
683
  capsule directly (polars >= 1.3), so no ``pyarrow`` is involved. After
647
684
  exhaustion its ``state`` attribute holds the final interpreter state (axes,
648
- symbol_table, translation, rotation, string_table, g_groups, feed, tool,
685
+ symbol_table, translation, rotation, axis_scale, string_table, g_groups, feed, tool,
649
686
  transformation, fgroup, fgref), like
650
687
  the iterator returned by :func:`nc_to_rows`.
651
688
  """
652
689
 
653
- def __init__(self, inner: Any) -> None:
690
+ def __init__(self, inner: Any, xyz_in_g500: bool) -> None:
654
691
  self._inner = inner
692
+ self._xyz_in_g500 = xyz_in_g500
655
693
 
656
694
  def __iter__(self) -> "Iterator[pl.DataFrame]":
657
695
  return self
658
696
 
659
697
  def __next__(self) -> pl.DataFrame:
660
- return _batch_frame(next(self._inner))
698
+ return _batch_frame(next(self._inner), self._xyz_in_g500)
661
699
 
662
700
  @property
663
701
  def state(self) -> dict | None:
@@ -708,6 +746,7 @@ def nc_to_batches(
708
746
  required_subprograms: "Iterable[str] | None" = None,
709
747
  stop_on_setal: bool = False,
710
748
  include_frame: bool = False,
749
+ work_offsets: dict[str, list[float]] | None = None,
711
750
  ) -> _BatchIterator:
712
751
  """Interpret an NC program into a stream of columnar polars DataFrames.
713
752
 
@@ -725,7 +764,10 @@ def nc_to_batches(
725
764
  with ``how="diagonal"`` and select the final column order.
726
765
 
727
766
  The returned iterator exposes a ``state`` attribute holding the final
728
- interpreter state once it is exhausted, like :func:`nc_to_rows`.
767
+ interpreter state once it is exhausted, like :func:`nc_to_rows`. With
768
+ ``work_offsets`` its translation and rotation are the programmable frame
769
+ relative to the selected offset, while the ``frame_*`` columns hold the
770
+ offset times the programmable frame.
729
771
  ``definitions``, ``variables`` and ``start`` work as in
730
772
  :func:`nc_to_dataframe`.
731
773
 
@@ -776,5 +818,6 @@ def nc_to_batches(
776
818
  None if required_subprograms is None else list(required_subprograms),
777
819
  stop_on_setal,
778
820
  include_frame=include_frame,
821
+ work_offsets=work_offsets,
779
822
  )
780
- return _BatchIterator(inner)
823
+ return _BatchIterator(inner, work_offsets is not None)
@@ -62,11 +62,12 @@ def nc_to_batches(
62
62
  stop_on_setal: bool = False,
63
63
  defer_rows: bool = False,
64
64
  include_frame: bool = False,
65
+ work_offsets: dict[str, list[float]] | None = None,
65
66
  ) -> Any:
66
67
  """Interpret an NC program into an iterator of columnar polars DataFrames.
67
68
 
68
69
  The returned iterator exposes ``state`` (dict with ``axes``,
69
- ``symbol_table``, ``translation``, ``rotation``, ``string_table``,
70
+ ``symbol_table``, ``translation``, ``rotation``, ``axis_scale``, ``string_table``,
70
71
  ``g_groups``, ``feed``, ``tool``, ``transformation``, ``fgroup`` and
71
72
  ``fgref``) once
72
73
  exhausted, and
@@ -139,7 +139,7 @@ def test_string_table_round_trips_through_state_dict():
139
139
  assert state["string_table"] == {"MSG": "HELLO WORLD", "TAG": "ABC"}
140
140
  # The existing numeric sub-tables are untouched by the new key.
141
141
  assert set(state) == {
142
- "axes", "symbol_table", "translation", "rotation", "string_table", "g_groups", "feed",
142
+ "axes", "symbol_table", "translation", "rotation", "axis_scale", "string_table", "g_groups", "feed",
143
143
  "tool", "transformation", "fgroup", "fgref",
144
144
  }
145
145
  # The string variable never leaks into the numeric symbol table.
@@ -0,0 +1,244 @@
1
+ """Programmable scaling, mirroring and solid-angle rotation.
2
+
3
+ Conventions under test (NC programming manual 3.12.2.5 to 3.12.2.7, Basic
4
+ Functions manual 4.5.2.11): machine XYZ = L * local XYZ + t with
5
+ L = rotation * scale * mirror; SCALE and MIRROR replace the whole programmable
6
+ frame, ASCALE and AMIRROR chain onto it; an offset programmed after a scale is
7
+ scaled; AMIRROR on a mirrored axis switches the mirror off (MD10612 = 0); one
8
+ solid angle is the same rotation as ROT about that axis.
9
+ """
10
+
11
+ import math
12
+
13
+ import pytest
14
+ from nc_gcode_interpreter import nc_to_dataframe
15
+ from nc_source import nc_lines
16
+
17
+ IDENTITY = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
18
+ START = "G17 G1 X0 Y0 Z0 F1000"
19
+
20
+
21
+ @pytest.fixture(params=["0", "1"], autouse=True)
22
+ def stage1(request, monkeypatch):
23
+ monkeypatch.setenv("NC_STAGE1", request.param)
24
+
25
+
26
+ def run(*lines, **options):
27
+ return nc_to_dataframe(nc_lines(START, *lines), **options)
28
+
29
+
30
+ def xyz(df, row=-1):
31
+ return [df[axis][row] for axis in ("X", "Y", "Z")]
32
+
33
+
34
+ def flat(matrix):
35
+ return [value for row in matrix for value in row]
36
+
37
+
38
+ def test_scale_multiplies_the_programmed_coordinates():
39
+ df, state = run("SCALE X2 Y3", "G1 X1 Y1 Z1")
40
+ assert xyz(df) == pytest.approx([2.0, 3.0, 1.0])
41
+ assert state["rotation"] == [[2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 1.0]]
42
+
43
+
44
+ def test_scale_is_absolute_and_ascale_is_additive():
45
+ df, _ = run("TRANS X10", "SCALE X2", "G1 X1", "ASCALE X3", "G1 X1", "SCALE X5", "G1 X1")
46
+ # SCALE deletes the TRANS; ASCALE multiplies the factor; SCALE replaces it.
47
+ assert df["X"].to_list()[1:] == pytest.approx([2.0, 6.0, 5.0])
48
+
49
+
50
+ def test_scale_does_not_move_the_machine():
51
+ df, state = run("G1 X4 Y6", "SCALE X2 Y3", "G1 Z1")
52
+ assert xyz(df) == pytest.approx([4.0, 6.0, 1.0])
53
+ assert state["axes"]["X"] == pytest.approx(2.0)
54
+ assert state["axes"]["Y"] == pytest.approx(2.0)
55
+
56
+
57
+ def test_offset_after_a_scale_is_scaled():
58
+ # Manual 3.12.2.6, note "Work offset after scaling".
59
+ df, state = run("TRANS X10", "ASCALE X2", "ATRANS X5", "G1 X1")
60
+ assert df["X"][-1] == pytest.approx(10.0 + 2.0 * (5.0 + 1.0))
61
+ assert state["translation"]["X"] == pytest.approx(20.0)
62
+
63
+
64
+ def test_manual_example_offset_rotation_and_scale():
65
+ # Manual 3.12.2.6 example 2: TRANS X40 Y20, AROT RPL=35, ASCALE X0.7 Y0.7.
66
+ df, _ = run("TRANS X40 Y20", "AROT RPL=35", "ASCALE X0.7 Y0.7", "G1 X10 Y5")
67
+ c, s = math.cos(math.radians(35)), math.sin(math.radians(35))
68
+ assert xyz(df)[:2] == pytest.approx([40 + 0.7 * (10 * c - 5 * s), 20 + 0.7 * (10 * s + 5 * c)])
69
+
70
+
71
+ def test_rotation_after_equal_factors_is_accepted():
72
+ df, _ = run("SCALE X2 Y2", "AROT Z90", "G1 X1 Y0")
73
+ assert xyz(df)[:2] == pytest.approx([0.0, 2.0], abs=1e-12)
74
+
75
+
76
+ @pytest.mark.parametrize("block", ["SCALE X0", "SCALE X-1", "ASCALE Y0"])
77
+ def test_scale_factor_must_be_positive(block):
78
+ with pytest.raises(ValueError, match="must be greater than 0"):
79
+ run(block, "G1 X1")
80
+
81
+
82
+ def test_mirror_reverses_the_programmed_axis():
83
+ df, state = run("MIRROR X0", "G1 X1 Y2 Z3")
84
+ assert xyz(df) == pytest.approx([-1.0, 2.0, 3.0])
85
+ assert state["rotation"] == [[-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]]
86
+
87
+
88
+ def test_mirror_value_is_not_evaluated():
89
+ df, _ = run("MIRROR X1 Y=5", "G1 X1 Y2")
90
+ assert xyz(df)[:2] == pytest.approx([-1.0, -2.0])
91
+
92
+
93
+ def test_manual_example_four_mirrored_contours():
94
+ # Manual 3.12.2.7 example 1: MIRROR X0, AMIRROR Y0, MIRROR Y0, MIRROR.
95
+ df, state = run(
96
+ "G1 X1 Y2", "MIRROR X0", "G1 X1 Y2", "AMIRROR Y0", "G1 X1 Y2", "MIRROR Y0", "G1 X1 Y2", "MIRROR", "G1 X1 Y2"
97
+ )
98
+ points = list(zip(df["X"].to_list()[1:], df["Y"].to_list()[1:], strict=True))
99
+ assert points == [(1.0, 2.0), (-1.0, 2.0), (-1.0, -2.0), (1.0, -2.0), (1.0, 2.0)]
100
+ assert state["rotation"] == IDENTITY
101
+
102
+
103
+ def test_second_amirror_switches_the_mirror_off():
104
+ df, state = run("MIRROR X0", "AMIRROR X0", "G1 X1")
105
+ assert df["X"][-1] == pytest.approx(1.0)
106
+ assert state["rotation"] == IDENTITY
107
+
108
+
109
+ def test_manual_example_mirror_then_offset():
110
+ # Manual 3.12.2.7 example 2: TRANS X0 Z600, AMIRROR Z0, ATRANS Z120.
111
+ df, _ = run("TRANS X0 Z600", "AMIRROR Z0", "ATRANS Z120", "G1 Z10")
112
+ assert df["Z"][-1] == pytest.approx(600.0 - 120.0 - 10.0)
113
+
114
+
115
+ def test_rotation_after_a_mirror_turns_the_other_way():
116
+ # Manual 3.12.2.7, note on AROT after MIRROR: Mx * Rz(a) = Rz(-a) * Mx.
117
+ mirrored_first, _ = run("MIRROR X0", "AROT Z30", "G1 X1 Y2 Z3")
118
+ rotated_first, _ = run("ROT Z-30", "AMIRROR X0", "G1 X1 Y2 Z3")
119
+ assert xyz(mirrored_first) == pytest.approx(xyz(rotated_first), abs=1e-12)
120
+ same_sign, _ = run("ROT Z30", "AMIRROR X0", "G1 X1 Y2 Z3")
121
+ assert xyz(mirrored_first) != pytest.approx(xyz(same_sign), abs=1e-6)
122
+
123
+
124
+ @pytest.mark.parametrize("op", ["ROTS", "CROTS"])
125
+ @pytest.mark.parametrize("word", ["X30", "Y-40", "Z=25"])
126
+ def test_one_solid_angle_equals_rot(op, word):
127
+ solid, state = run("TRANS X10", f"{op} {word}", "G1 X1 Y2 Z3")
128
+ plain, expected = run("TRANS X10", f"ROT {word}", "G1 X1 Y2 Z3")
129
+ assert xyz(solid) == pytest.approx(xyz(plain), abs=1e-12)
130
+ assert flat(state["rotation"]) == pytest.approx(flat(expected["rotation"]), abs=1e-12)
131
+
132
+
133
+ def test_arots_chains_onto_the_frame():
134
+ solid, _ = run("TRANS X10", "AROT Z20", "AROTS X30", "G1 X1 Y2 Z3")
135
+ plain, _ = run("TRANS X10", "AROT Z20", "AROT X30", "G1 X1 Y2 Z3")
136
+ assert xyz(solid) == pytest.approx(xyz(plain), abs=1e-12)
137
+
138
+
139
+ def test_three_solid_angles_are_rejected():
140
+ with pytest.raises(ValueError, match="at most two solid angles"):
141
+ run("ROTS X10 Y10 Z10", "G1 X1")
142
+
143
+
144
+ @pytest.mark.parametrize("block", ["ASCALE", "AMIRROR", "AROTS"])
145
+ def test_bare_additive_instruction_keeps_the_frame(block):
146
+ df, _ = run("TRANS X10", block, "G1 X5")
147
+ assert df["X"][-1] == pytest.approx(15.0)
148
+
149
+
150
+ @pytest.mark.parametrize("block", ["SCALE", "MIRROR", "ROTS", "CROTS"])
151
+ def test_bare_absolute_instruction_deletes_the_frame(block):
152
+ df, state = run("TRANS X10", "ASCALE X2", block, "G1 X5")
153
+ assert df["X"][-1] == pytest.approx(5.0)
154
+ assert state["rotation"] == IDENTITY
155
+
156
+
157
+ def test_combined_chain_matches_the_composed_matrices():
158
+ df, state = run("TRANS X10 Y20", "AROT Z90", "ASCALE X2 Y2 Z3", "AMIRROR Y0", "ATRANS X1 Y1 Z1", "G1 X1 Y1 Z1")
159
+ # L = Rz(90) * diag(2, 2, 3) * diag(1, -1, 1), t = (10, 20, 0) + L * (1, 1, 1).
160
+ assert flat(state["rotation"]) == pytest.approx([0, 2, 0, 2, 0, 0, 0, 0, 3], abs=1e-12)
161
+ assert xyz(df) == pytest.approx([10 + 2 * 2, 20 + 2 * 2, 3 * 2], abs=1e-12)
162
+
163
+
164
+ def test_frame_columns_hold_scale_and_mirror():
165
+ df, _ = run("SCALE X2", "AMIRROR Y0", "G1 X1 Y1", include_frame=True)
166
+ row = df.row(-1, named=True)
167
+ assert [row["frame_r11"], row["frame_r22"], row["frame_r33"]] == [2.0, -1.0, 1.0]
168
+
169
+
170
+ def test_final_state_with_scale_and_mirror_resumes():
171
+ _, state = run("TRANS X10", "ASCALE X2", "AMIRROR Y0", "G1 X1 Y1")
172
+ df, _ = nc_to_dataframe("G1 X3 Y3", start=state)
173
+ assert (df["X"][-1], df["Y"][-1]) == pytest.approx((16.0, -3.0))
174
+
175
+
176
+ def test_arc_under_a_uniform_scale_scales_centre_and_radius():
177
+ df, _ = run("SCALE X2 Y2", "G1 X1 Y0", "G2 X3 Y0 I1 J0", "G2 X5 Y0 CR=1")
178
+ assert (df["I"][-2], df["J"][-2]) == pytest.approx((2.0, 0.0))
179
+ assert df["X"][-2] == pytest.approx(6.0)
180
+ assert df["CR"][-1] == pytest.approx(2.0)
181
+
182
+
183
+ @pytest.mark.parametrize(
184
+ "frame",
185
+ ["SCALE X2", "SCALE X2 Y3", "MIRROR X0", "MIRROR Y0"],
186
+ )
187
+ def test_arc_under_a_distorting_or_mirroring_frame_errors(frame):
188
+ with pytest.raises(ValueError, match="tilts, mirrors or unevenly scales the G17 plane"):
189
+ run(frame, "G1 X1 Y0", "G2 X3 Y0 I1 J0")
190
+
191
+
192
+ def test_arc_ignores_scale_and_mirror_of_the_plane_normal():
193
+ df, _ = run("SCALE Z3", "AMIRROR Z0", "G1 X1 Y0 Z1", "G2 X3 Y0 I1 J0")
194
+ assert (df["X"][-1], df["I"][-1], df["Z"][-1]) == pytest.approx((3.0, 1.0, -3.0))
195
+
196
+
197
+ def test_scaled_square_program():
198
+ # Manual 3.12.2.6: the contour is enlarged by the factors of the programmed axes.
199
+ square = ["G1 X10 Y0", "G1 X10 Y10", "G1 X0 Y10", "G1 X0 Y0"]
200
+ df, _ = run("TRANS X5 Y5", "ASCALE X2 Y2", *square)
201
+ points = list(zip(df["X"].to_list()[-4:], df["Y"].to_list()[-4:], strict=True))
202
+ assert points == [(25, 5), (25, 25), (5, 25), (5, 5)]
203
+
204
+
205
+ def test_scale_applies_to_a_non_geometry_axis():
206
+ # Manual 3.12.2.6 scales all path, synchronized and positioning axes, not only X, Y, Z.
207
+ df, state = run("G1 E0", "SCALE E1.5", "G1 X1 E10", "G1 E=IC(2)", "G1 E4")
208
+ assert df["E"].to_list()[-3:] == pytest.approx([15.0, 18.0, 6.0])
209
+ assert df["X"][-3] == pytest.approx(1.0)
210
+ assert state["axes"]["E"] == pytest.approx(4.0)
211
+
212
+
213
+ def test_ascale_multiplies_and_bare_scale_resets_a_non_geometry_axis():
214
+ df, _ = run("SCALE E2", "G1 E1", "ASCALE E3", "G1 E1", "SCALE", "G1 E1")
215
+ assert df["E"].to_list()[-3:] == pytest.approx([2.0, 6.0, 1.0])
216
+
217
+
218
+ def test_offset_after_a_scale_is_scaled_on_a_non_geometry_axis():
219
+ df, state = run("TRANS E10", "ASCALE E2", "ATRANS E5", "G1 E1")
220
+ assert df["E"][-1] == pytest.approx(10.0 + 2.0 * (5.0 + 1.0))
221
+ assert state["translation"]["E"] == pytest.approx(20.0)
222
+
223
+
224
+ def test_scale_does_not_move_a_non_geometry_axis():
225
+ df, state = run("G1 E6", "SCALE E2", "G1 X1")
226
+ assert df["E"][-1] == pytest.approx(6.0)
227
+ assert state["axes"]["E"] == pytest.approx(3.0)
228
+
229
+
230
+ def test_scale_of_an_unknown_axis_errors():
231
+ with pytest.raises(ValueError, match="not a configured axis"):
232
+ run("SCALE ELX=2", "G1 X1")
233
+
234
+
235
+ def test_final_state_with_a_non_geometry_scale_resumes():
236
+ _, state = run("TRANS E1", "ASCALE E2", "G1 E3")
237
+ assert state["axis_scale"] == {"E": pytest.approx(2.0)}
238
+ df, _ = nc_to_dataframe("G1 E4", start=state)
239
+ assert df["E"][-1] == pytest.approx(9.0)
240
+
241
+
242
+ def test_start_axis_scale_rejects_a_geometry_axis():
243
+ with pytest.raises(ValueError, match="start\\['rotation'\\]"):
244
+ nc_to_dataframe("G1 X1 F100", start={"axis_scale": {"X": 2.0}})
@@ -287,17 +287,17 @@ def test_cr_arc_under_an_in_plane_rotation_matches_the_baked_arc():
287
287
  def test_arc_under_a_tilting_rotation_errors(arc):
288
288
  """An arc whose plane no longer coincides with the machine plane is not
289
289
  modeled; it must fail instead of flattening a wrong arc."""
290
- with pytest.raises(ValueError, match="tilts the G17 plane"):
290
+ with pytest.raises(ValueError, match="unevenly scales the G17 plane"):
291
291
  nc_to_dataframe(nc_lines("G1 F1000 X0 Y0 Z0 F100", "AROT X30", arc))
292
292
  # A half turn keeps the plane parallel but reverses it: also unsupported.
293
- with pytest.raises(ValueError, match="tilts the G17 plane"):
293
+ with pytest.raises(ValueError, match="unevenly scales the G17 plane"):
294
294
  nc_to_dataframe(nc_lines("G1 F1000 X0 Y0 Z0 F100", "AROT Y180", arc))
295
295
 
296
296
 
297
297
  def test_arc_in_another_plane_checks_that_plane():
298
298
  # In G18 the normal is Y, so an RPL (about Y) is fine and an X tilt is not.
299
299
  nc_to_dataframe(nc_lines("G18 G1 X0 Y0 Z0 F100", "AROT RPL=30", "G2 X10 Z0 I5 K0"))
300
- with pytest.raises(ValueError, match="tilts the G18 plane"):
300
+ with pytest.raises(ValueError, match="unevenly scales the G18 plane"):
301
301
  nc_to_dataframe(nc_lines("G18 G1 X0 Y0 Z0 F100", "AROT X30", "G2 X10 Z0 I5 K0"))
302
302
 
303
303
 
@@ -49,12 +49,12 @@ def test_group_numbers_follow_the_manual() -> None:
49
49
  def test_renamed_and_added_commands_reach_their_columns() -> None:
50
50
  from nc_gcode_interpreter import nc_to_dataframe
51
51
 
52
- program = "DYNFINISH\nWALCS1\nTOROT\nTOWWCS\nG646\nCOMPPATH\nORIAXESFR\nCUT3DCP\nSPIF2\nG1 X1 F100\n"
52
+ program = "DYNFINISH\nWALCS1\nTOROTOF\nTOWWCS\nG646\nCOMPPATH\nORIAXESFR\nCUT3DCP\nSPIF2\nG1 X1 F100\n"
53
53
  df, _ = nc_to_dataframe(program)
54
54
  last = df.row(-1, named=True)
55
55
  assert last["gg59_dyn_resp_path"] == "DYNFINISH"
56
56
  assert last["gg60_area_limit"] == "WALCS1"
57
- assert last["gg53_frame_rot_tool"] == "TOROT"
57
+ assert last["gg53_frame_rot_tool"] == "TOROTOF"
58
58
  assert last["gg56_tool_wear"] == "TOWWCS"
59
59
  assert last["gg10_exact_stop_mode"] == "G646"
60
60
  assert last["gg30_nc_compress"] == "COMPPATH"
@@ -135,8 +135,8 @@ def test_start_seeds_every_entry_point():
135
135
  {"g_groups": {"gg02_wait": "G4"}},
136
136
  {"g_groups": {"motion": "G1"}},
137
137
  {"axes": {"Q": 1.0}},
138
- {"rotation": [[2, 0, 0], [0, 1, 0], [0, 0, 1]]},
139
- {"rotation": [[-1, 0, 0], [0, 1, 0], [0, 0, 1]]},
138
+ {"rotation": [[1, 1, 0], [0, 1, 0], [0, 0, 1]]},
139
+ {"rotation": [[0, 0, 0], [0, 1, 0], [0, 0, 1]]},
140
140
  ],
141
141
  )
142
142
  def test_invalid_start_values_are_errors(start):
@@ -5,25 +5,34 @@ from nc_gcode_interpreter import nc_to_dataframe
5
5
  @pytest.mark.parametrize(
6
6
  "program",
7
7
  [
8
- "MIRROR X0\nX2", # mirroring frame
9
- "AMIRROR X0\nX2", # additive mirroring frame
10
- "ROTS X30 Y10\nX2", # solid-angle rotation frame
11
- "AROTS X30\nX2", # additive solid-angle rotation frame
12
- "CROTS X30\nX2", # solid-angle rotation on the data-management frame
13
- "SCALE X2 Y2\nX2", # scaling frame
14
- "ASCALE X2 Y2\nX2", # additive scaling frame
8
+ "ROTS X30 Y10\nX2", # two solid angles: the manuals disagree on the rotation
9
+ "CROTS X30 Y10\nX2",
10
+ "MIRROR A0\nX2",
11
+ "SCALE X2\nAROT Z30\nX2", # a rotation after unequal factors shears the frame
12
+ "TOFRAME\nX2", # frame rotations that follow the tool or workpiece orientation
13
+ "TOFRAMEZ\nX2",
14
+ "TOROT\nX2",
15
+ "torotx\nX2",
16
+ "PAROT\nX2",
17
+ "G1 F100 X1 TOROT",
15
18
  ],
16
- ids=lambda p: p.splitlines()[0],
19
+ ids=lambda p: " / ".join(p.splitlines()[:-1]) or p,
17
20
  )
18
21
  def test_unsupported_statements_error_loudly(program):
19
22
  """
20
23
  Statements that would silently corrupt the output (unmodeled frame
21
24
  transformations) must raise instead of being ignored.
22
25
  """
23
- with pytest.raises(ValueError, match="not supported"):
26
+ with pytest.raises(ValueError, match=r"not supported|geometry axes X, Y, Z only"):
24
27
  nc_to_dataframe(program)
25
28
 
26
29
 
30
+ def test_switching_an_orientation_frame_off_is_accepted():
31
+ df, _state = nc_to_dataframe("TOROTOF\nPAROTOF\nX2")
32
+ assert df["gg53_frame_rot_tool"][-1] == "TOROTOF"
33
+ assert df["gg52_frame_rot_wp"][-1] == "PAROTOF"
34
+
35
+
27
36
  @pytest.mark.parametrize(
28
37
  "program",
29
38
  [