-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_basic.py
95 lines (72 loc) · 2.43 KB
/
test_basic.py
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
import os
import trimesh
import unittest
import pocketing
import numpy as np
def get_model(file_name):
"""
Load a model from the models directory by expanding paths out.
Parameters
------------
file_name : str
Name of file in `models`
Returns
------------
mesh : trimesh.Geometry
Trimesh object or similar
"""
pwd = os.path.dirname(os.path.abspath(
os.path.expanduser(__file__)))
return trimesh.load(os.path.abspath(
os.path.join(pwd, '../models', file_name)))
class PocketTest(unittest.TestCase):
def test_contour(self):
path = get_model('wrench.dxf')
poly = path.polygons_full[0]
# generate tool paths
toolpaths = pocketing.contour.contour_parallel(poly, .05)
assert all(trimesh.util.is_shape(i, (-1, 2))
for i in toolpaths)
def test_troch(self):
path = get_model('wrench.dxf')
polygon = path.polygons_full[0]
# set radius arbitrarily
radius = .125
# set step to 10% of tool radius
step = radius * 0.10
# generate our trochoids
toolpath = pocketing.trochoidal.toolpath(
polygon, step=step)
assert trimesh.util.is_shape(toolpath, (-1, 2))
def test_archimedian(self):
# test generating a simple archimedean spiral
spiral = pocketing.spiral.archimedean(0.5, 2.0, 0.125)
assert trimesh.util.is_shape(spiral, (-1, 3, 2))
def test_helix(self):
# check a 3D helix
# set values off a tool radius
tool_radius = 0.25
radius = tool_radius * 1.2
pitch = tool_radius * 0.3
height = 2.0
# create the helix
h = pocketing.spiral.helix(
radius=radius,
height=height,
pitch=pitch,)
# should be 3-point arcs
check_arcs(h)
# heights should start and end correctly
assert np.isclose(h[0][0][2], 0.0)
assert np.isclose(h[-1][-1][2], height)
# check the flattened 2D radius
radii = np.linalg.norm(h.reshape((-1, 3))[:, :2], axis=1)
assert np.allclose(radii, radius)
def check_arcs(arcs):
# arcs should be 2D or 2D 3-point arcs
assert trimesh.util.is_shape(arcs, (-1, 3, (3, 2)))
# make sure arcs start where previous arc begins
for a, b in zip(arcs[:-1], arcs[1:]):
assert np.allclose(a[2], b[0])
if __name__ == '__main__':
unittest.main()