def cut_across_axis(self, dim, minval=None, maxval=None):
        '''
        Cut the mesh by a plane, discarding vertices that lie behind that
        plane. Or cut the mesh by two parallel planes, discarding vertices
        that lie outside them.

        The region to keep is defined by an axis of perpendicularity,
        specified by `dim`: 0 means x, 1 means y, 2 means z. `minval`
        and `maxval` indicate the portion of that axis to keep.

        Return the original indices of the kept vertices.

        '''
        # vertex_mask keeps track of the vertices we want to keep.
        vertex_mask = np.ones((len(self.v),), dtype=bool)

        if minval is not None:
            predicate = self.v[:, dim] >= minval
            vertex_mask = np.logical_and(vertex_mask, predicate)

        if maxval is not None:
            predicate = self.v[:, dim] <= maxval
            vertex_mask = np.logical_and(vertex_mask, predicate)

        vertex_indices = np.flatnonzero(vertex_mask)
        self.keep_vertices(vertex_indices)

        return vertex_indices
Cut the mesh by a plane, discarding vertices that lie behind that
        plane. Or cut the mesh by two parallel planes, discarding vertices
        that lie outside them.

        The region to keep is defined by an axis of perpendicularity,
        specified by `dim`: 0 means x, 1 means y, 2 means z. `minval`
        and `maxval` indicate the portion of that axis to keep.

        Return the original indices of the kept vertices.