3
3
from importlib .machinery import SourceFileLoader
4
4
from importlib .util import module_from_spec , spec_from_loader
5
5
import pytest
6
+ import os
6
7
from unittest .mock import patch
7
8
from pathlib import Path
8
9
15
16
DovetailStyle ,
16
17
dovetail_split_line ,
17
18
dovetail_subpart ,
19
+ snugtail_subpart_outline ,
18
20
)
19
21
20
22
@@ -34,6 +36,22 @@ def test_direct_run(self):
34
36
module_from_spec (spec_from_loader (loader .name , loader ))
35
37
)
36
38
39
+ def test_start_end_match (self ):
40
+ with BuildPart (mode = Mode .PRIVATE ) as test :
41
+ Box (10 , 50 , 2 , align = (Align .CENTER , Align .CENTER , Align .MIN ))
42
+ with pytest .raises (ValueError ):
43
+ x = (
44
+ dovetail_subpart (
45
+ test .part ,
46
+ Point (5 , 0 ),
47
+ Point (5 , 0 ),
48
+ # scarf_distance=0.5,
49
+ section = DovetailPart .TAIL ,
50
+ # tilt=20,
51
+ vertical_offset = - 100 ,
52
+ ),
53
+ )
54
+
37
55
def test_vertical_offset_too_high (self ):
38
56
with BuildPart (mode = Mode .PRIVATE ) as test :
39
57
Box (10 , 50 , 2 , align = (Align .CENTER , Align .CENTER , Align .MIN ))
@@ -167,3 +185,104 @@ def test_valid_vert_tail(self):
167
185
vertical_offset = 0.5 ,
168
186
),
169
187
)
188
+
189
+ @pytest .mark .manual
190
+ def test_visualize_positive_voffset_dovetail ():
191
+ from ocp_vscode import show , Camera
192
+ with BuildPart () as hanger :
193
+ Box (20 ,10 ,2 , align = [Align .CENTER , Align .MAX , Align .MIN ])
194
+ Box (20 ,200 ,2 , align = [Align .CENTER , Align .MIN , Align .MIN ])
195
+
196
+ taper = 0
197
+ scarf = - 45
198
+ voffset = .6
199
+ top = dovetail_subpart (hanger .part , Point (- 10 ,17 ), Point (10 ,17 ),
200
+ section = DovetailPart .TAIL ,
201
+ taper_angle = taper ,
202
+ scarf_angle = scarf ,vertical_offset = voffset
203
+ )
204
+ bottom = dovetail_subpart (hanger .part , Point (- 10 ,17 ), Point (10 ,17 ), section = DovetailPart .SOCKET ,
205
+ taper_angle = taper ,
206
+ scarf_angle = scarf ,vertical_offset = voffset ).move (Location ((0 , - 15 , 0 )))
207
+ show (top , bottom , reset_camera = Camera .KEEP )
208
+
209
+ @pytest .mark .manual
210
+ def test_visualize_negative_voffset_dovetail ():
211
+ from ocp_vscode import show , Camera
212
+ from build123d import BuildSketch , make_face , Plane , Cylinder
213
+ with BuildPart (mode = Mode .PRIVATE ) as test :
214
+ Box (40 , 80 , 78.7 , align = (Align .CENTER , Align .CENTER , Align .MIN ))
215
+ with BuildPart (
216
+ Plane .XY .offset (73.6
217
+ ),
218
+ mode = Mode .SUBTRACT ,
219
+ ):
220
+ Cylinder (
221
+ 25 ,
222
+ 170 ,
223
+ rotation = (90 , 0 , 0 ),
224
+ )
225
+
226
+ tl = dovetail_subpart (
227
+ test .part ,
228
+ Point (- 20 , 0 ),
229
+ Point (20 , 0 ),
230
+ section = DovetailPart .TAIL ,
231
+ tolerance = .075 ,
232
+ vertical_tolerance = 0.2 ,
233
+ taper_angle = 2 ,
234
+ scarf_angle = 20 ,
235
+ vertical_offset = - 14.33333 ,
236
+ click_fit_radius = .75
237
+ ).move (Location ((0 , 0 , 0 )))
238
+ sckt = dovetail_subpart (
239
+ test .part ,
240
+ Point (- 20 , 0 ),
241
+ Point (20 , 0 ),
242
+ section = DovetailPart .SOCKET ,
243
+ tolerance = .075 ,
244
+ vertical_tolerance = 0.2 ,
245
+ taper_angle = 2 ,
246
+ scarf_angle = 20 ,
247
+ vertical_offset = - 14.33333 ,
248
+ click_fit_radius = .75
249
+ )
250
+ sckt .color = (0.5 , 0.5 , 0.5 )
251
+ splines = snugtail_subpart_outline (
252
+ test .part ,
253
+ Point (- 25 , 0 ),
254
+ Point (25 , 0 ),
255
+ section = DovetailPart .SOCKET ,
256
+ taper_distance = 0 ,
257
+ # scarf_angle=20,
258
+ straighten_dovetail = True ,
259
+ )
260
+ spline = snugtail_subpart_outline (
261
+ test .part ,
262
+ Point (- 25 , 0 ),
263
+ Point (25 , 0 ),
264
+ section = DovetailPart .TAIL ,
265
+ taper_distance = 0 ,
266
+ # scarf_angle=20,
267
+ straighten_dovetail = True ,
268
+ )
269
+ with BuildSketch () as sks :
270
+ add (splines )
271
+ make_face ()
272
+ with BuildSketch () as sk :
273
+ add (spline )
274
+ make_face ()
275
+ from build123d import export_stl
276
+
277
+ show (
278
+ tl ,
279
+ sckt ,
280
+ # sk,
281
+ # sks,
282
+ # spline,
283
+ # splines,
284
+ reset_camera = Camera .KEEP ,
285
+ )
286
+
287
+ if __name__ == "__main__" :
288
+ test_visualize_positive_voffset_dovetail ()
0 commit comments