<commit_before>import sys
import numpy as np

if sys.version_info >= (3,):
    xrange = range


class MeshData(object):
    """
    Class for storing and operating on 3D mesh data.

    Parameters
    ----------
    vertexes : ndarray, shape (Nv, 3)
        Vertex coordinates. If faces is not specified, then this will
        instead be interpreted as (Nf, 3, 3) array of coordinates.
    faces : ndarray, shape (Nf, 3)
        Indexes into the vertex array.
    edges : None
        [not available yet]
    vertexColors : ndarray, shape (Nv, 4)
        Vertex colors. If faces is not specified, this will be
        interpreted as (Nf, 3, 4) array of colors.
    faceColors : ndarray, shape (Nf, 4)
        Face colors.

    Notes
    -----
    All arguments are optional.

    The object may contain:

    - list of vertex locations
    - list of edges
    - list of triangles
    - colors per vertex, edge, or tri
    - normals per vertex or tri

    This class handles conversion between the standard
    [list of vertexes, list of faces] format (suitable for use with
    glDrawElements) and 'indexed' [list of vertexes] format (suitable
    for use with glDrawArrays). It will automatically compute face normal
    vectors as well as averaged vertex normal vectors.

    The class attempts to be as efficient as possible in caching conversion
    results and avoiding unnecessary conversions.
    """

    def __init__(self, vertexes=None, faces=None, edges=None,
                 vertexColors=None, faceColors=None):
        self._vertexes = None  # (Nv,3) array of vertex coordinates
        self._vertexesIndexedByFaces = None  # (Nf, 3, 3) vertex coordinates
        self._vertexesIndexedByEdges = None  # (Ne, 2, 3) vertex coordinates

        ## mappings between vertexes, faces, and edges
        self._faces = None  # Nx3 indexes into self._vertexes, 3 verts/face
        self._edges = None  # Nx2 indexes into self._vertexes, 2 verts/edge
        # inverse mappings
        self._vertexFaces = None  # maps vertex ID to a list of face IDs
        self._vertexEdges = None  # maps vertex ID to a list of edge IDs

        ## Per-vertex data
        self._vertexNormals = None                # (Nv, 3) normals
        self._vertexNormalsIndexedByFaces = None  # (Nf, 3, 3) normals
        self._vertexColors = None                 # (Nv, 3) colors
        self._vertexColorsIndexedByFaces = None   # (Nf, 3, 4) colors
        self._vertexColorsIndexedByEdges = None   # (Nf, 2, 4) colors

        ## Per-face data
        self._faceNormals = None                # (Nf, 3) face normals
        self._faceNormalsIndexedByFaces = None  # (Nf, 3, 3) face normals
        self._faceColors = None                 # (Nf, 4) face colors
        self._faceColorsIndexedByFaces = None   # (Nf, 3, 4) face colors
        self._faceColorsIndexedByEdges = None   # (Ne, 2, 4) face colors

        ## Per-edge data
        self._edgeColors = None                # (Ne, 4) edge colors
        self._edgeColorsIndexedByEdges = None  # (Ne, 2, 4) edge colors
        # default color to use if no face/edge/vertex colors are given
        #self._meshColor = (1, 1, 1, 0.1)

        if vertexes is not None:
            if faces is None:
                self.setVertexes(vertexes, indexed='faces')
                if vertexColors is not None:
                    self.setVertexColors(vertexColors, indexed='faces')
                if faceColors is not None:
                    self.setFaceColors(faceColors, indexed='faces')
            else:
                self.setVertexes(vertexes)
                self.setFaces(faces)
                if vertexColors is not None:
                    self.setVertexColors(vertexColors)
                if faceColors is not None:
                    self.setFaceColors(faceColors)

    def faces(self):
        """Array (Nf, 3) of vertex indices, three per triangular face.

        If faces have not been computed for this mesh, returns None.
        """
        return self._faces

    def edges(self):
        """Array (Nf, 3) of vertex indexes, two per edge in the mesh."""
        if self._edges is None:
            self._computeEdges()
        return self._edges

    def setFaces(self, faces):
        """Set the (Nf, 3) array of faces. Each rown in the array contains
        three indexes into the vertex array, specifying the three corners
        of a triangular face."""
        self._faces = faces
        self._edges = None
        self._vertexFaces = None
        self._vertexesIndexedByFaces = None
        self.resetNormals()
        self._vertexColorsIndexedByFaces = None
        self._faceColorsIndexedByFaces = None

    def vertexes(self, indexed=None):
        """Return an array (N,3) of the positions of vertexes in the mesh.
        By default, each unique vertex appears only once in the array.
        If indexed is 'faces', then the array will instead contain three
        vertexes per face in the mesh (and a single vertex may appear more
        than once in the array)."""
        if indexed is None:
            if (self._vertexes is None and
                    self._vertexesIndexedByFaces is not None):
                self._computeUnindexedVertexes()
            return self._vertexes
        elif indexed == 'faces':
            if (self._vertexesIndexedByFaces is None and
                    self._vertexes is not None):
                self._vertexesIndexedByFaces = self._vertexes[self.faces()]
            return self._vertexesIndexedByFaces
        else:
            raise Exception("Invalid indexing mode. Accepts: None, 'faces'")

    def setVertexes(self, verts=None, indexed=None, resetNormals=True):
        """
        Set the array (Nv, 3) of vertex coordinates.
        If indexed=='faces', then the data must have shape (Nf, 3, 3) and is
        assumed to be already indexed as a list of faces.
        This will cause any pre-existing normal vectors to be cleared
        unless resetNormals=False.
        """
        if indexed is None:
            if verts is not None:
                self._vertexes = verts
            self._vertexesIndexedByFaces = None
        elif indexed == 'faces':
            self._vertexes = None
            if verts is not None:
                self._vertexesIndexedByFaces = verts
        else:
            raise Exception("Invalid indexing mode. Accepts: None, 'faces'")

        if resetNormals:
            self.resetNormals()

    def resetNormals(self):
        self._vertexNormals = None
        self._vertexNormalsIndexedByFaces = None
        self._faceNormals = None
        self._faceNormalsIndexedByFaces = None

    def hasFaceIndexedData(self):
        """Return True if vertex positions are already indexed by face"""
        return self._vertexesIndexedByFaces is not None

    def hasEdgeIndexedData(self):<commit_msg>STY: Fix wording<commit_after>import sys
