继续按 align-linuxcnc 约束:补极坐标源码覆盖,测试通过

This commit is contained in:
cnc
2026-06-02 22:08:26 +08:00
parent 868f20382a
commit 9c03f91fa8
11 changed files with 79 additions and 0 deletions

View File

@@ -547,6 +547,35 @@ CNC_SIM_RS274_VAR="$var_file" \
CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_arc_distance_modes.ngc \
>"$output_dir/cnc_sim_linuxcnc_source_arc_distance_modes.json"
# Source basis: LinuxCNC src/emc/rs274ngc/interp_read.cc read_atsign()
# and read_carat() parse @/^ polar words; src/emc/rs274ngc/interp_internal.cc
# enhance_block() restricts polar coordinates to G17 motion without X/Y words;
# src/emc/rs274ngc/interp_find.cc find_ends() maps absolute polar radius/angle
# to XY endpoints and rejects G53 or origin-indeterminate polar motions.
CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_polar_coordinates.ngc \
>"$output_dir/cnc_sim_linuxcnc_source_polar_coordinates.json"
polar_coordinate_error_cases=(
"linuxcnc_polar_g18_error|Cannot use polar coordinate except in G17 plane"
"linuxcnc_polar_with_x_error|Cannot specify both polar coordinate and X word"
"linuxcnc_polar_with_y_error|Cannot specify both polar coordinate and Y word"
"linuxcnc_polar_g92_error|Polar coordinates can only be used for motion"
"linuxcnc_polar_g53_error|Cannot use polar coordinates with G53"
"linuxcnc_polar_radius_origin_error|Must specify angle in polar coordinate if at the origin"
"linuxcnc_polar_incremental_radius_origin_error|Incremental motion with polar coordinates is indeterminate when at the origin"
"linuxcnc_polar_incremental_theta_origin_error|G91 motion with polar coordinates is indeterminate when at the origin"
)
for case in "${polar_coordinate_error_cases[@]}"; do
fixture=${case%%|*}
expected=${case#*|}
if CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" "tests/gcode/$fixture.ngc" \
>"$output_dir/cnc_sim_linuxcnc_source_$fixture.json" 2>"$output_dir/cnc_sim_linuxcnc_source_$fixture.err"; then
echo "expected $fixture.ngc to fail" >&2
exit 1
fi
grep -Fq "$expected" "$output_dir/cnc_sim_linuxcnc_source_$fixture.err"
done
CNC_SIM_RS274_VAR="$var_file" \
"$build_dir/linuxcnc_rs274_source_dump" tests/gcode/linuxcnc_predefined_positions.ngc \
>"$output_dir/cnc_sim_linuxcnc_source_predefined_positions.json"
@@ -2051,6 +2080,25 @@ expected_arc_centers = [(5, 5, 0), (7, 15, 0), (9, 25, 0)]
if arc_centers != expected_arc_centers:
raise SystemExit(f"unexpected source-linked G90.1/G91.1 arc centers: {arc_centers!r}")
polar_coordinates = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_polar_coordinates.json").read_text())
polar_linear_events = [
event
for event in polar_coordinates
if event["type"] == "linear-feed"
]
expected_polar_linear_ends = [(3, 10, 0), (4, 0, 10)]
if len(polar_linear_events) != len(expected_polar_linear_ends) or any(
event["line"] != line or
abs(event["end"]["x"] - x) > 1e-9 or
abs(event["end"]["y"] - y) > 1e-9
for event, (line, x, y) in zip(polar_linear_events, expected_polar_linear_ends)
):
polar_linear_ends = [
(event["line"], event["end"]["x"], event["end"]["y"])
for event in polar_linear_events
]
raise SystemExit(f"unexpected source-linked polar-coordinate endpoints: {polar_linear_ends!r}")
predefined = json.loads((OUTPUT_DIR / "cnc_sim_linuxcnc_source_predefined_positions.json").read_text())
predefined_rapids = [
(

View File

@@ -145,6 +145,8 @@ grep -F 'convert_lathe_diameter_mode() scales G7/G8 X words and G76 I/J/K words'
grep -F 'tests/gcode/linuxcnc_lathe_diameter_mode.ngc' docs/linuxcnc-porting.md >/dev/null
grep -F 'tests/gcode/linuxcnc_lathe_diameter_g76.ngc' docs/linuxcnc-porting.md >/dev/null
grep -F 'missing source-linked G7 diameter-mode G76 final threading pass' test-linuxcnc-source-link.sh >/dev/null
grep -F 'read_atsign()' test-linuxcnc-source-link.sh >/dev/null
grep -F 'tests/gcode/linuxcnc_polar_coordinates.ngc' test-linuxcnc-source-link.sh >/dev/null
grep -F 'lookup_named_param()' test-linuxcnc-rs274-native.sh >/dev/null
grep -F 'tests/gcode/linuxcnc_readonly_named_parameters.ngc' docs/linuxcnc-porting.md >/dev/null
grep -F 'rs274ngc_pre.cc ini_load() consumes INI_FILE_NAME' test-web-wasm-node-smoke.cjs >/dev/null

View File

@@ -0,0 +1,5 @@
G21 G90 G17
G0 X0 Y0 Z0
G1 @10 ^0 F100
G1 @10 ^90
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G18
G1 @10 ^45 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G17
G53 G1 @10 ^45 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G17
G92 @10 ^45
M30

View File

@@ -0,0 +1,3 @@
G21 G91 G17
G1 @10 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G91 G17
G1 ^45 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G17
G1 @10 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G17
G1 X1 @10 ^45 F100
M30

View File

@@ -0,0 +1,3 @@
G21 G90 G17
G1 Y1 @10 ^45 F100
M30