41
41
)
42
42
from ansys .geometry .core .sketch .sketch import Sketch
43
43
44
- """A helper function to create a sketch line given two points and a design."""
45
-
46
44
47
45
def create_sketch_line (design : Design , p1 : Point3D , p2 : Point3D ):
46
+ """A helper function to create a sketch line given two points and a design."""
48
47
point1 = point3d_to_grpc_point (p1 )
49
48
point2 = point3d_to_grpc_point (p2 )
50
49
design ._commands_stub .CreateSketchLine (CreateSketchLineRequest (point1 = point1 , point2 = point2 ))
51
50
52
51
53
- """A helper function that creates the Hedgehog model."""
54
-
55
-
56
52
def create_hedgehog (modeler : Modeler ):
53
+ """A helper function that creates the Hedgehog model."""
57
54
design = modeler .create_design ("Hedgehog" )
58
55
sketch = Sketch ().arc_from_three_points (
59
56
Point2D ([0.01 , 0.01 ]), Point2D ([0 , - 0.005 ]), Point2D ([- 0.01 , 0.01 ])
@@ -97,19 +94,15 @@ def create_hedgehog(modeler: Modeler):
97
94
return design
98
95
99
96
100
- """A fixture of the hedgehog design to test the surface and curve properties individually."""
101
-
102
-
103
97
@pytest .fixture
104
98
def hedgehog_design (modeler : Modeler ):
99
+ """A fixture of the hedgehog design to test the surface and curve properties individually."""
105
100
h = create_hedgehog (modeler )
106
101
yield h
107
102
108
103
109
- """Tests the surface properties for the hedgehog design."""
110
-
111
-
112
104
def test_trimmed_surface_properties (hedgehog_design ):
105
+ """Tests the surface properties for the hedgehog design."""
113
106
hedgehog_body = hedgehog_design .bodies [0 ]
114
107
faces = hedgehog_body .faces
115
108
@@ -161,10 +154,8 @@ def test_trimmed_surface_properties(hedgehog_design):
161
154
assert faces [i ].shape .box_uv .interval_v == Interval (start = interval_v [0 ], end = interval_v [1 ])
162
155
163
156
164
- """Tests the normal vectors for the hedgehog design using the BoxUV coordinates."""
165
-
166
-
167
157
def test_trimmed_surface_normals (hedgehog_design ):
158
+ """Tests the normal vectors for the hedgehog design using the BoxUV coordinates."""
168
159
hedgehog_body = hedgehog_design .bodies [0 ]
169
160
faces = hedgehog_body .faces
170
161
# corners to consider
@@ -219,10 +210,8 @@ def test_trimmed_surface_normals(hedgehog_design):
219
210
assert np .allclose (faces [i ].shape .normal (corner_param .u , corner_param .v ), bottom_right )
220
211
221
212
222
- """Tests the curve properties for the hedgehog design."""
223
-
224
-
225
213
def test_trimmed_curve_properties (hedgehog_design ):
214
+ """Tests the curve properties for the hedgehog design."""
226
215
hedgehog_body = hedgehog_design .bodies [0 ]
227
216
edges = hedgehog_body .edges
228
217
@@ -245,3 +234,73 @@ def test_trimmed_curve_properties(hedgehog_design):
245
234
assert isinstance (edges [i ].shape .geometry , geometry_type )
246
235
assert np .allclose (edges [i ].shape .start , Point3D (start ))
247
236
assert np .allclose (edges [i ].shape .end , Point3D (end ))
237
+
238
+
239
+ def test_trimmed_curve_line_translate (hedgehog_design ):
240
+ """Tests the translation of a trimmed curve with line geometry."""
241
+ hedgehog_body = hedgehog_design .bodies [0 ]
242
+ edges = hedgehog_body .edges
243
+ edge = edges [1 ]
244
+ trimmed_curve = edge .shape
245
+
246
+ assert isinstance (trimmed_curve , TrimmedCurve )
247
+ assert trimmed_curve .start == Point3D ([0.01 , 0.01 , 0.0 ])
248
+ assert trimmed_curve .end == Point3D ([0.01 , 0.01 , 0.02 ])
249
+
250
+ trimmed_curve .translate (UnitVector3D ([1 , 0 , 0 ]), 0.01 )
251
+
252
+ assert trimmed_curve .start == Point3D ([0.02 , 0.01 , 0.0 ])
253
+ assert trimmed_curve .end == Point3D ([0.02 , 0.01 , 0.02 ])
254
+
255
+
256
+ def test_trimmed_curve_line_rotate (hedgehog_design ):
257
+ """Tests the rotation of a trimmed curve with line geometry."""
258
+ hedgehog_body = hedgehog_design .bodies [0 ]
259
+ edges = hedgehog_body .edges
260
+ edge = edges [1 ]
261
+ trimmed_curve = edge .shape
262
+
263
+ assert isinstance (trimmed_curve , TrimmedCurve )
264
+ assert trimmed_curve .start == Point3D ([0.01 , 0.01 , 0.0 ])
265
+ assert trimmed_curve .end == Point3D ([0.01 , 0.01 , 0.02 ])
266
+
267
+ # Rotate the curve in the x-direction by 90 degrees about the point (0.01, 0.01, 0.0)
268
+ trimmed_curve .rotate (Point3D ([0.01 , 0.01 , 0.0 ]), UnitVector3D ([1 , 0 , 0 ]), np .pi / 2 )
269
+
270
+ assert np .allclose (trimmed_curve .start , Point3D ([0.01 , 0.01 , 0.0 ]))
271
+ assert np .allclose (trimmed_curve .end , Point3D ([0.01 , - 0.01 , 0.0 ]))
272
+
273
+
274
+ def test_trimmed_curve_circle_translate (hedgehog_design ):
275
+ """Tests the rotation of a trimmed curve with circle geometry."""
276
+ hedgehog_body = hedgehog_design .bodies [0 ]
277
+ edges = hedgehog_body .edges
278
+ edge = edges [0 ]
279
+ trimmed_curve = edge .shape
280
+
281
+ assert isinstance (trimmed_curve , TrimmedCurve )
282
+ assert np .allclose (trimmed_curve .start , Point3D ([0.01 , 0.01 , 0.02 ]))
283
+ assert np .allclose (trimmed_curve .end , Point3D ([- 0.01 , 0.01 , 0.02 ]))
284
+
285
+ trimmed_curve .translate (UnitVector3D ([1 , 0 , 0 ]), 0.01 )
286
+
287
+ assert np .allclose (trimmed_curve .start , Point3D ([0.02 , 0.01 , 0.02 ]))
288
+ assert np .allclose (trimmed_curve .end , Point3D ([0.0 , 0.01 , 0.02 ]))
289
+
290
+
291
+ def test_trimmed_curve_circle_rotate (hedgehog_design ):
292
+ """Tests the rotation of a trimmed curve with circle geometry."""
293
+ hedgehog_body = hedgehog_design .bodies [0 ]
294
+ edges = hedgehog_body .edges
295
+ edge = edges [0 ]
296
+ trimmed_curve = edge .shape
297
+
298
+ assert isinstance (trimmed_curve , TrimmedCurve )
299
+ assert np .allclose (trimmed_curve .start , Point3D ([0.01 , 0.01 , 0.02 ]))
300
+ assert np .allclose (trimmed_curve .end , Point3D ([- 0.01 , 0.01 , 0.02 ]))
301
+
302
+ # Rotate the curve in the x-direction by 90 degrees about the point (0.01, 0.01, 0.02)
303
+ trimmed_curve .rotate (Point3D ([0.01 , 0.01 , 0.02 ]), UnitVector3D ([0 , 1 , 0 ]), np .pi / 2 )
304
+
305
+ assert np .allclose (trimmed_curve .start , Point3D ([0.01 , 0.01 , 0.02 ]))
306
+ assert np .allclose (trimmed_curve .end , Point3D ([0.01 , 0.01 , 0.04 ]))
0 commit comments