Пример #1
0
def layer(normal, offset1, offset2):
    """Generate a layer, i. e. a region of space between two planes.

    If either offset is 0, the respective plane will contain the origin.
    Otherwise, the plane will be translated by offset along the normal vector.

    The normal vector needs not be normalized.
    """
    return Layer(normal, offset1, offset2)
Пример #2
0
    def test_equality(self):
        # Same object
        self.assertEqualToItself(Layer(X, 4, 5))

        # Equal objects
        self.assertEqual(Layer(X, 4, 5), Layer(X, 4, 5))

        # Different objects
        self.assertNotEqual(Layer(X, 4, 5), Layer(Y, 4, 5))  # Different normal
        self.assertNotEqual(Layer(X, 4, 5), Layer(
            X, 5, 4))  # Different offsets (even though equivalent)

        # Equal objects from different specifications
        self.assertEqual(Layer(X, 4, 5), Layer([1, 0, 0], 4,
                                               5))  # Different normal
Пример #3
0
    def test_to_scad(self):
        self.ignore_scad_comments = True

        # General case, with the normal vector in the Y/Z plane
        self.assertEqual(
            Layer([0, 1, 1], 2, 2.5).to_scad(),
            ScadObject(
                "rotate", None, [('a', 45.0), ('v', [-1.0, 0.0, 0.0])], [
                    ScadObject("translate", [[0, 0, 2]], None, [
                        ScadObject(
                            "translate", [[-infinity / 2, -infinity / 2, 0]],
                            None, [
                                ScadObject("cube", [[infinity, infinity, 0.5]],
                                           None, None)
                            ])
                    ])
                ]))
Пример #4
0
 def test_layer_generators(self):
     self.assertEqual(layer(X, 1, 2), Layer(X, 1, 2))
Пример #5
0
    def test_construction(self):
        # Valid
        with self.assertNothingRaised():
            Layer(Vector(1, 2, 3), 0, 5)
        with self.assertNothingRaised():
            Layer(Vector(1, 2, 3), 5, 0)
        with self.assertNothingRaised():
            Layer(Vector(1, 2, 3), 4, 5)
        with self.assertNothingRaised():
            Layer([1, 2, 3], 4, 5)

        # Zero size
        with self.assertWarnsRegex(UserWarning, r'offsets are equal'):
            Layer(X, 4, 4)

        # Invalid
        with self.assertRaises(ValueError):
            Layer(Vector(0, 0, 0), 4, 5)  # Zero normal
        with self.assertRaises(TypeError):
            Layer(Vector(1, 2, 3), "0", 5)
        with self.assertRaises(TypeError):
            Layer(Vector(1, 2, 3), 0, "5")
        with self.assertRaises(TypeError):
            Layer(Vector(1, 2, 3))  # Offsets missing
        with self.assertRaises(TypeError):
            Layer(Vector(1, 2, 3), 4)  # Offset missing
        with self.assertRaises(TypeError):
            Layer(1, 4, 5)  # Wrong type
Пример #6
0
 def test_str(self):
     self.assertStr(Layer(X, 2, 3),
                    "Layer with normal <1, 0, 0> from 2 to 3")
Пример #7
0
 def test_repr(self):
     self.assertRepr(Layer(X, 2, 3), "Layer(Vector(1, 0, 0), 2, 3)")