@@ -71,6 +71,15 @@ def box_and_vertex():
71
71
return assy
72
72
73
73
74
+ def solve_result_check (solve_result : dict ) -> bool :
75
+ checks = [
76
+ solve_result ["status" ] == nlopt .XTOL_REACHED ,
77
+ solve_result ["cost" ] < 1e-9 ,
78
+ solve_result ["iters" ] > 0 ,
79
+ ]
80
+ return all (checks )
81
+
82
+
74
83
def test_color ():
75
84
76
85
c1 = cq .Color ("red" )
@@ -228,9 +237,7 @@ def test_constrain(simple_assy, nested_assy):
228
237
229
238
simple_assy .solve ()
230
239
231
- assert simple_assy ._solve_result ["status" ] == nlopt .XTOL_REACHED
232
- assert simple_assy ._solve_result ["cost" ] < 1e-9
233
- assert simple_assy ._solve_result ["iters" ] > 0
240
+ assert solve_result_check (simple_assy ._solve_result )
234
241
235
242
assert (
236
243
simple_assy .loc .wrapped .Transformation ()
@@ -247,9 +254,7 @@ def test_constrain(simple_assy, nested_assy):
247
254
248
255
nested_assy .solve ()
249
256
250
- assert nested_assy ._solve_result ["status" ] == nlopt .XTOL_REACHED
251
- assert nested_assy ._solve_result ["cost" ] < 1e-9
252
- assert nested_assy ._solve_result ["iters" ] > 0
257
+ assert solve_result_check (nested_assy ._solve_result )
253
258
254
259
assert (
255
260
nested_assy .children [0 ]
@@ -302,6 +307,7 @@ def test_PointInPlane_constraint(box_and_vertex):
302
307
param = 0 ,
303
308
)
304
309
box_and_vertex .solve ()
310
+ solve_result_check (box_and_vertex ._solve_result )
305
311
306
312
x_pos = (
307
313
box_and_vertex .children [0 ].loc .wrapped .Transformation ().TranslationPart ().X ()
@@ -311,6 +317,7 @@ def test_PointInPlane_constraint(box_and_vertex):
311
317
# add a second PointInPlane constraint
312
318
box_and_vertex .constrain ("vertex" , "box@faces@>Y" , "PointInPlane" , param = 0 )
313
319
box_and_vertex .solve ()
320
+ solve_result_check (box_and_vertex ._solve_result )
314
321
315
322
vertex_translation_part = (
316
323
box_and_vertex .children [0 ].loc .wrapped .Transformation ().TranslationPart ()
@@ -323,6 +330,7 @@ def test_PointInPlane_constraint(box_and_vertex):
323
330
# add a third PointInPlane constraint
324
331
box_and_vertex .constrain ("vertex" , "box@faces@>Z" , "PointInPlane" , param = 0 )
325
332
box_and_vertex .solve ()
333
+ solve_result_check (box_and_vertex ._solve_result )
326
334
327
335
# should now be on the >X and >Y and >Z corner
328
336
assert (
@@ -342,6 +350,7 @@ def test_PointInPlane_3_parts(box_and_vertex):
342
350
box_and_vertex .constrain ("vertex" , "cylinder@faces@>Z" , "PointInPlane" )
343
351
box_and_vertex .constrain ("vertex" , "box@faces@>X" , "PointInPlane" )
344
352
box_and_vertex .solve ()
353
+ solve_result_check (box_and_vertex ._solve_result )
345
354
vertex_translation_part = (
346
355
box_and_vertex .children [0 ].loc .wrapped .Transformation ().TranslationPart ()
347
356
)
@@ -356,6 +365,7 @@ def test_PointInPlane_param(box_and_vertex, param0, param1):
356
365
box_and_vertex .constrain ("vertex" , "box@faces@>Z" , "PointInPlane" , param = param0 )
357
366
box_and_vertex .constrain ("vertex" , "box@faces@>X" , "PointInPlane" , param = param1 )
358
367
box_and_vertex .solve ()
368
+ solve_result_check (box_and_vertex ._solve_result )
359
369
360
370
vertex_translation_part = (
361
371
box_and_vertex .children [0 ].loc .wrapped .Transformation ().TranslationPart ()
@@ -364,9 +374,9 @@ def test_PointInPlane_param(box_and_vertex, param0, param1):
364
374
assert vertex_translation_part .X () - 0.5 == pytest .approx (param1 , abs = 1e-6 )
365
375
366
376
367
- def test_constraint_getPlane ():
377
+ def test_constraint_getPln ():
368
378
"""
369
- Test that _getPlane does the right thing with different arguments
379
+ Test that _getPln does the right thing with different arguments
370
380
"""
371
381
ids = (0 , 1 )
372
382
sublocs = (cq .Location (), cq .Location ())
@@ -377,11 +387,19 @@ def make_constraint(shape0):
377
387
def fail_this (shape0 ):
378
388
c0 = make_constraint (shape0 )
379
389
with pytest .raises (ValueError ):
380
- c0 ._getPlane (c0 .args [0 ])
390
+ c0 ._getPln (c0 .args [0 ])
381
391
382
- def resulting_plane (shape0 ):
392
+ def resulting_pln (shape0 ):
383
393
c0 = make_constraint (shape0 )
384
- return c0 ._getPlane (c0 .args [0 ])
394
+ return c0 ._getPln (c0 .args [0 ])
395
+
396
+ def resulting_plane (shape0 ):
397
+ p0 = resulting_pln (shape0 )
398
+ return cq .Plane (
399
+ cq .Vector (p0 .Location ()),
400
+ cq .Vector (p0 .XAxis ().Direction ()),
401
+ cq .Vector (p0 .Axis ().Direction ()),
402
+ )
385
403
386
404
# point should fail
387
405
fail_this (cq .Vertex .makeVertex (0 , 0 , 0 ))
@@ -423,7 +441,7 @@ def resulting_plane(shape0):
423
441
wonky_shape = cq .Wire .makePolygon (points3 )
424
442
fail_this (wonky_shape )
425
443
426
- # all faces should succeed
444
+ # all makePlane faces should succeed
427
445
for length , width in product ([None , 10 ], [None , 11 ]):
428
446
f0 = cq .Face .makePlane (
429
447
length = length , width = width , basePnt = (1 , 2 , 3 ), dir = (1 , 0 , 0 )
@@ -482,3 +500,36 @@ def test_toCompound(simple_assy, nested_assy):
482
500
assert cq .Vector (0 , 0 , 18 ) in [x .Center () for x in c3 .Faces ()]
483
501
# also check with bounding box
484
502
assert c3 .BoundingBox ().zlen == pytest .approx (18 )
503
+
504
+
505
+ @pytest .mark .parametrize ("origin" , [(0 , 0 , 0 ), (10 , - 10 , 10 )])
506
+ @pytest .mark .parametrize ("normal" , [(0 , 0 , 1 ), (- 1 , - 1 , 1 )])
507
+ def test_infinite_face_constraint_PointInPlane (origin , normal ):
508
+ """
509
+ An OCCT infinite face has a center at (1e99, 1e99), but when a user uses it
510
+ in a constraint, the center should be basePnt.
511
+ """
512
+
513
+ f0 = cq .Face .makePlane (length = None , width = None , basePnt = origin , dir = normal )
514
+
515
+ c0 = cq .assembly .Constraint (
516
+ ("point" , "plane" ),
517
+ (cq .Vertex .makeVertex (10 , 10 , 10 ), f0 ),
518
+ sublocs = (cq .Location (), cq .Location ()),
519
+ kind = "PointInPlane" ,
520
+ )
521
+ p0 = c0 ._getPln (c0 .args [1 ]) # a gp_Pln
522
+ derived_origin = cq .Vector (p0 .Location ())
523
+ assert derived_origin == cq .Vector (origin )
524
+
525
+
526
+ @pytest .mark .parametrize ("kind" , ["Plane" , "PointInPlane" , "Point" ])
527
+ def test_infinite_face_constraint_Plane (kind ):
528
+
529
+ assy = cq .Assembly (cq .Workplane ().sphere (1 ), name = "part0" )
530
+ assy .add (cq .Workplane ().sphere (1 ), name = "part1" )
531
+ assy .constrain (
532
+ "part0" , cq .Face .makePlane (), "part1" , cq .Face .makePlane (), kind ,
533
+ )
534
+ assy .solve ()
535
+ assert solve_result_check (assy ._solve_result )
0 commit comments