import numpy as np

if sys.version_info >= (3,):
    xrange = range


class MeshData(object):
    """
    Class for storing and operating on 3D mesh data.

    Parameters
    ----------
    vertexes : ndarray, shape (Nv, 3)
        Vertex coordinates. If faces is not specified, then this will
        instead be interpreted as (Nf, 3, 3) array of coordinates.
    faces : ndarray, shape (Nf, 3)
        Indexes into the vertex array.
    edges : None
        [not available yet]
    vertexColors : ndarray, shape (Nv, 4)
        Vertex colors. If faces is not specified, this will be
        interpreted as (Nf, 3, 4) array of colors.
    faceColors : ndarray, shape (Nf, 4)
        Face colors.

    Notes
    -----
    All arguments are optional.

    The object may contain:

    - list of vertex locations
    - list of edges
    - list of triangles
    - colors per vertex, edge, or tri
    - normals per vertex or tri

    This class handles conversion between the standard
    [list of vertexes, list of faces] format (suitable for use with
    glDrawElements) and 'indexed' [list of vertexes] format (suitable
    for use with glDrawArrays). It will automatically compute face normal
    vectors as well as averaged vertex normal vectors.

    The class attempts to be as efficient as possible in caching conversion
    results and avoiding unnecessary conversions.
    """

    def __init__(self, vertexes=None, faces=None, edges=None,
                 vertexColors=None, faceColors=None):
        self._vertexes = None  # (Nv,3) array of vertex coordinates
        self._vertexesIndexedByFaces = None  # (Nf, 3, 3) vertex coordinates
        self._vertexesIndexedByEdges = None  # (Ne, 2, 3) vertex coordinates

        ## mappings between vertexes, faces, and edges
        self._faces = None  # Nx3 indexes into self._vertexes, 3 verts/face
        self._edges = None  # Nx2 indexes into self._vertexes, 2 verts/edge
        # inverse mappings
        self._vertexFaces = None  # maps vertex ID to a list of face IDs
        self._vertexEdges = None  # maps vertex ID to a list of edge IDs

        ## Per-vertex data
        self._vertexNormals = None                # (Nv, 3) normals
        self._vertexNormalsIndexedByFaces = None  # (Nf, 3, 3) normals
        self._vertexColors = None                 # (Nv, 3) colors
        self._vertexColorsIndexedByFaces = None   # (Nf, 3, 4) colors
        self._vertexColorsIndexedByEdges = None   # (Nf, 2, 4) colors

        ## Per-face data
        self._faceNormals = None                # (Nf, 3) face normals
        self._faceNormalsIndexedByFaces = None  # (Nf, 3, 3) face normals
        self._faceColors = None                 # (Nf, 4) face colors
        self._faceColorsIndexedByFaces = None   # (Nf, 3, 4) face colors
        self._faceColorsIndexedByEdges = None   # (Ne, 2, 4) face colors

        ## Per-edge data
        self._edgeColors = None                # (Ne, 4) edge colors
        self._edgeColorsIndexedByEdges = None  # (Ne, 2, 4) edge colors
        # default color to use if no face/edge/vertex colors are given
        #self._meshColor = (1, 1, 1, 0.1)

        if vertexes is not None:
            if faces is None:
                self.setVertexes(vertexes, indexed='faces')
                if vertexColors is not None:
                    self.setVertexColors(vertexColors, indexed='faces')
                if faceColors is not None:
                    self.setFaceColors(faceColors, indexed='faces')
            else:
                self.setVertexes(vertexes)
                self.setFaces(faces)
                if vertexColors is not None:
                    self.setVertexColors(vertexColors)
                if faceColors is not None:
                    self.setFaceColors(faceColors)

    def faces(self):
        """Array (Nf, 3) of vertex indices, three per triangular face.

        If faces have not been computed for this mesh, returns None.
        """
        return self._faces

    def edges(self):
        """Array (Nf, 3) of vertex indexes, two per edge in the mesh."""
        if self._edges is None:
            self._computeEdges()
        return self._edges

    def setFaces(self, faces):
        """Set the (Nf, 3) array of faces. Each rown in the array contains
        three indexes into the vertex array, specifying the three corners
        of a triangular face."""
        self._faces = faces
        self._edges = None
        self._vertexFaces = None
        self._vertexesIndexedByFaces = None
        self.resetNormals()
        self._vertexColorsIndexedByFaces = None
        self._faceColorsIndexedByFaces = None

    def vertexes(self, indexed=None):
        """Return an array (N,3) of the positions of vertexes in the mesh.
        By default, each unique vertex appears only once in the array.
        If indexed is 'faces', then the array will instead contain three
        vertexes per face in the mesh (and a single vertex may appear more
        than once in the array)."""
        if indexed is None:
            if (self._vertexes is None and
                    self._vertexesIndexedByFaces is not None):
                self._computeUnindexedVertexes()
            return self._vertexes
        elif indexed == 'faces':
            if (self._vertexesIndexedByFaces is None and
                    self._vertexes is not None):
                self._vertexesIndexedByFaces = self._vertexes[self.faces()]
            return self._vertexesIndexedByFaces
        else:
            raise Exception("Invalid indexing mode. Accepts: None, 'faces'")

    def setVertexes(self, verts=None, indexed=None, resetNormals=True):
        """
        Set the array (Nv, 3) of vertex coordinates.
        If indexed=='faces', then the data must have shape (Nf, 3, 3) and is
        assumed to be already indexed as a list of faces.
        This will cause any pre-existing normal vectors to be cleared
        unless resetNormals=False.
        """
        if indexed is None:
            if verts is not None:
                self._vertexes = verts
            self._vertexesIndexedByFaces = None
        elif indexed == 'faces':
            self._vertexes = None
            if verts is not None:
                self._vertexesIndexedByFaces = verts
        else:
            raise Exception("Invalid indexing mode. Accepts: None, 'faces'")

        if resetNormals:
            self.resetNormals()

    def resetNormals(self):
        self._vertexNormals = None
        self._vertexNormalsIndexedByFaces = None
        self._faceNormals = None
        self._faceNormalsIndexedByFaces = None

    def hasFaceIndexedData(self):
        """Return True if this object already has vertex positions indexed
        by face"""
        return self._vertexesIndexedByFaces is not None

    def hasEdgeIndexedData(self):
{'fraction_non_alphanumeric': 0.07432481618985222, 'fraction_numerical': 0.007279609812914028, 'mean_word_length': 2.0617338979273456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7354892', 'n_tokens_mistral': 3892, 'n_tokens_neox': 3710, 'n_words': 1383}