MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / TrapezoidMapTriFinder

Class TrapezoidMapTriFinder

lib/matplotlib/tri/_trifinder.py:27–96  ·  view source on GitHub ↗

`~matplotlib.tri.TriFinder` class implemented using the trapezoid map algorithm from the book "Computational Geometry, Algorithms and Applications", second edition, by M. de Berg, M. van Kreveld, M. Overmars and O. Schwarzkopf. The triangulation must be valid, i.e. it must not

Source from the content-addressed store, hash-verified

25
26
27class TrapezoidMapTriFinder(TriFinder):
28 """
29 `~matplotlib.tri.TriFinder` class implemented using the trapezoid
30 map algorithm from the book "Computational Geometry, Algorithms and
31 Applications", second edition, by M. de Berg, M. van Kreveld, M. Overmars
32 and O. Schwarzkopf.
33
34 The triangulation must be valid, i.e. it must not have duplicate points,
35 triangles formed from colinear points, or overlapping triangles. The
36 algorithm has some tolerance to triangles formed from colinear points, but
37 this should not be relied upon.
38 """
39
40 def __init__(self, triangulation):
41 from matplotlib import _tri
42 super().__init__(triangulation)
43 self._cpp_trifinder = _tri.TrapezoidMapTriFinder(
44 triangulation.get_cpp_triangulation())
45 self._initialize()
46
47 def __call__(self, x, y):
48 """
49 Return an array containing the indices of the triangles in which the
50 specified *x*, *y* points lie, or -1 for points that do not lie within
51 a triangle.
52
53 *x*, *y* are array-like x and y coordinates of the same shape and any
54 number of dimensions.
55
56 Returns integer array with the same shape and *x* and *y*.
57 """
58 x = np.asarray(x, dtype=np.float64)
59 y = np.asarray(y, dtype=np.float64)
60 if x.shape != y.shape:
61 raise ValueError("x and y must be array-like with the same shape")
62
63 # C++ does the heavy lifting, and expects 1D arrays.
64 indices = (self._cpp_trifinder.find_many(x.ravel(), y.ravel())
65 .reshape(x.shape))
66 return indices
67
68 def _get_tree_stats(self):
69 """
70 Return a python list containing the statistics about the node tree:
71 0: number of nodes (tree size)
72 1: number of unique nodes
73 2: number of trapezoids (tree leaf nodes)
74 3: number of unique trapezoids
75 4: maximum parent count (max number of times a node is repeated in
76 tree)
77 5: maximum depth of tree (one more than the maximum number of
78 comparisons needed to search through the tree)
79 6: mean of all trapezoid depths (one more than the average number
80 of comparisons needed to search through the tree)
81 """
82 return self._cpp_trifinder.get_tree_stats()
83
84 def _initialize(self):

Callers 1

get_trifinderMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…