Skip to content

Commit 250346c

Browse files
Fix bad unit conversion for elliptics (#7767)
* Fix bad unit conversion for elliptics * Update snapshots * add regression test for elliptic curve using inches * Update snapshots * Update snapshots * Update snapshots * Update snapshots --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 31ada6b commit 250346c

File tree

13 files changed

+2463
-2
lines changed

13 files changed

+2463
-2
lines changed

rust/kcl-lib/src/simulation_tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,3 +3796,24 @@ mod complex_expr_as_array_index {
37963796
super::execute(TEST_NAME, true).await
37973797
}
37983798
}
3799+
mod elliptic_curve_inches_regression {
3800+
const TEST_NAME: &str = "elliptic_curve_inches_regression";
3801+
3802+
/// Test parsing KCL.
3803+
#[test]
3804+
fn parse() {
3805+
super::parse(TEST_NAME)
3806+
}
3807+
3808+
/// Test that parsing and unparsing KCL produces the original KCL input.
3809+
#[tokio::test(flavor = "multi_thread")]
3810+
async fn unparse() {
3811+
super::unparse(TEST_NAME).await
3812+
}
3813+
3814+
/// Test that KCL is executed correctly.
3815+
#[tokio::test(flavor = "multi_thread")]
3816+
async fn kcl_test_execute() {
3817+
super::execute(TEST_NAME, true).await
3818+
}
3819+
}

