feat: 2d location
This commit is contained in:
parent
eb445b3d8b
commit
9de4159166
16
nhf/test.py
16
nhf/test.py
|
@ -62,6 +62,22 @@ class TestChecks(unittest.TestCase):
|
|||
|
||||
class TestUtils(unittest.TestCase):
|
||||
|
||||
def test_2d_orientation(self):
|
||||
l1 = Cq.Location.from2d(1.2, 0)
|
||||
l2 = Cq.Location.from2d(0, 0, 90)
|
||||
l3 = l2 * l1
|
||||
(x, y), r = l3.to2d()
|
||||
self.assertAlmostEqual(x, 0)
|
||||
self.assertAlmostEqual(y, 1.2)
|
||||
self.assertAlmostEqual(r, 90)
|
||||
|
||||
def test_2d_planar(self):
|
||||
l1 = Cq.Location.from2d(1.2, 4.5, 67)
|
||||
l2 = Cq.Location.from2d(98, 5.4, 36)
|
||||
l3 = Cq.Location.from2d(10, 10, 0)
|
||||
l = l3 * l2 * l1
|
||||
self.assertTrue(l.is2d())
|
||||
|
||||
def test_tag_point(self):
|
||||
"""
|
||||
A board with 3 holes of unequal sizes. Each hole is marked
|
||||
|
|
20
nhf/utils.py
20
nhf/utils.py
|
@ -43,6 +43,26 @@ def location_sub(self: Cq.Location, rhs: Cq.Location) -> Cq.Vector:
|
|||
return Cq.Vector(x1 - x2, y1 - y2, z1 - z2)
|
||||
Cq.Location.__sub__ = location_sub
|
||||
|
||||
def from2d(x: float, y: float, rotate: float=0.0) -> Cq.Location:
|
||||
return Cq.Location((x, y, 0), (0, 0, 1), rotate)
|
||||
Cq.Location.from2d = from2d
|
||||
|
||||
def is2d(self: Cq.Location) -> bool:
|
||||
(_, _, z), (rx, ry, _) = self.toTuple()
|
||||
return z == 0 and rx == 0 and ry == 0
|
||||
Cq.Location.is2d = is2d
|
||||
|
||||
def to2d(self: Cq.Location) -> Tuple[Tuple[float, float], float]:
|
||||
"""
|
||||
Returns position and angle
|
||||
"""
|
||||
(x, y, z), (rx, ry, rz) = self.toTuple()
|
||||
assert z == 0
|
||||
assert rx == 0
|
||||
assert ry == 0
|
||||
return (x, y), rz
|
||||
Cq.Location.to2d = to2d
|
||||
|
||||
### Tags
|
||||
|
||||
def tagPoint(self, tag: str):
|
||||
|
|
Loading…
Reference in New Issue