| 40 | triangles formed from colinear points, or overlapping triangles. |
| 41 | """ |
| 42 | def __init__(self, x, y, triangles=None, mask=None): |
| 43 | from matplotlib import _qhull |
| 44 | |
| 45 | self.x = np.asarray(x, dtype=np.float64) |
| 46 | self.y = np.asarray(y, dtype=np.float64) |
| 47 | if self.x.shape != self.y.shape or self.x.ndim != 1: |
| 48 | raise ValueError("x and y must be equal-length 1D arrays, but " |
| 49 | f"found shapes {self.x.shape!r} and " |
| 50 | f"{self.y.shape!r}") |
| 51 | |
| 52 | self.mask = None |
| 53 | self._edges = None |
| 54 | self._neighbors = None |
| 55 | self.is_delaunay = False |
| 56 | |
| 57 | if triangles is None: |
| 58 | # No triangulation specified, so use matplotlib._qhull to obtain |
| 59 | # Delaunay triangulation. |
| 60 | self.triangles, self._neighbors = _qhull.delaunay(x, y, sys.flags.verbose) |
| 61 | self.is_delaunay = True |
| 62 | else: |
| 63 | # Triangulation specified. Copy, since we may correct triangle |
| 64 | # orientation. |
| 65 | try: |
| 66 | self.triangles = np.array(triangles, dtype=np.int32, order='C') |
| 67 | except ValueError as e: |
| 68 | raise ValueError('triangles must be a (N, 3) int array, not ' |
| 69 | f'{triangles!r}') from e |
| 70 | if self.triangles.ndim != 2 or self.triangles.shape[1] != 3: |
| 71 | raise ValueError( |
| 72 | 'triangles must be a (N, 3) int array, but found shape ' |
| 73 | f'{self.triangles.shape!r}') |
| 74 | if self.triangles.max() >= len(self.x): |
| 75 | raise ValueError( |
| 76 | 'triangles are indices into the points and must be in the ' |
| 77 | f'range 0 <= i < {len(self.x)} but found value ' |
| 78 | f'{self.triangles.max()}') |
| 79 | if self.triangles.min() < 0: |
| 80 | raise ValueError( |
| 81 | 'triangles are indices into the points and must be in the ' |
| 82 | f'range 0 <= i < {len(self.x)} but found value ' |
| 83 | f'{self.triangles.min()}') |
| 84 | |
| 85 | # Underlying C++ object is not created until first needed. |
| 86 | self._cpp_triangulation = None |
| 87 | |
| 88 | # Default TriFinder not created until needed. |
| 89 | self._trifinder = None |
| 90 | |
| 91 | self.set_mask(mask) |
| 92 | |
| 93 | def calculate_plane_coefficients(self, z): |
| 94 | """ |