Skip to content

Commit 7f21c43

Browse files
committed
positive vertical_offsets were causing an issue for dovetails; addressed issue & updated testss
1 parent ea4b588 commit 7f21c43

File tree

3 files changed

+134
-9
lines changed

3 files changed

+134
-9
lines changed

pyproject.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fb-library"
3-
version = "0.0.18"
3+
version = "0.0.19"
44
authors = [
55
{ name="x0pherl"},
66
]
@@ -22,3 +22,8 @@ Documentation = "https://fb-library.readthedocs.org"
2222
requires = ["hatchling", "hatch-vcs"]
2323

2424
build-backend = "hatchling.build"
25+
26+
[tool.pytest.ini_options]
27+
markers = [
28+
"manual: marks tests that can only be executed manually",
29+
]

src/fb_library/dovetail.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545

4646
from fb_library.click_fit import divot
4747

48-
from ocp_vscode import show, Camera
49-
50-
5148
class DovetailPart(Enum):
5249
TAIL = auto()
5350
SOCKET = auto()
@@ -703,6 +700,8 @@ def dovetail_subpart(
703700
cut on one side, and provides a hard stop for fitting. A positive number results in a straight cut on the bottom
704701
of the part passed, a negagive number results in a straight cut on the top of the part passed
705702
"""
703+
if start == end:
704+
raise ValueError("start and end points cannot be the same")
706705
if abs(vertical_offset) > part.bounding_box().size.Z:
707706
raise ValueError(
708707
"Vertical offset cannot be greater than the part's height"
@@ -776,7 +775,7 @@ def dovetail_subpart(
776775
taper_distance=0,
777776
length_ratio=length_ratio,
778777
depth_ratio=depth_ratio,
779-
scarf_offset=-scarf_offset + vertical_scarf_offset,
778+
scarf_offset=-scarf_offset + vertical_scarf_offset * (2 if section == DovetailPart.TAIL else .5),
780779
straighten_dovetail=True,
781780
)
782781
)
@@ -805,7 +804,7 @@ def dovetail_subpart(
805804
),
806805
length_ratio=length_ratio,
807806
depth_ratio=depth_ratio,
808-
scarf_offset=-scarf_offset + vertical_scarf_offset,
807+
scarf_offset=-scarf_offset + vertical_scarf_offset * (2 if section == DovetailPart.TAIL else .5),
809808
straighten_dovetail=False,
810809
)
811810
)
@@ -1027,6 +1026,8 @@ def dovetail_split_line(
10271026

10281027

10291028
if __name__ == "__main__":
1029+
from ocp_vscode import show, Camera
1030+
10301031
with BuildPart(mode=Mode.PRIVATE) as test:
10311032
Box(40, 80, 78.7, align=(Align.CENTER, Align.CENTER, Align.MIN))
10321033
with BuildPart(
@@ -1064,7 +1065,7 @@ def dovetail_split_line(
10641065
vertical_offset=-14.33333,
10651066
click_fit_radius=.75
10661067
)
1067-
sckt.color = (0.5, 0.5, 0.5)
1068+
sckt.color = (0.5, 0.5, .5)
10681069
splines = snugtail_subpart_outline(
10691070
test.part,
10701071
Point(-25, 0),
@@ -1100,5 +1101,5 @@ def dovetail_split_line(
11001101
# splines,
11011102
reset_camera=Camera.KEEP,
11021103
)
1103-
export_stl(tl, "tail.stl")
1104-
export_stl(sckt, "socket.stl")
1104+
# export_stl(tl, "tail.stl")
1105+
# export_stl(sckt, "socket.stl")

tests/test_dovetail.py

+119
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from importlib.machinery import SourceFileLoader
44
from importlib.util import module_from_spec, spec_from_loader
55
import pytest
6+
import os
67
from unittest.mock import patch
78
from pathlib import Path
89

@@ -15,6 +16,7 @@
1516
DovetailStyle,
1617
dovetail_split_line,
1718
dovetail_subpart,
19+
snugtail_subpart_outline,
1820
)
1921

2022

@@ -34,6 +36,22 @@ def test_direct_run(self):
3436
module_from_spec(spec_from_loader(loader.name, loader))
3537
)
3638

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+
3755
def test_vertical_offset_too_high(self):
3856
with BuildPart(mode=Mode.PRIVATE) as test:
3957
Box(10, 50, 2, align=(Align.CENTER, Align.CENTER, Align.MIN))
@@ -167,3 +185,104 @@ def test_valid_vert_tail(self):
167185
vertical_offset=0.5,
168186
),
169187
)
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

Comments
 (0)