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

Function split_path_inout

lib/matplotlib/bezier.py:439–497  ·  view source on GitHub ↗

Divide a path into two segments at the point where ``inside(x, y)`` becomes False.

(path, inside, tolerance=0.01, reorder_inout=False)

Source from the content-addressed store, hash-verified

437
438
439def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
440 """
441 Divide a path into two segments at the point where ``inside(x, y)`` becomes
442 False.
443 """
444 from .path import Path
445 path_iter = path.iter_segments()
446
447 ctl_points, command = next(path_iter)
448 begin_inside = inside(ctl_points[-2:]) # true if begin point is inside
449
450 ctl_points_old = ctl_points
451
452 iold = 0
453 i = 1
454
455 for ctl_points, command in path_iter:
456 iold = i
457 i += len(ctl_points) // 2
458 if inside(ctl_points[-2:]) != begin_inside:
459 bezier_path = np.concatenate([ctl_points_old[-2:], ctl_points])
460 break
461 ctl_points_old = ctl_points
462 else:
463 raise ValueError("The path does not intersect with the patch")
464
465 bp = bezier_path.reshape((-1, 2))
466 left, right = split_bezier_intersecting_with_closedpath(
467 bp, inside, tolerance)
468 if len(left) == 2:
469 codes_left = [Path.LINETO]
470 codes_right = [Path.MOVETO, Path.LINETO]
471 elif len(left) == 3:
472 codes_left = [Path.CURVE3, Path.CURVE3]
473 codes_right = [Path.MOVETO, Path.CURVE3, Path.CURVE3]
474 elif len(left) == 4:
475 codes_left = [Path.CURVE4, Path.CURVE4, Path.CURVE4]
476 codes_right = [Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4]
477 else:
478 raise AssertionError("This should never be reached")
479
480 verts_left = left[1:]
481 verts_right = right[:]
482
483 if path.codes is None:
484 path_in = Path(np.concatenate([path.vertices[:i], verts_left]))
485 path_out = Path(np.concatenate([verts_right, path.vertices[i:]]))
486
487 else:
488 path_in = Path(np.concatenate([path.vertices[:iold], verts_left]),
489 np.concatenate([path.codes[:iold], codes_left]))
490
491 path_out = Path(np.concatenate([verts_right, path.vertices[i:]]),
492 np.concatenate([codes_right, path.codes[i:]]))
493
494 if reorder_inout and not begin_inside:
495 path_in, path_out = path_out, path_in
496

Callers 1

_clipMethod · 0.85

Calls 3

PathClass · 0.85
iter_segmentsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…