bezierTools¶
fontTools.misc.bezierTools.py – tools for working with bezier path segments. Rewritten to elimate the numpy dependency
-
calcQuadraticBounds
(pt1, pt2, pt3)¶ Return the bounding rectangle for a qudratic bezier segment. pt1 and pt3 are the “anchor” points, pt2 is the “handle”.
>>> calcQuadraticBounds((0, 0), (50, 100), (100, 0)) (0, 0, 100, 50.0) >>> calcQuadraticBounds((0, 0), (100, 0), (100, 100)) (0.0, 0.0, 100, 100)
-
calcCubicBounds
(pt1, pt2, pt3, pt4)¶ Return the bounding rectangle for a cubic bezier segment. pt1 and pt4 are the “anchor” points, pt2 and pt3 are the “handles”.
>>> calcCubicBounds((0, 0), (25, 100), (75, 100), (100, 0)) (0, 0, 100, 75.0) >>> calcCubicBounds((0, 0), (50, 0), (100, 50), (100, 100)) (0.0, 0.0, 100, 100) >>> calcCubicBounds((50, 0), (0, 100), (100, 100), (50, 0)) (35.566243270259356, 0, 64.43375672974068, 75.0)
-
splitLine
(pt1, pt2, where, isHorizontal)¶ Split the line between pt1 and pt2 at position ‘where’, which is an x coordinate if isHorizontal is False, a y coordinate if isHorizontal is True. Return a list of two line segments if the line was successfully split, or a list containing the original line.
>>> printSegments(splitLine((0, 0), (100, 200), 50, False)) ((0, 0), (50.0, 100.0)) ((50.0, 100.0), (100, 200)) >>> printSegments(splitLine((0, 0), (100, 200), 50, True)) ((0, 0), (25.0, 50.0)) ((25.0, 50.0), (100, 200)) >>> printSegments(splitLine((0, 0), (100, 100), 50, True)) ((0, 0), (50.0, 50.0)) ((50.0, 50.0), (100, 100)) >>> printSegments(splitLine((0, 0), (100, 100), 100, True)) ((0, 0), (100, 100)) >>> printSegments(splitLine((0, 0), (100, 100), 0, True)) ((0, 0), (0.0, 0.0)) ((0.0, 0.0), (100, 100)) >>> printSegments(splitLine((0, 0), (100, 100), 0, False)) ((0, 0), (0.0, 0.0)) ((0.0, 0.0), (100, 100))
-
splitQuadratic
(pt1, pt2, pt3, where, isHorizontal)¶ Split the quadratic curve between pt1, pt2 and pt3 at position ‘where’, which is an x coordinate if isHorizontal is False, a y coordinate if isHorizontal is True. Return a list of curve segments.
>>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 150, False)) ((0, 0), (50, 100), (100, 0)) >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 50, False)) ((0.0, 0.0), (25.0, 50.0), (50.0, 50.0)) ((50.0, 50.0), (75.0, 50.0), (100.0, 0.0)) >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 25, False)) ((0.0, 0.0), (12.5, 25.0), (25.0, 37.5)) ((25.0, 37.5), (62.5, 75.0), (100.0, 0.0)) >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 25, True)) ((0.0, 0.0), (7.32233047034, 14.6446609407), (14.6446609407, 25.0)) ((14.6446609407, 25.0), (50.0, 75.0), (85.3553390593, 25.0)) ((85.3553390593, 25.0), (92.6776695297, 14.6446609407), (100.0, -7.1054273576e-15)) >>> # XXX I'm not at all sure if the following behavior is desirable: >>> printSegments(splitQuadratic((0, 0), (50, 100), (100, 0), 50, True)) ((0.0, 0.0), (25.0, 50.0), (50.0, 50.0)) ((50.0, 50.0), (50.0, 50.0), (50.0, 50.0)) ((50.0, 50.0), (75.0, 50.0), (100.0, 0.0))
-
splitCubic
(pt1, pt2, pt3, pt4, where, isHorizontal)¶ Split the cubic curve between pt1, pt2, pt3 and pt4 at position ‘where’, which is an x coordinate if isHorizontal is False, a y coordinate if isHorizontal is True. Return a list of curve segments.
>>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 150, False)) ((0, 0), (25, 100), (75, 100), (100, 0)) >>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 50, False)) ((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0)) ((50.0, 75.0), (68.75, 75.0), (87.5, 50.0), (100.0, 0.0)) >>> printSegments(splitCubic((0, 0), (25, 100), (75, 100), (100, 0), 25, True)) ((0.0, 0.0), (2.2937927384, 9.17517095361), (4.79804488188, 17.5085042869), (7.47413641001, 25.0)) ((7.47413641001, 25.0), (31.2886200204, 91.6666666667), (68.7113799796, 91.6666666667), (92.52586359, 25.0)) ((92.52586359, 25.0), (95.2019551181, 17.5085042869), (97.7062072616, 9.17517095361), (100.0, 1.7763568394e-15))
-
splitQuadraticAtT
(pt1, pt2, pt3, *ts)¶ Split the quadratic curve between pt1, pt2 and pt3 at one or more values of t. Return a list of curve segments.
>>> printSegments(splitQuadraticAtT((0, 0), (50, 100), (100, 0), 0.5)) ((0.0, 0.0), (25.0, 50.0), (50.0, 50.0)) ((50.0, 50.0), (75.0, 50.0), (100.0, 0.0)) >>> printSegments(splitQuadraticAtT((0, 0), (50, 100), (100, 0), 0.5, 0.75)) ((0.0, 0.0), (25.0, 50.0), (50.0, 50.0)) ((50.0, 50.0), (62.5, 50.0), (75.0, 37.5)) ((75.0, 37.5), (87.5, 25.0), (100.0, 0.0))
-
splitCubicAtT
(pt1, pt2, pt3, pt4, *ts)¶ Split the cubic curve between pt1, pt2, pt3 and pt4 at one or more values of t. Return a list of curve segments.
>>> printSegments(splitCubicAtT((0, 0), (25, 100), (75, 100), (100, 0), 0.5)) ((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0)) ((50.0, 75.0), (68.75, 75.0), (87.5, 50.0), (100.0, 0.0)) >>> printSegments(splitCubicAtT((0, 0), (25, 100), (75, 100), (100, 0), 0.5, 0.75)) ((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0)) ((50.0, 75.0), (59.375, 75.0), (68.75, 68.75), (77.34375, 56.25)) ((77.34375, 56.25), (85.9375, 43.75), (93.75, 25.0), (100.0, 0.0))
-
solveQuadratic
(a, b, c, sqrt=<built-in function sqrt>)¶ - Solve a quadratic equation where a, b and c are real.
- a*x*x + b*x + c = 0
This function returns a list of roots. Note that the returned list is neither guaranteed to be sorted nor to contain unique values!
-
solveCubic
(a, b, c, d, abs=<built-in function abs>, pow=<built-in function pow>, sqrt=<built-in function sqrt>, cos=<built-in function cos>, acos=<built-in function acos>, pi=3.141592653589793)¶ - Solve a cubic equation where a, b, c and d are real.
- a*x*x*x + b*x*x + c*x + d = 0
This function returns a list of roots. Note that the returned list is neither guaranteed to be sorted nor to contain unique values!