Exemple #1
0
    def test_multiplication(self):
        a = solid.Box(Point(0, 0, 0), Vector(1, 1, 1)).view(color='red')
        b = solid.Box(Point(0, 0, 2), Vector(1, 1, 1))
        collection = solid.Collection([a, b])
        common = solid.Box(Point(0.25, 0.25, 0.25), Vector(0.5, 0.5, 2))

        collection = collection * common
        self.assertEqual(len(collection.nodes), 2)
        self.assertEqual(collection.nodes[0].view_data, {'color': 'red'})

        collection = solid.Collection([a, b])
        common = solid.Box(Point(0.25, 0.25, 0.25), Vector(0.5, 0.5, 0.5))
        self.assertTrue(len(collection.nodes), 1)

        shift_units = (collection * u.cm).m_as(u.mm)
        self.assertEqual(shift_units.envelope().size(), Vector(10, 10, 30))
Exemple #2
0
 def test_view_recursion(self):
     a = solid.Box(Point(0, 0, 0), Vector(1, 1, 1))
     b = solid.Box(Point(0, 0, 2), Vector(1, 1, 1))
     collection = solid.Collection([a.view(color='red'), b])
     self.assertEqual(
         collection.view(opacity=0.5).nodes[0].view_data, {
             'color': 'red',
             'opacity': 0.5
         })
Exemple #3
0
    def test_addition(self):
        a = solid.Box(Point(0, 0, 0), Vector(1, 1, 1)).view(color='red')
        b = solid.Box(Point(0, 0, 2), Vector(1, 1, 1)).view(color='blue')
        collection = solid.Collection([a, b]) + Vector.basis.x

        self.assertEqual([n.view_data for n in collection.nodes],
                         [{
                             'color': 'red'
                         }, {
                             'color': 'blue'
                         }])
Exemple #4
0
    def test_subtraction(self):
        a = solid.Box(Point(0, 0, 0), Vector(1, 1, 1))
        b = solid.Box(Point(0, 0, 2), Vector(1, 1, 1))
        collection = solid.Collection([a, b])
        cut = solid.Box(Point(0.25, 0.25, 0.25), Vector(0.5, 0.5, 2))

        collection = collection - cut
        inset = Vector(0.05, 0.05, 0.05)
        inside = solid.Box(cut.origin + inset, cut.size() - (inset * 2))
        for n in collection.nodes:
            self.assertTrue(len((n * inside).polygons) == 0)
Exemple #5
0
    def test_inner_methods(self):
        a = solid.Box(Point(0, 0, 0), Vector(1, 1, 1)).view(color='red')
        b = solid.Box(Point(0, 0, 2), Vector(1, 1, 1)).view(color='blue')
        c = solid.Collection([a, b]) + Vector.basis.x

        original = [{'color': 'red'}, {'color': 'blue'}]

        def _vd(c):
            return [n.view_data for n in c.nodes]

        self.assertEqual(_vd(c.scale(Vector(2, 2, 2))), original)
        self.assertEqual(_vd(c.translate(Vector(1, 2, 3))), original)
        self.assertEqual(_vd(c.rotate(Vector.basis.z, tau / 3)), original)
        self.assertEqual(
            _vd(c.rotate_at(Point(1, 1, 1), Vector.basis.z, tau / 3)),
            original)