148 lines
18 KiB
HTML
148 lines
18 KiB
HTML
|
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><title>Python: module fontTools.misc.bezierTools</title>
|
|
</head><body bgcolor="#f0f0f8">
|
|
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
|
<tr bgcolor="#7799ee">
|
|
<td valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="fontTools.html"><font color="#ffffff">fontTools</font></a>.<a href="fontTools.misc.html"><font color="#ffffff">misc</font></a>.bezierTools</strong></big></big></font></td
|
|
><td align=right valign=bottom
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/code/fontTools/Lib/fontTools/misc/bezierTools.py">/code/fontTools/Lib/fontTools/misc/bezierTools.py</a></font></td></tr></table>
|
|
<p><tt>fontTools.misc.bezierTools.py -- tools for working with bezier path segments.</tt></p>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#aa55cc">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
|
|
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="Numeric.html">Numeric</a><br>
|
|
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#eeaa77">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl><dt><a name="-acos"><strong>acos</strong></a>(...)</dt><dd><tt><a href="#-acos">acos</a>(x)<br>
|
|
<br>
|
|
Return the arc cosine (measured in radians) of x.</tt></dd></dl>
|
|
<dl><dt><a name="-calcCubicBounds"><strong>calcCubicBounds</strong></a>(pt1, pt2, pt3, pt4)</dt><dd><tt>Return the bounding rectangle for a cubic bezier segment.<br>
|
|
pt1 and pt4 are the "anchor" points, pt2 and pt3 are the "handles".<br>
|
|
<br>
|
|
>>> <a href="#-calcCubicBounds">calcCubicBounds</a>((0, 0), (25, 100), (75, 100), (100, 0))<br>
|
|
(0.0, 0.0, 100.0, 75.0)<br>
|
|
>>> <a href="#-calcCubicBounds">calcCubicBounds</a>((0, 0), (50, 0), (100, 50), (100, 100))<br>
|
|
(0.0, 0.0, 100.0, 100.0)<br>
|
|
>>> <a href="#-calcCubicBounds">calcCubicBounds</a>((50, 0), (0, 100), (100, 100), (50, 0))<br>
|
|
(35.566243270259356, 0.0, 64.433756729740679, 75.0)</tt></dd></dl>
|
|
<dl><dt><a name="-calcCubicParameters"><strong>calcCubicParameters</strong></a>(pt1, pt2, pt3, pt4)</dt></dl>
|
|
<dl><dt><a name="-calcCubicPoints"><strong>calcCubicPoints</strong></a>(a, b, c, d)</dt></dl>
|
|
<dl><dt><a name="-calcQuadraticBounds"><strong>calcQuadraticBounds</strong></a>(pt1, pt2, pt3)</dt><dd><tt>Return the bounding rectangle for a qudratic bezier segment.<br>
|
|
pt1 and pt3 are the "anchor" points, pt2 is the "handle".<br>
|
|
<br>
|
|
>>> <a href="#-calcQuadraticBounds">calcQuadraticBounds</a>((0, 0), (50, 100), (100, 0))<br>
|
|
(0.0, 0.0, 100.0, 50.0)<br>
|
|
>>> <a href="#-calcQuadraticBounds">calcQuadraticBounds</a>((0, 0), (100, 0), (100, 100))<br>
|
|
(0.0, 0.0, 100.0, 100.0)</tt></dd></dl>
|
|
<dl><dt><a name="-calcQuadraticParameters"><strong>calcQuadraticParameters</strong></a>(pt1, pt2, pt3)</dt></dl>
|
|
<dl><dt><a name="-calcQuadraticPoints"><strong>calcQuadraticPoints</strong></a>(a, b, c)</dt></dl>
|
|
<dl><dt><a name="-cos"><strong>cos</strong></a>(...)</dt><dd><tt><a href="#-cos">cos</a>(x)<br>
|
|
<br>
|
|
Return the cosine of x (measured in radians).</tt></dd></dl>
|
|
<dl><dt><a name="-printSegments"><strong>printSegments</strong></a>(segments)</dt><dd><tt>Helper for the doctests, displaying each segment in a list of<br>
|
|
segments on a single line as a tuple.</tt></dd></dl>
|
|
<dl><dt><a name="-solveCubic"><strong>solveCubic</strong></a>(a, b, c, d, abs<font color="#909090">=<built-in function abs></font>, pow<font color="#909090">=<built-in function pow></font>, sqrt<font color="#909090">=<built-in function sqrt></font>, cos<font color="#909090">=<built-in function cos></font>, acos<font color="#909090">=<built-in function acos></font>, pi<font color="#909090">=3.1415926535897931</font>)</dt><dd><tt>Solve a cubic equation where a, b, c and d are real.<br>
|
|
a*x*x*x + b*x*x + c*x + d = 0<br>
|
|
This function returns a list of roots. Note that the returned list<br>
|
|
is neither guaranteed to be sorted nor to contain unique values!</tt></dd></dl>
|
|
<dl><dt><a name="-solveQuadratic"><strong>solveQuadratic</strong></a>(a, b, c, sqrt<font color="#909090">=<built-in function sqrt></font>)</dt><dd><tt>Solve a quadratic equation where a, b and c are real.<br>
|
|
a*x*x + b*x + c = 0<br>
|
|
This function returns a list of roots. Note that the returned list<br>
|
|
is neither guaranteed to be sorted nor to contain unique values!</tt></dd></dl>
|
|
<dl><dt><a name="-splitCubic"><strong>splitCubic</strong></a>(pt1, pt2, pt3, pt4, where, isHorizontal)</dt><dd><tt>Split the cubic curve between pt1, pt2, pt3 and pt4 at position 'where',<br>
|
|
which is an x coordinate if isHorizontal is False, a y coordinate if<br>
|
|
isHorizontal is True. Return a list of curve segments.<br>
|
|
<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitCubic">splitCubic</a>((0, 0), (25, 100), (75, 100), (100, 0), 150, False))<br>
|
|
((0, 0), (25, 100), (75, 100), (100, 0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitCubic">splitCubic</a>((0, 0), (25, 100), (75, 100), (100, 0), 50, False))<br>
|
|
((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0))<br>
|
|
((50.0, 75.0), (68.75, 75.0), (87.5, 50.0), (100.0, 0.0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitCubic">splitCubic</a>((0, 0), (25, 100), (75, 100), (100, 0), 25, True))<br>
|
|
((0.0, 0.0), (2.2937927384, 9.17517095361), (4.79804488188, 17.5085042869), (7.47413641001, 25.0))<br>
|
|
((7.47413641001, 25.0), (31.2886200204, 91.6666666667), (68.7113799796, 91.6666666667), (92.52586359, 25.0))<br>
|
|
((92.52586359, 25.0), (95.2019551181, 17.5085042869), (97.7062072616, 9.17517095361), (100.0, 1.7763568394e-15))</tt></dd></dl>
|
|
<dl><dt><a name="-splitCubicAtT"><strong>splitCubicAtT</strong></a>(pt1, pt2, pt3, pt4, *ts)</dt><dd><tt>Split the cubic curve between pt1, pt2, pt3 and pt4 at one or more<br>
|
|
values of t. Return a list of curve segments.<br>
|
|
<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitCubicAtT">splitCubicAtT</a>((0, 0), (25, 100), (75, 100), (100, 0), 0.5))<br>
|
|
((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0))<br>
|
|
((50.0, 75.0), (68.75, 75.0), (87.5, 50.0), (100.0, 0.0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitCubicAtT">splitCubicAtT</a>((0, 0), (25, 100), (75, 100), (100, 0), 0.5, 0.75))<br>
|
|
((0.0, 0.0), (12.5, 50.0), (31.25, 75.0), (50.0, 75.0))<br>
|
|
((50.0, 75.0), (59.375, 75.0), (68.75, 68.75), (77.34375, 56.25))<br>
|
|
((77.34375, 56.25), (85.9375, 43.75), (93.75, 25.0), (100.0, 0.0))</tt></dd></dl>
|
|
<dl><dt><a name="-splitLine"><strong>splitLine</strong></a>(pt1, pt2, where, isHorizontal)</dt><dd><tt>Split the line between pt1 and pt2 at position 'where', which<br>
|
|
is an x coordinate if isHorizontal is False, a y coordinate if<br>
|
|
isHorizontal is True. Return a list of two line segments if the<br>
|
|
line was successfully split, or a list containing the original<br>
|
|
line.<br>
|
|
<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitLine">splitLine</a>((0, 0), (100, 100), 50, True))<br>
|
|
((0, 0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (100, 100))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitLine">splitLine</a>((0, 0), (100, 100), 100, True))<br>
|
|
((0, 0), (100, 100))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitLine">splitLine</a>((0, 0), (100, 100), 0, True))<br>
|
|
((0, 0), (0.0, 0.0))<br>
|
|
((0.0, 0.0), (100, 100))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitLine">splitLine</a>((0, 0), (100, 100), 0, False))<br>
|
|
((0, 0), (0.0, 0.0))<br>
|
|
((0.0, 0.0), (100, 100))</tt></dd></dl>
|
|
<dl><dt><a name="-splitQuadratic"><strong>splitQuadratic</strong></a>(pt1, pt2, pt3, where, isHorizontal)</dt><dd><tt>Split the quadratic curve between pt1, pt2 and pt3 at position 'where',<br>
|
|
which is an x coordinate if isHorizontal is False, a y coordinate if<br>
|
|
isHorizontal is True. Return a list of curve segments.<br>
|
|
<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadratic">splitQuadratic</a>((0, 0), (50, 100), (100, 0), 150, False))<br>
|
|
((0, 0), (50, 100), (100, 0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadratic">splitQuadratic</a>((0, 0), (50, 100), (100, 0), 50, False))<br>
|
|
((0.0, 0.0), (25.0, 50.0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (75.0, 50.0), (100.0, 0.0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadratic">splitQuadratic</a>((0, 0), (50, 100), (100, 0), 25, False))<br>
|
|
((0.0, 0.0), (12.5, 25.0), (25.0, 37.5))<br>
|
|
((25.0, 37.5), (62.5, 75.0), (100.0, 0.0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadratic">splitQuadratic</a>((0, 0), (50, 100), (100, 0), 25, True))<br>
|
|
((0.0, 0.0), (7.32233047034, 14.6446609407), (14.6446609407, 25.0))<br>
|
|
((14.6446609407, 25.0), (50.0, 75.0), (85.3553390593, 25.0))<br>
|
|
((85.3553390593, 25.0), (92.6776695297, 14.6446609407), (100.0, -7.1054273576e-15))<br>
|
|
>>> # XXX I'm not at all sure if the following behavior is desirable:<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadratic">splitQuadratic</a>((0, 0), (50, 100), (100, 0), 50, True))<br>
|
|
((0.0, 0.0), (25.0, 50.0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (50.0, 50.0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (75.0, 50.0), (100.0, 0.0))</tt></dd></dl>
|
|
<dl><dt><a name="-splitQuadraticAtT"><strong>splitQuadraticAtT</strong></a>(pt1, pt2, pt3, *ts)</dt><dd><tt>Split the quadratic curve between pt1, pt2 and pt3 at one or more<br>
|
|
values of t. Return a list of curve segments.<br>
|
|
<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadraticAtT">splitQuadraticAtT</a>((0, 0), (50, 100), (100, 0), 0.5))<br>
|
|
((0.0, 0.0), (25.0, 50.0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (75.0, 50.0), (100.0, 0.0))<br>
|
|
>>> <a href="#-printSegments">printSegments</a>(<a href="#-splitQuadraticAtT">splitQuadraticAtT</a>((0, 0), (50, 100), (100, 0), 0.5, 0.75))<br>
|
|
((0.0, 0.0), (25.0, 50.0), (50.0, 50.0))<br>
|
|
((50.0, 50.0), (62.5, 50.0), (75.0, 37.5))<br>
|
|
((75.0, 37.5), (87.5, 25.0), (100.0, 0.0))</tt></dd></dl>
|
|
<dl><dt><a name="-sqrt"><strong>sqrt</strong></a>(...)</dt><dd><tt><a href="#-sqrt">sqrt</a>(x)<br>
|
|
<br>
|
|
Return the square root of x.</tt></dd></dl>
|
|
</td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#55aa55">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
|
|
<td width="100%"><strong>__all__</strong> = ['calcQuadraticBounds', 'calcCubicBounds', 'splitLine', 'splitQuadratic', 'splitCubic', 'splitQuadraticAtT', 'splitCubicAtT', 'solveQuadratic', 'solveCubic']<br>
|
|
<strong>epsilon</strong> = 9.9999999999999998e-13<br>
|
|
<strong>pi</strong> = 3.1415926535897931</td></tr></table>
|
|
</body></html> |