Example #1
0
 def test_create_unit_length_z_dtype(self):
     result = vector3.create_unit_length_z(dtype=np.float32)
     np.testing.assert_almost_equal(result, [0., 0., 1.], decimal=5)
     self.assertTrue(result.dtype == np.float32)
Example #2
0
import numpy as np
from pyrr import vector3, matrix33

from ..color import convert_color
from ..allocators.vertlists import VAO
from ..rect import ZRect

Z = vector3.create_unit_length_z()


def identity():
    """Return an identity transformation matrix."""
    return np.identity(3, dtype='f4')


def bounds_from_verts(vertices: np.ndarray) -> ZRect:
    """Given an array of vertices, get the bounds of the object."""
    # Ensure we only have 2D vertices
    vertices = vertices[:, :2]

    # Calculate the bounds
    mins = np.min(vertices, axis=0)
    maxs = np.max(vertices, axis=0)
    return ZRect(mins, maxs - mins)


class Bounds:
    """Descriptor for a property that returns bounds based on vertices.

    We compile an expression to access the vertices in order to be faster and
    save code.
Example #3
0
 def test_create_unit_length_z_dtype(self):
     result = vector3.create_unit_length_z(dtype=np.float32)
     np.testing.assert_almost_equal(result, [0.,0.,1.], decimal=5)
     self.assertTrue(result.dtype == np.float32)