test_cadquery formatting
This commit is contained in:
@ -2746,10 +2746,13 @@ class TestCadQuery(BaseTest):
|
|||||||
def testTag(self):
|
def testTag(self):
|
||||||
|
|
||||||
# test tagging
|
# test tagging
|
||||||
Workplane("XY").pushPoints([(-2, 0), (2, 0)]).box(1, 1, 1, combine=False)
|
result = (
|
||||||
result = (Workplane("XY").pushPoints([(-2, 0), (2, 0)])
|
Workplane("XY")
|
||||||
.box(1, 1, 1, combine=False).tag("2 solids")
|
.pushPoints([(-2, 0), (2, 0)])
|
||||||
.union(Workplane("XY").box(6, 1, 1)))
|
.box(1, 1, 1, combine=False)
|
||||||
|
.tag("2 solids")
|
||||||
|
.union(Workplane("XY") .box(6, 1, 1))
|
||||||
|
)
|
||||||
self.assertEqual(len(result.objects), 1)
|
self.assertEqual(len(result.objects), 1)
|
||||||
result = result._getTagged("2 solids")
|
result = result._getTagged("2 solids")
|
||||||
self.assertEqual(len(result.objects), 2)
|
self.assertEqual(len(result.objects), 2)
|
||||||
@ -2758,23 +2761,34 @@ class TestCadQuery(BaseTest):
|
|||||||
|
|
||||||
obj0 = Workplane("XY").box(1, 1, 10).faces(">Z").workplane()
|
obj0 = Workplane("XY").box(1, 1, 10).faces(">Z").workplane()
|
||||||
obj1 = Workplane("XY").copyWorkplane(obj0).box(1, 1, 1)
|
obj1 = Workplane("XY").copyWorkplane(obj0).box(1, 1, 1)
|
||||||
self.assertTupleAlmostEquals((0, 0, 5),
|
self.assertTupleAlmostEquals((0, 0, 5), obj1.val().Center().toTuple(), 9)
|
||||||
obj1.val().Center().toTuple(),
|
|
||||||
9)
|
|
||||||
|
|
||||||
def testWorkplaneFromTagged(self):
|
def testWorkplaneFromTagged(self):
|
||||||
|
|
||||||
# create a flat, wide base. Extrude one object 4 units high, another
|
# create a flat, wide base. Extrude one object 4 units high, another
|
||||||
# object ontop of it 6 units high. Go back to base plane. Extrude an
|
# object ontop of it 6 units high. Go back to base plane. Extrude an
|
||||||
# object 11 units high. Assert that top face is 11 units high.
|
# object 11 units high. Assert that top face is 11 units high.
|
||||||
result = (Workplane("XY").box(10, 10, 1, centered=(True, True, False))
|
result = (
|
||||||
.faces(">Z").workplane().tag("base").center(3, 0).rect(2, 2)
|
Workplane("XY")
|
||||||
.extrude(4).faces(">Z").workplane().circle(1).extrude(6)
|
.box(10, 10, 1, centered=(True, True, False))
|
||||||
.workplaneFromTagged("base").center(-3, 0).circle(1)
|
.faces(">Z")
|
||||||
.extrude(11))
|
.workplane()
|
||||||
self.assertTupleAlmostEquals(result.faces(">Z").val().Center().toTuple(),
|
.tag("base")
|
||||||
(-3, 0, 12),
|
.center(3, 0)
|
||||||
9)
|
.rect(2, 2)
|
||||||
|
.extrude(4)
|
||||||
|
.faces(">Z")
|
||||||
|
.workplane()
|
||||||
|
.circle(1)
|
||||||
|
.extrude(6)
|
||||||
|
.workplaneFromTagged("base")
|
||||||
|
.center(-3, 0)
|
||||||
|
.circle(1)
|
||||||
|
.extrude(11)
|
||||||
|
)
|
||||||
|
self.assertTupleAlmostEquals(
|
||||||
|
result.faces(">Z").val().Center().toTuple(), (-3, 0, 12), 9
|
||||||
|
)
|
||||||
|
|
||||||
def testTagSelectors(self):
|
def testTagSelectors(self):
|
||||||
|
|
||||||
@ -2791,16 +2805,26 @@ class TestCadQuery(BaseTest):
|
|||||||
self.assertEqual(6, result0.wires(tag="box").size())
|
self.assertEqual(6, result0.wires(tag="box").size())
|
||||||
|
|
||||||
# create two solids, tag them, join to one solid
|
# create two solids, tag them, join to one solid
|
||||||
result1 = (Workplane("XY").pushPoints([(1, 0), (-1, 0)]).box(1, 1, 1)
|
result1 = (
|
||||||
.tag("boxes").sphere(1))
|
Workplane("XY")
|
||||||
|
.pushPoints([(1, 0), (-1, 0)])
|
||||||
|
.box(1, 1, 1)
|
||||||
|
.tag("boxes")
|
||||||
|
.sphere(1)
|
||||||
|
)
|
||||||
self.assertEqual(1, result1.solids().size())
|
self.assertEqual(1, result1.solids().size())
|
||||||
self.assertEqual(2, result1.solids(tag="boxes").size())
|
self.assertEqual(2, result1.solids(tag="boxes").size())
|
||||||
self.assertEqual(1, result1.shells().size())
|
self.assertEqual(1, result1.shells().size())
|
||||||
self.assertEqual(2, result1.shells(tag="boxes").size())
|
self.assertEqual(2, result1.shells(tag="boxes").size())
|
||||||
|
|
||||||
# create 4 individual objects, tag it, then combine to one compound
|
# create 4 individual objects, tag it, then combine to one compound
|
||||||
result2 = (Workplane("XY").rect(4, 4).vertices()
|
result2 = (
|
||||||
.box(1, 1, 1, combine=False).tag("4 objs"))
|
Workplane("XY")
|
||||||
|
.rect(4, 4)
|
||||||
|
.vertices()
|
||||||
|
.box(1, 1, 1, combine=False)
|
||||||
|
.tag("4 objs")
|
||||||
|
)
|
||||||
result2 = result2.newObject([Compound.makeCompound(result2.objects)])
|
result2 = result2.newObject([Compound.makeCompound(result2.objects)])
|
||||||
self.assertEqual(1, result2.compounds().size())
|
self.assertEqual(1, result2.compounds().size())
|
||||||
self.assertEqual(0, result2.compounds(tag="4 objs").size())
|
self.assertEqual(0, result2.compounds(tag="4 objs").size())
|
||||||
|
|||||||
Reference in New Issue
Block a user