def add_streamline(
        self,
        points,
        mirror=False,
    ):
        """
        Adds a line (or series of lines) to draw.
        :param points: an iterable with an arbitrary number of items. Each item is a 3D point, represented as an iterable of length 3.
        :param mirror: Should we also draw a version that's mirrored over the XZ plane? [boolean]
        :return: None

        E.g. add_line([(0, 0, 0), (1, 0, 0)])
        """
        for p in points:
            self.x_streamline.append(float(p[0]))
            self.y_streamline.append(float(p[1]))
            self.z_streamline.append(float(p[2]))
        self.x_streamline.append(None)
        self.y_streamline.append(None)
        self.z_streamline.append(None)
        if mirror:
            reflected_points = [
                reflect_over_XZ_plane(point) for point in points
            ]
            self.add_streamline(points=reflected_points, mirror=False)
Esempio n. 2
0
def test_cas_vector():
    output = reflect_over_XZ_plane(cas.DM(vec))
    assert isinstance(output, cas.DM)
    assert np.all(
        output ==
        np.array([0, -1, 2])
    )
Esempio n. 3
0
def test_np_square():
    assert np.all(
        reflect_over_XZ_plane(square) ==
        np.array([
            [0, -1, 2],
            [3, -4, 5],
            [6, -7, 8]
        ])
    )
Esempio n. 4
0
def test_np_rectangular_tall():
    assert np.all(
        reflect_over_XZ_plane(rectangular_tall) ==
        np.array([
            [0, -1, 2],
            [3, -4, 5],
            [6, -7, 8],
            [9, -10, 11],
        ])
    )
Esempio n. 5
0
def test_cas_square():
    output = reflect_over_XZ_plane(cas.DM(square))
    assert isinstance(output, cas.DM)
    assert np.all(
        output ==
        np.array([
            [0, -1, 2],
            [3, -4, 5],
            [6, -7, 8]
        ])
    )
Esempio n. 6
0
def test_cas_rectangular_tall():
    output = reflect_over_XZ_plane(cas.DM(rectangular_tall))
    assert isinstance(output, cas.DM)
    assert np.all(
        output ==
        np.array([
            [0, -1, 2],
            [3, -4, 5],
            [6, -7, 8],
            [9, -10, 11],
        ])
    )
    def add_quad(
        self,
        points,
        intensity=0,
        outline=True,
        mirror=False,
    ):
        """
        Adds a quadrilateral face to draw. All points should be (approximately) coplanar if you want it to look right.
        :param points: an iterable with 4 items. Each item is a 3D point, represented as an iterable of length 3. Points should be given in sequential order.
        :param intensity: Intensity associated with this face
        :param outline: Do you want to outline this quad? [boolean]
        :param mirror: Should we also draw a version that's mirrored over the XZ plane? [boolean]
        :return: None

        E.g. add_face([(0, 0, 0), (1, 0, 0), (0, 1, 0)])
        """
        if not len(points) == 4:
            raise ValueError("'points' must have exactly 4 items!")
        for p in points:
            self.x_face.append(float(p[0]))
            self.y_face.append(float(p[1]))
            self.z_face.append(float(p[2]))
            self.intensity_face.append(intensity)
        indices_added = np.arange(len(self.x_face) - 4, len(self.x_face))

        self.i_face.append(indices_added[0])
        self.j_face.append(indices_added[1])
        self.k_face.append(indices_added[2])

        self.i_face.append(indices_added[0])
        self.j_face.append(indices_added[2])
        self.k_face.append(indices_added[3])

        if outline:
            self.add_line(list(points) + [points[0]])
        if mirror:
            reflected_points = [
                reflect_over_XZ_plane(point) for point in points
            ]
            self.add_quad(points=reflected_points,
                          intensity=intensity,
                          outline=outline,
                          mirror=False)
    def add_tri(
        self,
        points,
        intensity=0,
        outline=False,
        mirror=False,
    ):
        """
        Adds a triangular face to draw.
        :param points: an iterable with 3 items. Each item is a 3D point, represented as an iterable of length 3.
        :param intensity: Intensity associated with this face
        :param outline: Do you want to outline this triangle? [boolean]
        :param mirror: Should we also draw a version that's mirrored over the XZ plane? [boolean]
        :return: None

        E.g. add_face([(0, 0, 0), (1, 0, 0), (0, 1, 0)])
        """
        if not len(points) == 3:
            raise ValueError("'points' must have exactly 3 items!")
        for p in points:
            self.x_face.append(float(p[0]))
            self.y_face.append(float(p[1]))
            self.z_face.append(float(p[2]))
            self.intensity_face.append(intensity)
        indices_added = np.arange(len(self.x_face) - 3, len(self.x_face))
        self.i_face.append(indices_added[0])
        self.j_face.append(indices_added[1])
        self.k_face.append(indices_added[2])
        if outline:
            self.add_line(list(points) + [points[0]])
        if mirror:
            reflected_points = [
                reflect_over_XZ_plane(point) for point in points
            ]
            self.add_tri(points=reflected_points,
                         intensity=intensity,
                         outline=outline,
                         mirror=False)
Esempio n. 9
0
def test_np_3D():
    with pytest.raises(ValueError):
        reflect_over_XZ_plane(np.arange(2 * 3 * 4).reshape(2, 3, 4))
Esempio n. 10
0
def test_cas_rectangular_wide():
    with pytest.raises(ValueError):
        reflect_over_XZ_plane(cas.DM(rectangular_wide))
Esempio n. 11
0
def test_np_vector_2D_tall():
    with pytest.raises(ValueError):
        reflect_over_XZ_plane(np.expand_dims(vec, 1))
Esempio n. 12
0
def test_np_vector_2D_wide():
    assert np.all(
        reflect_over_XZ_plane(np.expand_dims(vec, 0)) ==
        np.array([0, -1, 2])
    )
Esempio n. 13
0
def test_np_vector():
    assert np.all(
        reflect_over_XZ_plane(vec) ==
        np.array([0, -1, 2])
    )