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

Function get_parallels

lib/matplotlib/bezier.py:558–629  ·  view source on GitHub ↗

Given the quadratic Bézier control points *bezier2*, returns control points of quadratic Bézier lines roughly parallel to given one separated by *width*.

(bezier2, width)

Source from the content-addressed store, hash-verified

556
557
558def get_parallels(bezier2, width):
559 """
560 Given the quadratic Bézier control points *bezier2*, returns
561 control points of quadratic Bézier lines roughly parallel to given
562 one separated by *width*.
563 """
564
565 # The parallel Bezier lines are constructed by following ways.
566 # c1 and c2 are control points representing the start and end of the
567 # Bezier line.
568 # cm is the middle point
569
570 c1x, c1y = bezier2[0]
571 cmx, cmy = bezier2[1]
572 c2x, c2y = bezier2[2]
573
574 parallel_test = check_if_parallel(c1x - cmx, c1y - cmy,
575 cmx - c2x, cmy - c2y)
576
577 if parallel_test == -1:
578 _api.warn_external(
579 "Lines do not intersect. A straight line is used instead.")
580 cos_t1, sin_t1 = get_cos_sin(c1x, c1y, c2x, c2y)
581 cos_t2, sin_t2 = cos_t1, sin_t1
582 else:
583 # t1 and t2 is the angle between c1 and cm, cm, c2. They are
584 # also an angle of the tangential line of the path at c1 and c2
585 cos_t1, sin_t1 = get_cos_sin(c1x, c1y, cmx, cmy)
586 cos_t2, sin_t2 = get_cos_sin(cmx, cmy, c2x, c2y)
587
588 # find c1_left, c1_right which are located along the lines
589 # through c1 and perpendicular to the tangential lines of the
590 # Bezier path at a distance of width. Same thing for c2_left and
591 # c2_right with respect to c2.
592 c1x_left, c1y_left, c1x_right, c1y_right = (
593 get_normal_points(c1x, c1y, cos_t1, sin_t1, width)
594 )
595 c2x_left, c2y_left, c2x_right, c2y_right = (
596 get_normal_points(c2x, c2y, cos_t2, sin_t2, width)
597 )
598
599 # find cm_left which is the intersecting point of a line through
600 # c1_left with angle t1 and a line through c2_left with angle
601 # t2. Same with cm_right.
602 try:
603 cmx_left, cmy_left = get_intersection(c1x_left, c1y_left, cos_t1,
604 sin_t1, c2x_left, c2y_left,
605 cos_t2, sin_t2)
606 cmx_right, cmy_right = get_intersection(c1x_right, c1y_right, cos_t1,
607 sin_t1, c2x_right, c2y_right,
608 cos_t2, sin_t2)
609 except ValueError:
610 # Special case straight lines, i.e., angle between two lines is
611 # less than the threshold used by get_intersection (we don't use
612 # check_if_parallel as the threshold is not the same).
613 cmx_left, cmy_left = (
614 0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left)
615 )

Callers 1

transmuteMethod · 0.85

Calls 4

check_if_parallelFunction · 0.85
get_cos_sinFunction · 0.85
get_normal_pointsFunction · 0.85
get_intersectionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…