OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrStrokePathRenderer.h" | 8 #include "GrStrokePathRenderer.h" |
9 | 9 |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4); | 32 SkScalar d = SkScalarMul(x1 - x2, y3 - y4) - SkScalarMul(y1 - y2, x3 - x4); |
33 // If d is zero, there is no intersection | 33 // If d is zero, there is no intersection |
34 if (SkScalarNearlyZero(d)) { | 34 if (SkScalarNearlyZero(d)) { |
35 return kNone_IntersectionType; | 35 return kNone_IntersectionType; |
36 } | 36 } |
37 | 37 |
38 // Get the x and y | 38 // Get the x and y |
39 SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2), | 39 SkScalar pre = SkScalarMul(x1, y2) - SkScalarMul(y1, x2), |
40 post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4); | 40 post = SkScalarMul(x3, y4) - SkScalarMul(y3, x4); |
41 // Compute the point of intersection | 41 // Compute the point of intersection |
42 res.set(SkScalarDiv(SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post),
d), | 42 res.set((SkScalarMul(pre, x3 - x4) - SkScalarMul(x1 - x2, post) / d, |
43 SkScalarDiv(SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post),
d)); | 43 (SkScalarMul(pre, y3 - y4) - SkScalarMul(y1 - y2, post) / d); |
44 | 44 |
45 // Check if the x and y coordinates are within both lines | 45 // Check if the x and y coordinates are within both lines |
46 return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) || | 46 return (res.x() < GrMin(x1, x2) || res.x() > GrMax(x1, x2) || |
47 res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) || | 47 res.x() < GrMin(x3, x4) || res.x() > GrMax(x3, x4) || |
48 res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) || | 48 res.y() < GrMin(y1, y2) || res.y() > GrMax(y1, y2) || |
49 res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ? | 49 res.y() < GrMin(y3, y4) || res.y() > GrMax(y3, y4)) ? |
50 kOut_IntersectionType : kIn_IntersectionType; | 50 kOut_IntersectionType : kIn_IntersectionType; |
51 } | 51 } |
52 | 52 |
53 GrStrokePathRenderer::GrStrokePathRenderer() { | 53 GrStrokePathRenderer::GrStrokePathRenderer() { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (sinHalfAngleSq >= invMiterLimitSq) { | 177 if (sinHalfAngleSq >= invMiterLimitSq) { |
178 // Find the miter point (or points i
f it is further | 178 // Find the miter point (or points i
f it is further |
179 // than the miter limit) | 179 // than the miter limit) |
180 const SkPoint pt2 = *pt0+v0, pt3 = *
pt1+v1; | 180 const SkPoint pt2 = *pt0+v0, pt3 = *
pt1+v1; |
181 if (intersection(*pt0, pt2, *pt1, pt
3, miterPt[0]) != | 181 if (intersection(*pt0, pt2, *pt1, pt
3, miterPt[0]) != |
182 kNone_IntersectionType) { | 182 kNone_IntersectionType) { |
183 SkPoint miterPt0 = miterPt[0] -
*pt0; | 183 SkPoint miterPt0 = miterPt[0] -
*pt0; |
184 SkPoint miterPt1 = miterPt[0] -
*pt1; | 184 SkPoint miterPt1 = miterPt[0] -
*pt1; |
185 SkScalar sqDist0 = miterPt0.dot(
miterPt0); | 185 SkScalar sqDist0 = miterPt0.dot(
miterPt0); |
186 SkScalar sqDist1 = miterPt1.dot(
miterPt1); | 186 SkScalar sqDist1 = miterPt1.dot(
miterPt1); |
187 const SkScalar rSq = | 187 const SkScalar rSq = radius*radi
us / sinHalfAngleSq; |
188 SkScalarDiv(SkScalarMul(
radius, radius), | |
189 sinHalfAngle
Sq); | |
190 const SkScalar sqRLimit = | 188 const SkScalar sqRLimit = |
191 SkScalarMul(sqMiterLimit
, rSq); | 189 SkScalarMul(sqMiterLimit
, rSq); |
192 if (sqDist0 > sqRLimit || sqDist
1 > sqRLimit) { | 190 if (sqDist0 > sqRLimit || sqDist
1 > sqRLimit) { |
193 if (sqDist1 > sqRLimit) { | 191 if (sqDist1 > sqRLimit) { |
194 v1.setLength(SkScalarSqr
t(sqRLimit)); | 192 v1.setLength(SkScalarSqr
t(sqRLimit)); |
195 miterPt[1] = *pt1+v1; | 193 miterPt[1] = *pt1+v1; |
196 } else { | 194 } else { |
197 miterPt[1] = miterPt[0]; | 195 miterPt[1] = miterPt[0]; |
198 } | 196 } |
199 if (sqDist0 > sqRLimit) { | 197 if (sqDist0 > sqRLimit) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (vCount > 0) { | 289 if (vCount > 0) { |
292 target->drawIndexed(kTriangles_GrPrimitiveType, | 290 target->drawIndexed(kTriangles_GrPrimitiveType, |
293 0, // start vertex | 291 0, // start vertex |
294 0, // start index | 292 0, // start index |
295 vCount, | 293 vCount, |
296 iCount); | 294 iCount); |
297 } | 295 } |
298 | 296 |
299 return true; | 297 return true; |
300 } | 298 } |
OLD | NEW |