Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Specialized path collection#16872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,6 +19,59 @@ | ||
from .cbook import _to_unmasked_float_array, simple_linear_interpolation | ||
class PathCollection: | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Perhaps another name would avoid confusion with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Sure, name isn't important for me. I didn't know this one is taken already. Any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nothing comes to my mind for now, but we can change this later (before this is merged). | ||
_is_uniform_path_collection = True | ||
def __init__(self, vertices, codes=None, _interpolation_steps=1, | ||
closed=False): | ||
# TODO: Should this support readonly?? | ||
vertices = _to_unmasked_float_array(vertices) | ||
if vertices.ndim != 3 or vertices.shape[-1] != 2: | ||
raise ValueError( | ||
"'vertices' must be a 3D list or array with shape CxNx2") | ||
if codes is not None: | ||
codes = np.asarray(codes, Path.code_type) | ||
if codes.shape != vertices.shape[:-1]: | ||
raise ValueError("'codes' must be a 2D list or array with the " | ||
"same length of 'vertices'") | ||
if len(codes) and np.any(codes[0] != self.MOVETO): | ||
raise ValueError("The first element of 'code' must be equal " | ||
"to 'MOVETO' ({})".format(self.MOVETO)) | ||
elif closed and len(vertices): | ||
codes = np.empty((1, vertices.shape[1]), dtype=Path.code_type) | ||
codes[:, 0] = Path.MOVETO | ||
codes[:, 1:-1] = Path.LINETO | ||
codes[:, -1] = Path.CLOSEPOLY | ||
codes = np.broadcast_to(codes, vertices.shape[:-1]) | ||
self._vertices = vertices | ||
self._codes = codes | ||
self._interpolation_steps = _interpolation_steps | ||
self._example_path = Path(vertices[0], codes[0], _interpolation_steps) | ||
def __len__(self): | ||
return len(self._vertices) | ||
def __getitem__(self, i): | ||
pth = Path.__new__(Path) | ||
pth._vertices = self._vertices[i] | ||
pth._codes = self._codes[i] | ||
pth._readonly = False | ||
pth._should_simplify = self._example_path._should_simplify | ||
pth._simplify_threshold = self._example_path._simplify_threshold | ||
pth._interpolation_steps = self._example_path._interpolation_steps | ||
return pth | ||
@property | ||
def should_simplify(self): | ||
return self._example_path.should_simplify | ||
@property | ||
def simplify_threshold(self): | ||
return self._example_path.simplify_threshold | ||
class Path: | ||
""" | ||
A series of possibly disconnected, possibly closed, line and curve | ||
Uh oh!
There was an error while loading.Please reload this page.