rust/kcl-lib/src/std/sketch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,8 +1924,8 @@ pub(crate) async fn inner_elliptic(
19241924
path: sketch.id.into(),
19251925
segment: PathSegment::Ellipse {
19261926
center: KPoint2d::from(untyped_point_to_mm(center_u, from.units)).map(LengthUnit),
1927-
major_radius: LengthUnit(from.units.adjust_to(major_radius.to_mm(), UnitLen::Mm).0),
1928-
minor_radius: LengthUnit(from.units.adjust_to(minor_radius.to_mm(), UnitLen::Mm).0),
1927+
major_radius: LengthUnit(major_radius.to_mm()),
1928+
minor_radius: LengthUnit(minor_radius.to_mm()),
19291929
start_angle,
19301930
end_angle,
19311931
},
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
---
2+
source: kcl-lib/src/simulation_tests.rs
3+
description: Artifact commands elliptic_curve_inches_regression.kcl
4+
---
5+
{
6+
"rust/kcl-lib/tests/elliptic_curve_inches_regression/input.kcl": [
7+
{
8+
"cmdId": "[uuid]",
9+
"range": [],
10+
"command": {
11+
"type": "make_plane",
12+
"origin": {
13+
"x": 0.0,
14+
"y": 0.0,
15+
"z": 0.0
16+
},
17+
"x_axis": {
18+
"x": 1.0,
19+
"y": 0.0,
20+
"z": 0.0
21+
},
22+
"y_axis": {
23+
"x": 0.0,
24+
"y": -1.0,
25+
"z": 0.0
26+
},
27+
"size": 60.0,
28+
"clobber": false,
29+
"hide": true
30+
}
31+
},
32+
{
33+
"cmdId": "[uuid]",
34+
"range": [],
35+
"command": {
36+
"type": "object_visible",
37+
"object_id": "[uuid]",
38+
"hidden": true
39+
}
40+
},
41+
{
42+
"cmdId": "[uuid]",
43+
"range": [],
44+
"command": {
45+
"type": "enable_sketch_mode",
46+
"entity_id": "[uuid]",
47+
"ortho": false,
48+
"animated": false,
49+
"adjust_camera": false,
50+
"planar_normal": {
51+
"x": 0.0,
52+
"y": 0.0,
53+
"z": -1.0
54+
}
55+
}
56+
},
57+
{
58+
"cmdId": "[uuid]",
59+
"range": [],
60+
"command": {
61+
"type": "start_path"
62+
}
63+
},
64+
{
65+
"cmdId": "[uuid]",
66+
"range": [],
67+
"command": {
68+
"type": "move_path_pen",
69+
"path": "[uuid]",
70+
"to": {
71+
"x": 2302.7323843617596,
72+
"y": 1545.7213341658817,
73+
"z": 0.0
74+
}
75+
}
76+
},
77+
{
78+
"cmdId": "[uuid]",
79+
"range": [],
80+
"command": {
81+
"type": "sketch_mode_disable"
82+
}
83+
},
84+
{
85+
"cmdId": "[uuid]",
86+
"range": [],
87+
"command": {
88+
"type": "extend_path",
89+
"path": "[uuid]",
90+
"segment": {
91+
"type": "ellipse",
92+
"center": {
93+
"x": 0.0,
94+
"y": 1545.7213433999998
95+
},
96+
"major_radius": 2302.732377,
97+
"minor_radius": 426.8591158,
98+
"start_angle": {
99+
"unit": "degrees",
100+
"value": 0.0
101+
},
102+
"end_angle": {
103+
"unit": "degrees",
104+
"value": 180.0
105+
}
106+
}
107+
}
108+
},
109+
{
110+
"cmdId": "[uuid]",
111+
"range": [],
112+
"command": {
113+
"type": "extend_path",
114+
"path": "[uuid]",
115+
"segment": {
116+
"type": "bezier",
117+
"control1": {
118+
"x": 381.18912839999996,
119+
"y": -648.6776714,
120+
"z": 0.0
121+
},
122+
"control2": {
123+
"x": 822.1615509999999,
124+
"y": -753.3404034,
125+
"z": 0.0
126+
},
127+
"end": {
128+
"x": 1275.198872,
129+
"y": -677.4812459999999,
130+
"z": 0.0
131+
},
132+
"relative": true
133+
}
134+
}
135+
},
136+
{
137+
"cmdId": "[uuid]",
138+
"range": [],
139+
"command": {
140+
"type": "extend_path",
141+
"path": "[uuid]",
142+
"segment": {
143+
"type": "bezier",
144+
"control1": {
145+
"x": 453.03732099999996,
146+
"y": 75.8591574,
147+
"z": 0.0
148+
},
149+
"control2": {
150+
"x": 918.1395658,
151+
"y": 332.24022959999996,
152+
"z": 0.0
153+
},
154+
"end": {
155+
"x": 1366.2393299999999,
156+
"y": 335.0833024,
157+
"z": 0.0
158+
},
159+
"relative": true
160+
}
161+
}
162+
},
163+
{
164+
"cmdId": "[uuid]",
165+
"range": [],
166+
"command": {
167+
"type": "extend_path",
168+
"path": "[uuid]",
169+
"segment": {
170+
"type": "bezier",
171+
"control1": {
172+
"x": 448.0997641999999,
173+
"y": 2.8430728,
174+
"z": 0.0
175+
},
176+
"control2": {
177+
"x": 879.1970732,
178+
"y": -247.85180299999996,
179+
"z": 0.0
180+
},
181+
"end": {
182+
"x": 1222.6556954,
183+
"y": -280.4740644,
184+
"z": 0.0
185+
},
186+
"relative": true
187+
}
188+
}
189+
},
190+
{
191+
"cmdId": "[uuid]",
192+
"range": [],
193+
"command": {
194+
"type": "extend_path",
195+
"path": "[uuid]",
196+
"segment": {
197+
"type": "bezier",
198+
"control1": {
199+
"x": 343.4586222,
200+
"y": -32.6222614,
201+
"z": 0.0
202+
},
203+
"control2": {
204+
"x": 599.2785576,
205+
"y": 152.8281424,
206+
"z": 0.0
207+
},
208+
"end": {
209+
"x": 741.3708566,
210+
"y": 622.8719825999999,
211+
"z": 0.0
212+
},
213+
"relative": true
214+
}
215+
}
216+
},
217+
{
218+
"cmdId": "[uuid]",
219+
"range": [],
220+
"command": {
221+
"type": "close_path",
222+
"path_id": "[uuid]"
223+
}
224+
}
225+
],
226+
"std::appearance": [],
227+
"std::array": [],
228+
"std::math": [],
229+
"std::prelude": [],
230+
"std::sketch": [],
231+
"std::solid": [],
232+
"std::sweep": [],
233+
"std::transform": [],
234+
"std::turns": [],
235+
"std::types": [],
236+
"std::units": [],
237+
"std::vector": []
238+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: kcl-lib/src/simulation_tests.rs
3+
description: Artifact graph flowchart elliptic_curve_inches_regression.kcl
4+
extension: md
5+
snapshot_kind: binary
6+
---
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```mermaid
2+
flowchart LR
3+
subgraph path2 [Path]
4+
2["Path<br>[322, 390, 0]"]
5+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 0 }]
6+
3["Segment<br>[396, 560, 0]"]
7+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 1 }]
8+
4["Segment<br>[566, 678, 0]"]
9+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 2 }]
10+
5["Segment<br>[684, 793, 0]"]
11+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 3 }]
12+
6["Segment<br>[799, 910, 0]"]
13+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 4 }]
14+
7["Segment<br>[916, 1026, 0]"]
15+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 5 }]
16+
8["Segment<br>[1032, 1039, 0]"]
17+
%% [ProgramBodyItem { index: 2 }, VariableDeclarationDeclaration, VariableDeclarationInit, PipeBodyItem { index: 6 }]
18+
9[Solid2d]
19+
end
20+
1["Plane<br>[230, 253, 0]"]
21+
%% [ProgramBodyItem { index: 1 }, VariableDeclarationDeclaration, VariableDeclarationInit]
22+
1 --- 2
23+
2 --- 3
24+
2 --- 4
25+
2 --- 5
26+
2 --- 6
27+
2 --- 7
28+
2 --- 8
29+
2 --- 9
30+
```

0 commit comments

Comments
 (0)