• Home
  • Raw
  • Download

Lines Matching +full:test +full:- +full:cython

1 # -*- coding: utf-8 -*-
2 """fontTools.misc.bezierTools.py -- tools for working with Bezier path segments.
11 import cython
13 COMPILED = cython.compiled
15 # if cython not installed, use mock module with no-op decorators and types
16 from fontTools.misc import cython
77 deriv3 = (p3 + p2 - p1 - p0) * 0.125
79 (p0, (p0 + p1) * 0.5, mid - deriv3, mid),
84 @cython.returns(cython.double)
85 @cython.locals(
86 p0=cython.complex,
87 p1=cython.complex,
88 p2=cython.complex,
89 p3=cython.complex,
91 @cython.locals(mult=cython.double, arch=cython.double, box=cython.double)
93 arch = abs(p0 - p3)
94 box = abs(p0 - p1) + abs(p1 - p2) + abs(p2 - p3)
104 @cython.returns(cython.double)
105 @cython.locals(
106 pt1=cython.complex,
107 pt2=cython.complex,
108 pt3=cython.complex,
109 pt4=cython.complex,
111 @cython.locals(
112 tolerance=cython.double,
113 mult=cython.double,
130 epsilon = 1e-10
133 @cython.cfunc
134 @cython.inline
135 @cython.returns(cython.double)
136 @cython.locals(v1=cython.complex, v2=cython.complex)
141 @cython.cfunc
142 @cython.inline
143 @cython.returns(cython.double)
144 @cython.locals(x=cython.double)
176 >>> calcQuadraticArcLength((0, 0), (50, -10), (80, 50))
178 … >>> calcQuadraticArcLength((0, 0), (40, 0), (-40, 0)) # collinear points, control point outside
186 @cython.returns(cython.double)
187 @cython.locals(
188 pt1=cython.complex,
189 pt2=cython.complex,
190 pt3=cython.complex,
191 d0=cython.complex,
192 d1=cython.complex,
193 d=cython.complex,
194 n=cython.complex,
196 @cython.locals(
197 scale=cython.double,
198 origDist=cython.double,
199 a=cython.double,
200 b=cython.double,
201 x0=cython.double,
202 x1=cython.double,
203 Len=cython.double,
218 d0 = pt2 - pt1
219 d1 = pt3 - pt2
220 d = d1 - d0
224 return abs(pt3 - pt1)
228 return abs(pt3 - pt1)
233 Len = abs(2 * (_intSecAtan(x1) - _intSecAtan(x0)) * origDist / (scale * (x1 - x0)))
240 Uses Gauss-Legendre quadrature for a branch-free approximation.
254 @cython.returns(cython.double)
255 @cython.locals(
256 pt1=cython.complex,
257 pt2=cython.complex,
258 pt3=cython.complex,
260 @cython.locals(
261 v0=cython.double,
262 v1=cython.double,
263 v2=cython.double,
268 Uses Gauss-Legendre quadrature for a branch-free approximation.
279 # This, essentially, approximates the length-of-derivative function
280 # to be integrated with the best-matching fifth-degree polynomial
288 -0.492943519233745 * pt1 + 0.430331482911935 * pt2 + 0.0626120363218102 * pt3
290 v1 = abs(pt3 - pt1) * 0.4444444444444444
292 -0.0626120363218102 * pt1 - 0.430331482911935 * pt2 + 0.492943519233745 * pt3
307 A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
321 roots.append(-bx / ax2)
323 roots.append(-by / ay2)
335 Uses Gauss-Lobatto quadrature with n=5 points to approximate arc length.
352 …>>> approximateCubicArcLength((0, 0), (50, 0), (100, 0), (-50, 0)) # cusp; exact result should be …
354 >>> approximateCubicArcLength((0, 0), (50, 0), (100, -50), (-50, 0)) # cusp
362 @cython.returns(cython.double)
363 @cython.locals(
364 pt1=cython.complex,
365 pt2=cython.complex,
366 pt3=cython.complex,
367 pt4=cython.complex,
369 @cython.locals(
370 v0=cython.double,
371 v1=cython.double,
372 v2=cython.double,
373 v3=cython.double,
374 v4=cython.double,
385 # This, essentially, approximates the length-of-derivative function
386 # to be integrated with the best-matching seventh-degree polynomial
393 v0 = abs(pt2 - pt1) * 0.15
395 -0.558983582205757 * pt1
400 v2 = abs(pt4 - pt1 + pt3 - pt2) * 0.26666666666666666
402 -0.024349751127576 * pt1
403 - 0.208983582205757 * pt2
404 - 0.325650248872424 * pt3
407 v4 = abs(pt4 - pt3) * 0.15
419 A four-item tuple representing the bounding rectangle ``(xMin, yMin, xMax, yMax)``.
489 ax = pt2x - pt1x
490 ay = pt2y - pt1y
499 t = (where - (bx, by)[isHorizontal]) / a
535 ((85.3553, 25), (92.6777, 14.6447), (100, -7.10543e-15))
544 a[isHorizontal], b[isHorizontal], c[isHorizontal] - where
577 ((92.5259, 25), (95.202, 17.5085), (97.7062, 9.17517), (100, 1.77636e-15))
581 a[isHorizontal], b[isHorizontal], c[isHorizontal], d[isHorizontal] - where
637 @cython.locals(
638 pt1=cython.complex,
639 pt2=cython.complex,
640 pt3=cython.complex,
641 pt4=cython.complex,
642 a=cython.complex,
643 b=cython.complex,
644 c=cython.complex,
645 d=cython.complex,
661 @cython.returns(cython.complex)
662 @cython.locals(
663 t=cython.double,
664 pt1=cython.complex,
665 pt2=cython.complex,
666 pt3=cython.complex,
667 pt4=cython.complex,
668 pointAtT=cython.complex,
669 off1=cython.complex,
670 off2=cython.complex,
672 @cython.locals(
673 t2=cython.double, _1_t=cython.double, _1_t_2=cython.double, _2_t_1_t=cython.double
686 _1_t = 1 - t
695 pt2 = pt1 + (pt2 - pt1) * t
696 pt3 = pt4 + (pt3 - pt4) * _1_t
709 for i in range(len(ts) - 1):
712 delta = t2 - t1
737 for i in range(len(ts) - 1):
740 delta = t2 - t1
763 @cython.locals(
764 a=cython.complex,
765 b=cython.complex,
766 c=cython.complex,
767 d=cython.complex,
768 t1=cython.double,
769 t2=cython.double,
770 delta=cython.double,
771 delta_2=cython.double,
772 delta_3=cython.double,
773 a1=cython.complex,
774 b1=cython.complex,
775 c1=cython.complex,
776 d1=cython.complex,
782 for i in range(len(ts) - 1):
785 delta = t2 - t1
824 # We have a non-equation; therefore, we have no valid solution
828 roots = [-c / b]
831 DD = b * b - 4.0 * a * c
834 roots = [(-b + rDD) / 2.0 / a, (-b - rDD) / 2.0 / a]
858 >>> solveCubic(1, 1, -6, 0)
859 [-3.0, -0.0, 2.0]
860 >>> solveCubic(-10.0, -9.0, 48.0, -29.0)
861 [-2.9, 1.0, 1.0]
862 >>> solveCubic(-9.875, -9.0, 47.625, -28.75)
863 [-2.911392, 1.0, 1.0]
864 >>> solveCubic(1.0, -4.5, 6.75, -3.375)
866 >>> solveCubic(-12.0, 18.0, -9.0, 1.50023651123)
869 ... 9.0, 0.0, 0.0, -7.62939453125e-05
870 ... ) == [-0.0, -0.0, -0.0]
875 # CUBIC.C - Solve a cubic polynomial
880 # don't just test for zero; for very small values of 'a' solveCubic()
888 Q = (a1 * a1 - 3.0 * a2) / 9.0
889 R = (2.0 * a1 * a1 * a1 - 9.0 * a1 * a2 + 27.0 * a3) / 54.0
896 R2_Q3 = R2 - Q3
899 x = round(-a1 / 3.0, epsilonDigits)
903 theta = acos(max(min(R / sqrt(Q3), 1.0), -1.0))
904 rQ2 = -2.0 * sqrt(Q)
906 x0 = rQ2 * cos(theta / 3.0) - a1_3
907 x1 = rQ2 * cos((theta + 2.0 * pi) / 3.0) - a1_3
908 x2 = rQ2 * cos((theta + 4.0 * pi) / 3.0) - a1_3
910 # Merge roots that are close-enough
911 if x1 - x0 < epsilon and x2 - x1 < epsilon:
913 elif x1 - x0 < epsilon:
916 elif x2 - x1 < epsilon:
928 x = -x
929 x = round(x - a1 / 3.0, epsilonDigits)
942 bx = (x2 - cx) * 2.0
943 by = (y2 - cy) * 2.0
944 ax = x3 - cx - bx
945 ay = y3 - cy - by
954 cx = (x2 - dx) * 3.0
955 cy = (y2 - dy) * 3.0
956 bx = (x3 - x2) * 3.0 - cx
957 by = (y3 - y2) * 3.0 - cy
958 ax = x4 - dx - cx - bx
959 ay = y4 - dy - cy - by
963 @cython.cfunc
964 @cython.inline
965 @cython.locals(
966 pt1=cython.complex,
967 pt2=cython.complex,
968 pt3=cython.complex,
969 pt4=cython.complex,
970 a=cython.complex,
971 b=cython.complex,
972 c=cython.complex,
975 c = (pt2 - pt1) * 3.0
976 b = (pt3 - pt2) * 3.0 - c
977 a = pt4 - pt1 - c - b
1010 @cython.cfunc
1011 @cython.inline
1012 @cython.locals(
1013 a=cython.complex,
1014 b=cython.complex,
1015 c=cython.complex,
1016 d=cython.complex,
1017 p2=cython.complex,
1018 p3=cython.complex,
1019 p4=cython.complex,
1043 return ((pt1[0] * (1 - t) + pt2[0] * t), (pt1[1] * (1 - t) + pt2[1] * t))
1056 x = (1 - t) * (1 - t) * pt1[0] + 2 * (1 - t) * t * pt2[0] + t * t * pt3[0]
1057 y = (1 - t) * (1 - t) * pt1[1] + 2 * (1 - t) * t * pt2[1] + t * t * pt3[1]
1072 _1_t = 1 - t
1087 @cython.returns(cython.complex)
1088 @cython.locals(
1089 t=cython.double,
1090 pt1=cython.complex,
1091 pt2=cython.complex,
1092 pt3=cython.complex,
1093 pt4=cython.complex,
1095 @cython.locals(t2=cython.double, _1_t=cython.double, _1_t_2=cython.double)
1107 _1_t = 1 - t
1131 if abs(sx - ex) < epsilon and abs(sy - ey) < epsilon:
1133 return -1
1135 if abs(sx - ex) > abs(sy - ey):
1136 return (px - sx) / (ex - sx)
1138 return (py - sy) / (ey - sy)
1142 xDiff = (a[0] - origin[0]) * (b[0] - origin[0])
1143 yDiff = (a[1] - origin[1]) * (b[1] - origin[1])
1188 slope34 = (e2y - s2y) / (e2x - s2x)
1189 y = slope34 * (x - s2x) + s2y
1198 slope12 = (e1y - s1y) / (e1x - s1x)
1199 y = slope12 * (x - s1x) + s1y
1207 slope12 = (e1y - s1y) / (e1x - s1x)
1208 slope34 = (e2y - s2y) / (e2x - s2x)
1211 x = (slope12 * s1x - s1y - slope34 * s2x + s2y) / (slope12 - slope34)
1212 y = slope12 * (x - s1x) + s1y
1227 # origin. Apply this transformation to curves and root-find to find
1230 end = segment[-1]
1231 angle = math.atan2(end[1] - start[1], end[0] - start[0])
1232 return Identity.rotate(-angle).translate(-start[0], -start[1])
1278 # Back-project the point onto the line, to avoid problems with
1307 curve1, curve2, precision=1e-3, range1=None, range2=None
1400 line1 = curve1[0], curve1[-1]
1402 line2 = curve2[0], curve2[-1]
1407 line2 = curve2[0], curve2[-1]