FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SimpleCADAPI/test/test_surface_api.py at master · PhySpace/SimpleCADAPI · GitHub
PhySpace
/
SimpleCADAPI
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
128
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SimpleCADAPI
/
test
/
test_surface_api.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
774 lines (679 loc) · 31.1 KB
Breadcrumbs
SimpleCADAPI
/
test
/
test_surface_api.py
Copy path
File metadata and controls
774 lines (679 loc) · 31.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
from
__future__
import
annotations
import
json
import
math
import
unittest
from
copy
import
deepcopy
from
unittest
import
mock
import
simplecadapi
as
scad
from
OCP
.
BRepAdaptor
import
BRepAdaptor_Surface
from
OCP
.
GeomAbs
import
GeomAbs_Cylinder
class
TestSurfaceApi
(
unittest
.
TestCase
):
@
staticmethod
def
_line_wire
(
start
,
end
):
return
scad
.
make_wire_from_edges_rwire
([
scad
.
make_line_redge
(
start
,
end
)])
def
test_public_surface_namespace_and_basic_faces
(
self
):
self
.
assertIs
(
scad
.
surface
.
make_bezier_surface_rface
,
scad
.
make_bezier_surface_rface
)
self
.
assertIs
(
scad
.
surface
.
make_cylindrical_surface_rface
,
scad
.
make_cylindrical_surface_rface
,
)
self
.
assertIs
(
scad
.
surface
.
make_solid_from_shell_rsolid
,
scad
.
make_solid_from_shell_rsolid
,
)
self
.
assertIs
(
scad
.
surface
.
SurfaceBoundary
,
scad
.
SurfaceBoundary
)
bezier
=
scad
.
make_bezier_surface_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
0
)]]
)
fitted
=
scad
.
fit_point_grid_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
0
)]],
degree_min
=
1
,
degree_max
=
3
,
)
self
.
assertIsInstance
(
bezier
,
scad
.
Face
)
self
.
assertIsInstance
(
fitted
,
scad
.
Face
)
self
.
assertAlmostEqual
(
bezier
.
get_area
(),
1.0
,
places
=
6
)
self
.
assertAlmostEqual
(
fitted
.
get_area
(),
1.0
,
places
=
6
)
def
test_cylindrical_surface_periodic_trim_and_replay
(
self
):
def
point
(
angle
,
z
):
return
(
2.0
*
math
.
cos
(
angle
),
2.0
*
math
.
sin
(
angle
),
z
)
with
scad
.
GraphSession
()
as
session
:
carrier
=
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
2.0
*
math
.
pi
),
(
0.0
,
2.0
),
tag_prefix
=
"carrier"
,
)
edges
=
[
scad
.
make_three_point_arc_redge
(
point
(
0.5
,
0.0
),
point
(
1.5
,
0.0
),
point
(
2.5
,
0.0
)
),
scad
.
make_line_redge
(
point
(
2.5
,
0.0
),
point
(
2.5
,
2.0
)),
scad
.
make_three_point_arc_redge
(
point
(
2.5
,
2.0
),
point
(
1.5
,
2.0
),
point
(
0.5
,
2.0
)
),
scad
.
make_line_redge
(
point
(
0.5
,
2.0
),
point
(
0.5
,
0.0
)),
]
outer
=
scad
.
make_wire_from_edges_rwire
(
edges
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
outer
,
tag_prefix
=
"trimmed"
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
self
.
assertEqual
(
BRepAdaptor_Surface
(
carrier
.
wrapped
).
GetType
(),
GeomAbs_Cylinder
)
self
.
assertEqual
(
BRepAdaptor_Surface
(
trimmed
.
wrapped
).
GetType
(),
GeomAbs_Cylinder
)
self
.
assertAlmostEqual
(
carrier
.
get_area
(),
8.0
*
math
.
pi
,
places
=
6
)
self
.
assertAlmostEqual
(
trimmed
.
get_area
(),
8.0
,
places
=
5
)
self
.
assertAlmostEqual
(
replayed
.
get_area
(),
trimmed
.
get_area
(),
places
=
7
)
self
.
assertIn
(
"trimmed.face"
,
scad
.
list_tags
(
replayed
))
def
test_cylindrical_surface_rejects_kernel_degenerate_spans
(
self
):
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"u_range"
):
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
1.0001e-12
),
(
0.0
,
2.0
),
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"v_range"
):
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
1.0
),
(
0.0
,
1.0e-8
),
)
def
test_cylindrical_surface_uses_radians_and_model_length_units
(
self
):
carrier
=
scad
.
make_cylindrical_surface_rface
(
scad
.
var
(
"radius"
,
0.2
,
unit
=
"cm"
),
(
0.0
,
scad
.
var
(
"u_max"
,
math
.
pi
,
unit
=
"1"
)),
(
scad
.
var
(
"v_min"
,
0.0
,
unit
=
"cm"
),
scad
.
var
(
"v_max"
,
0.2
,
unit
=
"cm"
),
),
tolerance
=
scad
.
var
(
"surface_tol"
,
0.001
,
unit
=
"mm"
),
)
self
.
assertAlmostEqual
(
carrier
.
get_area
(),
4.0
*
math
.
pi
,
places
=
6
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"unitless raw radians"
):
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
scad
.
var
(
"u_max"
,
math
.
pi
,
unit
=
"rad"
)),
(
0.0
,
2.0
),
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"tolerance must use model length"
):
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
math
.
pi
),
(
0.0
,
2.0
),
tolerance
=
scad
.
var
(
"angular_tol"
,
0.001
,
unit
=
"rad"
),
)
def
test_periodic_trim_rejects_wire_outside_partial_carrier
(
self
):
def
point
(
angle
,
z
):
return
(
2.0
*
math
.
cos
(
angle
),
2.0
*
math
.
sin
(
angle
),
z
)
carrier
=
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
1.0
),
(
0.0
,
2.0
),
)
outer
=
scad
.
make_wire_from_edges_rwire
(
[
scad
.
make_three_point_arc_redge
(
point
(
2.0
,
0.0
),
point
(
2.25
,
0.0
),
point
(
2.5
,
0.0
)
),
scad
.
make_line_redge
(
point
(
2.5
,
0.0
),
point
(
2.5
,
2.0
)),
scad
.
make_three_point_arc_redge
(
point
(
2.5
,
2.0
),
point
(
2.25
,
2.0
),
point
(
2.0
,
2.0
)
),
scad
.
make_line_redge
(
point
(
2.0
,
2.0
),
point
(
2.0
,
0.0
)),
]
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"bounded carrier"
):
scad
.
trim_surface_rface
(
carrier
,
outer
)
def
test_periodic_trim_rejects_holes_explicitly
(
self
):
carrier
=
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
2.0
*
math
.
pi
),
(
0.0
,
2.0
),
)
outer
=
scad
.
make_rectangle_rwire
(
1.0
,
1.0
,
center
=
(
2.0
,
0.0
,
1.0
))
hole
=
scad
.
make_rectangle_rwire
(
0.25
,
0.25
,
center
=
(
2.0
,
0.0
,
1.0
))
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"holes is not supported"
):
scad
.
trim_surface_rface
(
carrier
,
outer
,
holes
=
[
hole
])
def
test_periodic_trim_rejects_loop_spanning_more_than_one_period
(
self
):
carrier
=
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
2.0
*
math
.
pi
),
(
0.0
,
2.0
),
)
outer
=
scad
.
make_wire_from_edges_rwire
(
[
scad
.
make_helix_redge
(
1.0
,
2.0
,
2.0
),
scad
.
make_line_redge
((
2.0
,
0.0
,
2.0
), (
2.0
,
0.0
,
0.0
)),
]
)
with
mock
.
patch
(
"simplecadapi.kernel.ocp_surfaces.BRepAlgoAPI_Common"
,
side_effect
=
AssertionError
(
"boolean construction must not run"
),
):
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"bounded carrier parameter domain"
,
):
scad
.
trim_surface_rface
(
carrier
,
outer
)
def
test_periodic_trim_converts_linear_tolerance_to_angular_tolerance
(
self
):
def
point
(
angle
,
z
):
return
(
100.0
*
math
.
cos
(
angle
),
100.0
*
math
.
sin
(
angle
),
z
)
carrier
=
scad
.
make_cylindrical_surface_rface
(
100.0
,
(
0.0
,
1.0
),
(
0.0
,
2.0
),
)
outer
=
scad
.
make_wire_from_edges_rwire
(
[
scad
.
make_three_point_arc_redge
(
point
(
1.05
,
0.0
),
point
(
1.075
,
0.0
),
point
(
1.10
,
0.0
)
),
scad
.
make_line_redge
(
point
(
1.10
,
0.0
),
point
(
1.10
,
2.0
)),
scad
.
make_three_point_arc_redge
(
point
(
1.10
,
2.0
),
point
(
1.075
,
2.0
),
point
(
1.05
,
2.0
)
),
scad
.
make_line_redge
(
point
(
1.05
,
2.0
),
point
(
1.05
,
0.0
)),
]
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"bounded carrier"
):
scad
.
trim_surface_rface
(
carrier
,
outer
,
tolerance
=
0.2
)
def
test_solid_from_closed_shell_replays
(
self
):
with
scad
.
GraphSession
()
as
session
:
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
shell
=
scad
.
sew_faces_rshell
(
box
.
_iter_faces
())
shell
=
scad
.
apply_tag_rselection
(
shell
,
scad
.
ql
.
faces
(),
"role.preserved_face"
,
)
source_face_tags
=
{
face
.
topo_id
for
face
in
shell
.
_iter_faces
()}
solid
=
scad
.
make_solid_from_shell_rsolid
(
shell
,
tag_prefix
=
"body"
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
self
.
assertIsInstance
(
solid
,
scad
.
Solid
)
self
.
assertAlmostEqual
(
solid
.
get_volume
(),
6.0
,
places
=
6
)
self
.
assertAlmostEqual
(
replayed
.
get_volume
(),
solid
.
get_volume
(),
places
=
7
)
self
.
assertIn
(
"body.solid"
,
scad
.
list_tags
(
replayed
))
self
.
assertEqual
(
solid
.
_get_runtime
(
"semantic.lineage.coverage"
),
"partial"
)
self
.
assertTrue
(
all
(
face
.
topo_id
in
source_face_tags
and
"role.preserved_face"
in
scad
.
list_tags
(
face
)
for
face
in
solid
.
_iter_faces
()
)
)
self
.
assertTrue
(
all
(
"role.preserved_face"
in
scad
.
list_tags
(
face
)
for
face
in
replayed
.
_iter_faces
()
)
)
def
test_trim_replays_with_semantically_tagged_inputs
(
self
):
with
scad
.
GraphSession
()
as
session
:
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
outer
=
scad
.
make_rectangle_rwire
(
4.0
,
4.0
)
carrier
=
scad
.
apply_tag
(
carrier
,
"role.trim_carrier"
)
outer
=
scad
.
apply_tag
(
outer
,
"role.trim_outer"
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
outer
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
self
.
assertAlmostEqual
(
replayed
.
get_area
(),
trimmed
.
get_area
(),
places
=
7
)
for
result
in
(
trimmed
,
replayed
):
self
.
assertEqual
(
sorted
(
witness
.
binding
.
tag
for
witness
in
result
.
_tag_lineage
),
[
"role.trim_carrier"
,
"role.trim_outer"
],
)
self
.
assertTrue
(
all
(
witness
.
coverage
==
"partial"
for
witness
in
result
.
_tag_lineage
)
)
self
.
assertEqual
(
result
.
_get_runtime
(
"semantic.lineage.coverage"
),
"partial"
)
def
test_solid_from_shell_rejects_open_shell
(
self
):
face
=
scad
.
make_bezier_surface_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
0
)]]
)
shell
=
scad
.
sew_faces_rshell
([
face
])
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"closed shell"
):
scad
.
make_solid_from_shell_rsolid
(
shell
)
def
test_shell_scoped_face_tag_replays
(
self
):
with
scad
.
GraphSession
()
as
session
:
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
shell
=
scad
.
sew_faces_rshell
(
box
.
_iter_faces
())
tagged_face
=
scad
.
apply_tag
(
shell
.
get_faces
(
0
),
"role.shell_face"
,
)
session
.
capture_result
(
value
=
tagged_face
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
self
.
assertIsInstance
(
replayed
,
scad
.
Face
)
self
.
assertIn
(
"role.shell_face"
,
scad
.
list_tags
(
replayed
))
def
test_sewing_does_not_copy_tags_with_no_lineage_policy
(
self
):
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
source
=
box
.
get_faces
(
0
)
tagged
=
scad
.
apply_tag_rselection
(
source
,
[
source
],
"role.local_only"
,
lineage_policy
=
scad
.
LineagePolicy
.
NONE
,
)
sewn
=
scad
.
sew_faces_rshell
([
tagged
])
self
.
assertNotIn
(
"role.local_only"
,
scad
.
list_tags
(
sewn
.
get_faces
(
0
)))
def
test_workplane_bezier_model_replay_preserves_geometry_and_tag
(
self
):
with
scad
.
GraphSession
()
as
session
:
with
scad
.
Workplane
(
origin
=
(
10.0
,
20.0
,
30.0
),
normal
=
(
0.0
,
1.0
,
0.0
),
x_dir
=
(
1.0
,
0.0
,
0.0
),
):
original
=
scad
.
make_bezier_surface_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
1
)]],
tag_prefix
=
"skin"
,
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
original_center
=
original
.
get_center
()
replayed_center
=
replayed
.
get_center
()
self
.
assertIsInstance
(
replayed
,
scad
.
Face
)
self
.
assertAlmostEqual
(
replayed
.
get_area
(),
original
.
get_area
(),
places
=
8
)
self
.
assertAlmostEqual
(
replayed_center
.
x
,
original_center
.
x
,
places
=
8
)
self
.
assertAlmostEqual
(
replayed_center
.
y
,
original_center
.
y
,
places
=
8
)
self
.
assertAlmostEqual
(
replayed_center
.
z
,
original_center
.
z
,
places
=
8
)
self
.
assertIn
(
"skin.face"
,
scad
.
list_tags
(
replayed
))
def
test_derived_surface_builders_and_replay
(
self
):
with
scad
.
GraphSession
()
as
session
:
profile_edges
=
[
scad
.
make_line_redge
((
0
,
0
,
0
), (
1
,
0
,
0
)),
scad
.
make_line_redge
((
0
,
1
,
0
), (
1
,
1
,
0
)),
]
guide_edges
=
[
scad
.
make_line_redge
((
0
,
0
,
0
), (
0
,
1
,
0
)),
scad
.
make_line_redge
((
1
,
0
,
0
), (
1
,
1
,
0
)),
]
gordon
=
scad
.
make_gordon_surface_rface
(
profile_edges
,
guide_edges
)
points
=
[(
0
,
0
,
1
), (
2
,
0
,
1
), (
2
,
2
,
1
), (
0
,
2
,
1
)]
edges
=
[
scad
.
make_line_redge
(
points
[
index
],
points
[(
index
+
1
)
%
4
])
for
index
in
range
(
4
)
]
patch
=
scad
.
make_surface_patch_rface
(
[
scad
.
SurfaceBoundary
(
edge
)
for
edge
in
edges
],
tag_prefix
=
"patch"
,
)
session
.
capture_result
(
value
=
[
gordon
,
patch
])
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))
self
.
assertEqual
(
len
(
replayed
),
2
)
self
.
assertAlmostEqual
(
replayed
[
0
].
get_area
(),
gordon
.
get_area
(),
places
=
7
)
self
.
assertAlmostEqual
(
replayed
[
1
].
get_area
(),
patch
.
get_area
(),
places
=
7
)
self
.
assertEqual
(
len
(
replayed
[
1
].
_iter_edges
()),
4
)
self
.
assertIn
(
"patch.face"
,
scad
.
list_tags
(
replayed
[
1
]))
def
test_trim_surface_with_hole_and_replay
(
self
):
with
scad
.
GraphSession
()
as
session
:
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
outer
=
scad
.
make_rectangle_rwire
(
4.0
,
4.0
)
hole
=
scad
.
make_rectangle_rwire
(
1.0
,
1.0
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
outer
,
holes
=
[
hole
],
tag_prefix
=
"trimmed"
,
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))[
0
]
self
.
assertIsInstance
(
trimmed
,
scad
.
Face
)
self
.
assertAlmostEqual
(
trimmed
.
get_area
(),
15.0
,
places
=
6
)
self
.
assertAlmostEqual
(
replayed
.
get_area
(),
trimmed
.
get_area
(),
places
=
7
)
self
.
assertEqual
(
len
(
trimmed
.
_iter_wires
()),
2
)
self
.
assertIn
(
"trimmed.face"
,
scad
.
list_tags
(
replayed
))
def
test_trim_preserves_existing_carrier_holes
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
bounded
=
scad
.
trim_surface_rface
(
carrier
,
scad
.
make_rectangle_rwire
(
4.0
,
4.0
),
holes
=
[
scad
.
make_rectangle_rwire
(
2.0
,
2.0
)],
)
trimmed
=
scad
.
trim_surface_rface
(
bounded
,
scad
.
make_rectangle_rwire
(
3.0
,
3.0
),
)
self
.
assertAlmostEqual
(
trimmed
.
get_area
(),
5.0
,
places
=
6
)
self
.
assertEqual
(
len
(
trimmed
.
_iter_inner_wires
()),
1
)
def
test_trim_intersects_partially_overlapping_planar_loop
(
self
):
backing
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
carrier
=
scad
.
trim_surface_rface
(
backing
,
scad
.
make_rectangle_rwire
(
4.0
,
4.0
),
)
# 2(x) x 4(y) loop poking out on +x: same footprint the test has
# always exercised; the dims read (4, 2) under the pre-fix transposed
# plane basis, (2, 4) under the width-along-x convention.
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
scad
.
make_rectangle_rwire
(
2.0
,
4.0
,
center
=
(
1.5
,
0.0
,
0.0
)),
)
self
.
assertAlmostEqual
(
trimmed
.
get_area
(),
6.0
,
places
=
6
)
def
test_trim_rejects_empty_and_disconnected_carrier_intersections
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
4
,
-
4
,
0
), (
-
4
,
4
,
0
)], [(
4
,
-
4
,
0
), (
4
,
4
,
0
)]]
)
bounded
=
scad
.
trim_surface_rface
(
carrier
,
scad
.
make_rectangle_rwire
(
6.0
,
6.0
),
holes
=
[
scad
.
make_rectangle_rwire
(
2.0
,
4.0
)],
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"exactly one connected Face; intersection is empty"
,
):
scad
.
trim_surface_rface
(
bounded
,
scad
.
make_rectangle_rwire
(
1.0
,
1.0
))
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"exactly one connected Face; intersection produced 2 disconnected Faces"
,
):
scad
.
trim_surface_rface
(
bounded
,
scad
.
make_rectangle_rwire
(
4.0
,
2.0
))
def
test_trim_accepts_closed_near_tolerance_oscillating_loop
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
tolerance
=
1.0e-6
outer
=
scad
.
make_interpolated_spline_rwire
(
points
=
[
(
2.0
*
math
.
cos
(
2.0
*
math
.
pi
*
index
/
64.0
),
2.0
*
math
.
sin
(
2.0
*
math
.
pi
*
index
/
64.0
),
0.75
*
tolerance
*
math
.
sin
(
16.0
*
math
.
pi
*
index
/
32.0
),
)
for
index
in
range
(
64
)
],
periodic
=
True
,
tolerance
=
1.0e-9
,
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
outer
,
tolerance
=
tolerance
)
self
.
assertIsInstance
(
trimmed
,
scad
.
Face
)
self
.
assertEqual
(
len
(
trimmed
.
_iter_wires
()),
1
)
def
test_trim_rejects_closed_oscillating_curve_between_coarse_samples
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
outer
=
scad
.
make_interpolated_spline_rwire
(
points
=
[
(
2.0
*
math
.
cos
(
2.0
*
math
.
pi
*
index
/
64.0
),
2.0
*
math
.
sin
(
2.0
*
math
.
pi
*
index
/
64.0
),
0.5
if
index
%
2
else
0.0
,
)
for
index
in
range
(
64
)
],
periodic
=
True
,
tolerance
=
1.0e-9
,
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"deviates from the carrier"
):
scad
.
trim_surface_rface
(
carrier
,
outer
,
tolerance
=
1.0e-9
)
def
test_trim_rejects_open_and_self_intersecting_boundaries
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
open_wire
=
self
.
_line_wire
((
-
1.0
,
0.0
,
0.0
), (
1.0
,
0.0
,
0.0
))
self_intersecting
=
scad
.
make_polyline_rwire
(
[
(
-
2.0
,
-
2.0
,
0.0
),
(
2.0
,
2.0
,
0.0
),
(
-
2.0
,
2.0
,
0.0
),
(
2.0
,
-
2.0
,
0.0
),
],
closed
=
True
,
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"must be closed"
):
scad
.
trim_surface_rface
(
carrier
,
open_wire
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"must be simple"
):
scad
.
trim_surface_rface
(
carrier
,
self_intersecting
)
def
test_trim_surface_rejects_off_carrier_wire
(
self
):
carrier
=
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
)
outer
=
scad
.
make_rectangle_rwire
(
4.0
,
4.0
,
center
=
(
0
,
0
,
1
))
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"trim"
):
scad
.
trim_surface_rface
(
carrier
,
outer
)
def
test_shell_loft_roles_names_point_profiles_and_replay
(
self
):
with
scad
.
GraphSession
()
as
session
:
lower
=
scad
.
make_circle_rwire
((
0
,
0
,
0
),
2.0
)
upper
=
scad
.
make_circle_rwire
((
0
,
0
,
2
),
1.0
)
open_shell
=
scad
.
loft_rshell
(
[
lower
,
upper
],
tag_prefix
=
"skin"
,
result_tag
=
"part.skin"
,
start_wire_tag
=
"anchor.inlet"
,
end_wire_tag
=
"anchor.outlet"
,
side_faces_tag
=
"group.side"
,
)
session
.
capture_result
(
value
=
open_shell
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
),
strict
=
True
)[
0
]
self
.
assertIsInstance
(
replayed
,
scad
.
Shell
)
self
.
assertFalse
(
replayed
.
is_closed
())
self
.
assertEqual
(
len
(
replayed
.
_iter_wires
()),
2
)
self
.
assertEqual
(
len
(
scad
.
ql
.
wires
().
where
(
scad
.
ql
.
tag
(
"anchor.inlet"
)).
resolve
(
replayed
)),
1
,
)
self
.
assertEqual
(
len
(
scad
.
ql
.
wires
().
where
(
scad
.
ql
.
tag
(
"anchor.outlet"
)).
resolve
(
replayed
)),
1
,
)
self
.
assertEqual
(
len
(
scad
.
ql
.
faces
().
where
(
scad
.
ql
.
tag
(
"group.side"
)).
resolve
(
replayed
)),
1
,
)
self
.
assertIn
(
"part.skin"
,
scad
.
list_tags
(
replayed
))
self
.
assertIn
(
"skin.shell"
,
scad
.
list_tags
(
replayed
))
point
=
scad
.
make_point_rvertex
(
0
,
0
,
4
)
pointed
=
scad
.
loft_rshell
([
upper
,
point
],
start_wire_tag
=
"anchor.base"
)
self
.
assertEqual
(
len
(
pointed
.
_iter_wires
()),
1
)
self
.
assertEqual
(
len
(
scad
.
ql
.
wires
().
where
(
scad
.
ql
.
tag
(
"anchor.base"
)).
resolve
(
pointed
)),
1
,
)
def
test_sew_and_free_boundary_multi_output_replay
(
self
):
with
scad
.
GraphSession
()
as
session
:
face
=
scad
.
make_bezier_surface_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
0
)]]
)
shell
=
scad
.
sew_faces_rshell
([
face
])
boundaries
=
scad
.
free_boundaries_rwirelist
(
shell
)
session
.
capture_result
(
value
=
boundaries
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
))
self
.
assertEqual
(
len
(
boundaries
),
1
)
self
.
assertEqual
(
len
(
replayed
),
1
)
original_length
=
sum
(
edge
.
get_length
()
for
edge
in
boundaries
[
0
].
_iter_edges
())
replayed_length
=
sum
(
edge
.
get_length
()
for
edge
in
replayed
[
0
].
_iter_edges
())
self
.
assertAlmostEqual
(
replayed_length
,
original_length
,
places
=
8
)
def
test_sew_shell_faces_replays_selected_face_inputs
(
self
):
with
scad
.
GraphSession
()
as
session
:
lower
=
scad
.
make_circle_rwire
((
0
,
0
,
0
),
1.0
)
upper
=
scad
.
make_circle_rwire
((
0
,
0
,
2
),
1.0
)
lofted
=
scad
.
loft_rshell
([
lower
,
upper
])
resewn
=
scad
.
sew_faces_rshell
(
lofted
.
_iter_faces
())
session
.
capture_result
(
value
=
resewn
)
payload
=
scad
.
export_model_json
(
session
)
sew_node
=
next
(
node
for
node
in
json
.
loads
(
payload
)[
"graph"
][
"nodes"
]
if
node
[
"op"
]
==
"sew_faces_rshell"
)
self
.
assertEqual
(
len
(
sew_node
[
"params"
][
"input_refs"
]),
1
)
replayed
=
scad
.
replay_model_json
(
payload
,
strict
=
True
)
self
.
assertEqual
(
len
(
replayed
),
1
)
self
.
assertIsInstance
(
replayed
[
0
],
scad
.
Shell
)
self
.
assertEqual
(
len
(
replayed
[
0
].
_iter_faces
()),
len
(
resewn
.
_iter_faces
()))
self
.
assertAlmostEqual
(
replayed
[
0
].
get_area
(),
resewn
.
get_area
(),
places
=
8
)
def
test_solidification_does_not_overwrite_existing_shell_face_refs
(
self
):
with
scad
.
GraphSession
()
as
session
:
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
shell
=
scad
.
sew_faces_rshell
(
box
.
_iter_faces
())
retained_face
=
shell
.
get_faces
(
0
)
retained_ref
=
retained_face
.
_get_runtime
(
"topo.ref"
)
scad
.
make_solid_from_shell_rsolid
(
shell
)
moved
=
scad
.
translate_shape
(
retained_face
, (
1.0
,
0.0
,
0.0
))
session
.
capture_result
(
value
=
moved
)
self
.
assertEqual
(
retained_face
.
_get_runtime
(
"topo.ref"
),
retained_ref
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
),
strict
=
True
)
self
.
assertEqual
(
len
(
replayed
),
1
)
self
.
assertIsInstance
(
replayed
[
0
],
scad
.
Face
)
def
test_solidification_isolates_cache_and_preserves_subshape_state
(
self
):
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
shell
=
scad
.
sew_faces_rshell
(
box
.
_iter_faces
())
source_face
=
shell
.
get_faces
(
0
)
scad
.
apply_tag
(
source_face
,
"role.shell_face_state"
)
source_face
.
set_metadata
(
"audit"
, {
"value"
:
1
})
source_face
.
_set_runtime
(
"audit.runtime"
, {
"value"
:
2
})
solid
=
scad
.
make_solid_from_shell_rsolid
(
shell
)
matches
=
[
face
for
face
in
solid
.
_iter_faces
()
if
face
.
wrapped
.
IsSame
(
source_face
.
wrapped
)
]
self
.
assertIsNot
(
shell
.
_topology_cache
,
solid
.
_topology_cache
)
self
.
assertEqual
(
len
(
matches
),
1
)
self
.
assertIn
(
"role.shell_face_state"
,
scad
.
list_tags
(
matches
[
0
]))
self
.
assertEqual
(
matches
[
0
].
get_metadata
(
"audit"
), {
"value"
:
1
})
self
.
assertEqual
(
matches
[
0
].
_get_runtime
(
"audit.runtime"
), {
"value"
:
2
})
def
test_solid_subshape_uses_fresh_graph_references
(
self
):
with
scad
.
GraphSession
()
as
session
:
box
=
scad
.
make_box_rsolid
(
1.0
,
2.0
,
3.0
)
shell
=
scad
.
sew_faces_rshell
(
box
.
_iter_faces
())
solid
=
scad
.
make_solid_from_shell_rsolid
(
shell
)
moved
=
scad
.
translate_shape
(
solid
.
get_faces
(
0
), (
1.0
,
0.0
,
0.0
))
session
.
capture_result
(
value
=
moved
)
replayed
=
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
),
strict
=
True
)
self
.
assertEqual
(
len
(
replayed
),
1
)
self
.
assertIsInstance
(
replayed
[
0
],
scad
.
Face
)
def
test_partial_trim_lineage_stays_partial_after_transform
(
self
):
carrier
=
scad
.
apply_tag
(
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
),
"role.trim_carrier"
,
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
scad
.
make_rectangle_rwire
(
4.0
,
4.0
),
)
moved
=
scad
.
translate_shape
(
trimmed
, (
1.0
,
0.0
,
0.0
))
self
.
assertEqual
(
moved
.
_get_runtime
(
"semantic.lineage.coverage"
),
"partial"
)
self
.
assertEqual
(
[
witness
.
binding
.
tag
for
witness
in
moved
.
_tag_lineage
],
[
"role.trim_carrier"
],
)
self
.
assertEqual
(
moved
.
_tag_lineage
[
0
].
source_topo_id
,
trimmed
.
topo_id
)
self
.
assertTrue
(
all
(
witness
.
coverage
==
"partial"
for
witness
in
moved
.
_tag_lineage
)
)
def
test_continuation_only_lineage_does_not_cross_a_trim_fragment
(
self
):
carrier
=
scad
.
apply_tag_rselection
(
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
),
scad
.
ql
.
faces
().
exactly
(
1
),
"role.continuation_only"
,
lineage_policy
=
"continuation"
,
)
moved
=
scad
.
translate_shape
(
carrier
, (
0.0
,
0.0
,
0.0
))
trimmed
=
scad
.
trim_surface_rface
(
moved
,
scad
.
make_rectangle_rwire
(
4.0
,
4.0
),
)
self
.
assertNotIn
(
"role.continuation_only"
,
[
witness
.
binding
.
tag
for
witness
in
trimmed
.
_tag_lineage
],
)
def
test_cylindrical_tolerance_expression_replays_as_a_parameter
(
self
):
with
scad
.
GraphSession
()
as
session
:
tolerance
=
scad
.
var
(
"surface_tol"
,
1.0e-6
,
unit
=
"mm"
)
carrier
=
scad
.
make_cylindrical_surface_rface
(
2.0
,
(
0.0
,
math
.
pi
),
(
0.0
,
2.0
),
tolerance
=
tolerance
,
)
session
.
capture_result
(
value
=
carrier
)
payload
=
json
.
loads
(
scad
.
export_model_json
(
session
))
node
=
next
(
item
for
item
in
payload
[
"graph"
][
"nodes"
]
if
item
[
"op"
]
==
"make_cylindrical_surface_rface"
)
self
.
assertIn
(
"tolerance"
,
node
[
"param_exprs"
])
replayed
=
scad
.
replay_model_json
(
json
.
dumps
(
payload
),
strict
=
True
)
self
.
assertEqual
(
len
(
replayed
),
1
)
def
test_lineage_none_coverage_is_not_overwritten
(
self
):
carrier
=
scad
.
apply_tag
(
scad
.
make_bezier_surface_rface
(
[[(
-
3
,
-
3
,
0
), (
-
3
,
3
,
0
)], [(
3
,
-
3
,
0
), (
3
,
3
,
0
)]]
),
"role.source"
,
)
carrier
.
_set_runtime
(
"semantic.lineage.coverage"
,
"none"
)
trimmed
=
scad
.
trim_surface_rface
(
carrier
,
scad
.
make_rectangle_rwire
(
4.0
,
4.0
),
)
self
.
assertEqual
(
trimmed
.
_get_runtime
(
"semantic.lineage.coverage"
),
"none"
)
self
.
assertEqual
(
len
(
trimmed
.
_tag_lineage
),
1
)
self
.
assertEqual
(
trimmed
.
_tag_lineage
[
0
].
coverage
,
"none"
)
def
test_closed_shell_free_boundaries_records_zero_outputs
(
self
):
with
scad
.
GraphSession
()
as
session
:
lower
=
scad
.
make_circle_rwire
((
0
,
0
,
0
),
1.0
)
upper
=
scad
.
make_circle_rwire
((
0
,
0
,
2
),
1.0
)
closed_shell
=
scad
.
fill_holes_rshell
(
scad
.
loft_rshell
([
lower
,
upper
]))
boundaries
=
scad
.
free_boundaries_rwirelist
(
closed_shell
)
node
=
session
.
graph
.
leaf_nodes
()[
0
]
self
.
assertEqual
(
boundaries
, [])
self
.
assertEqual
(
node
.
op
,
"free_boundaries_rwirelist"
)
self
.
assertEqual
(
node
.
output_count
,
0
)
self
.
assertEqual
(
scad
.
replay_model_json
(
scad
.
export_model_json
(
session
)), [])
def
test_loft_rejects_middle_points_and_missing_endpoint_topology
(
self
):
lower
=
scad
.
make_circle_rwire
((
0
,
0
,
0
),
2.0
)
middle
=
scad
.
make_point_rvertex
(
0
,
0
,
2
)
upper
=
scad
.
make_circle_rwire
((
0
,
0
,
4
),
1.0
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"only at the start or end"
):
scad
.
loft_rshell
([
lower
,
middle
,
upper
])
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"end_wire_tag requires"
):
scad
.
loft_rshell
([
lower
,
middle
],
end_wire_tag
=
"anchor.end"
)
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"end_face_tag requires"
):
scad
.
loft_rsolid
([
lower
,
middle
],
end_face_tag
=
"anchor.end"
)
def
test_strict_replay_rejects_ordered_input_ref_tampering
(
self
):
with
scad
.
GraphSession
()
as
session
:
edge_a
=
scad
.
make_line_redge
((
0
,
0
,
0
), (
1
,
0
,
0
))
edge_b
=
scad
.
make_line_redge
((
0
,
0
,
1
), (
1
,
0
,
1
))
scad
.
make_ruled_surface_rface
(
edge_a
,
edge_b
)
payload
=
json
.
loads
(
scad
.
export_model_json
(
session
))
damaged
=
deepcopy
(
payload
)
ruled_node
=
next
(
node
for
node
in
damaged
[
"graph"
][
"nodes"
]
if
node
[
"op"
]
==
"make_ruled_surface_rface"
)
ruled_node
[
"params"
][
"input_refs"
][
0
][
"output_slot"
]
=
99
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"missing output slot 99"
):
scad
.
replay_model_json
(
json
.
dumps
(
damaged
),
strict
=
True
)
def
test_invalid_surface_inputs_use_public_error_contract
(
self
):
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"rectangular finite grid"
):
scad
.
make_bezier_surface_rface
([[(
0
,
0
,
0
)]])
with
self
.
assertRaisesRegex
(
scad
.
SimpleCADError
,
"positive tolerance"
):
scad
.
fit_point_grid_rface
(
[[(
0
,
0
,
0
), (
0
,
1
,
0
)], [(
1
,
0
,
0
), (
1
,
1
,
0
)]],
tolerance
=
0.0
,
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL