cosplay: Touhou/Houjuu Nue #4

Open
aniva wants to merge 189 commits from touhou/houjuu-nue into main
2 changed files with 36 additions and 0 deletions
Showing only changes of commit 9de4159166 - Show all commits

View File

@ -62,6 +62,22 @@ class TestChecks(unittest.TestCase):
class TestUtils(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): def test_tag_point(self):
""" """
A board with 3 holes of unequal sizes. Each hole is marked A board with 3 holes of unequal sizes. Each hole is marked

View File

@ -43,6 +43,26 @@ def location_sub(self: Cq.Location, rhs: Cq.Location) -> Cq.Vector:
return Cq.Vector(x1 - x2, y1 - y2, z1 - z2) return Cq.Vector(x1 - x2, y1 - y2, z1 - z2)
Cq.Location.__sub__ = location_sub 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 ### Tags
def tagPoint(self, tag: str): def tagPoint(self, tag: str):