Пример #1
0
    def test_bounding_box(self):
        """Method bounding_box() is virtual and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(NotImplementedError, msg="Virtual method did not raise NotImplementedError exception when called."):
            n.bounding_box()
Пример #2
0
    def test_bounding_sphere(self):
        """Method bounding_sphere() by default calls bounding_box() and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(NotImplementedError, msg="Method did not raise NotImplementedError exception when called."):
            n.bounding_sphere()
Пример #3
0
    def test_contains(self):
        """Method contains() is virtual and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(NotImplementedError, msg="Virtual method did not raise NotImplementedError exception when called."):
            n.contains(Point3D())
Пример #4
0
    def test_material(self):
        """Setting and getting material."""

        m = Material()
        n = Primitive()

        n.material = m
        self.assertTrue(n.material is m, "Primitive's material was not correctly set/returned.")
Пример #5
0
    def test_material_set_invalid(self):
        """Setting an invalid material should raise an exception."""

        n = Primitive()

        with self.assertRaises(TypeError, msg="Attempting to set material with an invalid type (a string) did not raise an exception."):
            n.material = "This should fail!"

        with self.assertRaises(TypeError, msg="Attempting to set material with an invalid type (None) did not raise an exception."):
            n.material = None
Пример #6
0
    def test_material(self):
        """Setting and getting material."""

        m = Material()
        n = Primitive()

        n.material = m
        self.assertTrue(
            n.material is m,
            "Primitive's material was not correctly set/returned.")
Пример #7
0
    def test_bounding_sphere(self):
        """Method bounding_sphere() by default calls bounding_box() and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(
                NotImplementedError,
                msg=
                "Method did not raise NotImplementedError exception when called."
        ):
            n.bounding_sphere()
Пример #8
0
    def test_bounding_box(self):
        """Method bounding_box() is virtual and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(
                NotImplementedError,
                msg=
                "Virtual method did not raise NotImplementedError exception when called."
        ):
            n.bounding_box()
Пример #9
0
    def test_contains(self):
        """Method contains() is virtual and should raise an exception if called."""

        n = Primitive()

        with self.assertRaises(
                NotImplementedError,
                msg=
                "Virtual method did not raise NotImplementedError exception when called."
        ):
            n.contains(Point3D())
Пример #10
0
    def test_initialise_with_material(self):
        """Initialisation with a material."""

        m = Material()
        n = Primitive(material=m)

        self.assertEqual(n.parent, None, "Parent should be None.")
        self.assertEqual(
            n.root, n,
            "Primitive should be it's own root as it is not attached to a parent."
        )
        self.assertEqual(len(n.children), 0, "Child list should be empty.")
        self.assertTransformAlmostEqual(
            n.transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Root transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform_inverse,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Inverse root transform should be an identity matrix.")
        self.assertEqual(n.name, None, "Primitive name should be None.")
        self.assertTrue(n.material is m,
                        "Primitive material was not correctly initialised.")
Пример #11
0
    def test_initialise_default(self):
        """Default initialisation."""

        n = Primitive()

        self.assertEqual(n.parent, None, "Parent should be None.")
        self.assertEqual(
            n.root, n,
            "Primitive should be it's own root as it is not attached to a parent."
        )
        self.assertEqual(len(n.children), 0, "Child list should be empty.")
        self.assertTransformAlmostEqual(
            n.transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Root transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform_inverse,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Inverse root transform should be an identity matrix.")
        self.assertEqual(n.name, None, "Primitive name should be None.")
        self.assertTrue(isinstance(n.material, Material),
                        "Primitive material is not a Material object.")
Пример #12
0
    def test_material_set_invalid(self):
        """Setting an invalid material should raise an exception."""

        n = Primitive()

        with self.assertRaises(
                TypeError,
                msg=
                "Attempting to set material with an invalid type (a string) did not raise an exception."
        ):
            n.material = "This should fail!"

        with self.assertRaises(
                TypeError,
                msg=
                "Attempting to set material with an invalid type (None) did not raise an exception."
        ):
            n.material = None
Пример #13
0
    def test_initialise_with_all_arguments(self):
        """Initialisation with all arguments."""

        m = Material()
        a = Node()
        b = Primitive(a, translate(1, 2, 3), m, "My New Primitive")

        # node a
        self.assertEqual(a.parent, None, "Node a's parent should be None.")
        self.assertEqual(a.root, a, "Node a's root should be Node a.")
        self.assertEqual(a.children.count(b), 1,
                         "Node a's child list should contain Node b.")
        self.assertTransformAlmostEqual(
            a.transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            a._root_transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's root transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            a._root_transform_inverse,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's inverse root transform should be an identity matrix."
        )
        self.assertEqual(a.name, None, "Node a's name should be None.")

        # node b
        self.assertEqual(b.parent, a, "Primitive b's parent should be Node a.")
        self.assertEqual(b.root, a, "Primitive b's root should be Node a.")
        self.assertEqual(len(b.children), 0,
                         "Primitive b's child list should be empty.")
        self.assertTransformAlmostEqual(
            b.transform,
            translate(1, 2, 3),
            delta=1e-14,
            msg="Primitive b's transform was not set correctly.")
        self.assertTransformAlmostEqual(
            b._root_transform,
            translate(1, 2, 3),
            delta=1e-14,
            msg="Primitive b's root transform is incorrect.")
        self.assertTransformAlmostEqual(
            b._root_transform_inverse,
            translate(1, 2, 3).inverse(),
            delta=1e-14,
            msg="Primitive b's inverse root transform is incorrect.")
        self.assertEqual(b.name, "My New Primitive",
                         "Primitive b's name is incorrect.")
        self.assertTrue(
            b.material is m,
            "Primitive b's material was not correctly initialised.")