Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: src/core/SkGeometry.cpp

Issue 48783002: perpendicular round rects; fuzzy convexity (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: fix conflict Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 (base[0] > base[4] && value < base[2])) // should root have been 1 1249 (base[0] > base[4] && value < base[2])) // should root have been 1
1250 { 1250 {
1251 dest[0] = quad[1]; 1251 dest[0] = quad[1];
1252 dest[1].set(x, y); 1252 dest[1].set(x, y);
1253 return true; 1253 return true;
1254 } 1254 }
1255 } 1255 }
1256 return false; 1256 return false;
1257 } 1257 }
1258 1258
1259 #ifdef SK_SCALAR_IS_FLOAT 1259 static const SkPoint gQuadCirclePts[kSkBuildQuadArcStorage] = {
1260 // The mid point of the quadratic arc approximation is half way between the two
1261 // control points. The float epsilon adjustment moves the on curve point out by
1262 // two bits, distributing the convex test error between the round rect approxima tion
1263 // and the convex cross product sign equality test.
1264 #define SK_MID_RRECT_OFFSET (SK_Scalar1 + SK_ScalarTanPIOver8 + FLT_EPSILON * 4) / 2
1265 { SK_Scalar1, 0 },
1266 { SK_Scalar1, SK_ScalarTanPIOver8 },
1267 { SK_MID_RRECT_OFFSET, SK_MID_RRECT_OFFSET },
1268 { SK_ScalarTanPIOver8, SK_Scalar1 },
1260 1269
1261 // Due to floating point issues (i.e., 1.0f - SK_ScalarRoot2Over2 != 1270 { 0, SK_Scalar1 },
1262 // SK_ScalarRoot2Over2 - SK_ScalarTanPIOver8), the "correct" off curve 1271 { -SK_ScalarTanPIOver8, SK_Scalar1 },
1263 // control points cause the quadratic circle approximation to be concave. 1272 { -SK_MID_RRECT_OFFSET, SK_MID_RRECT_OFFSET },
1264 // SK_OffEps is used to pull in the off-curve control points a bit 1273 { -SK_Scalar1, SK_ScalarTanPIOver8 },
1265 // to make the quadratic approximation convex.
1266 // Pulling the off-curve controls points in is preferable to pushing some
1267 // of the on-curve points off.
1268 #define SK_OffEps 0.0001f
1269 #else
1270 #define SK_OffEps 0
1271 #endif
1272 1274
1275 { -SK_Scalar1, 0 },
1276 { -SK_Scalar1, -SK_ScalarTanPIOver8 },
1277 { -SK_MID_RRECT_OFFSET, -SK_MID_RRECT_OFFSET },
1278 { -SK_ScalarTanPIOver8, -SK_Scalar1 },
1273 1279
1274 static const SkPoint gQuadCirclePts[kSkBuildQuadArcStorage] = { 1280 { 0, -SK_Scalar1 },
1275 { SK_Scalar1, 0 }, 1281 { SK_ScalarTanPIOver8, -SK_Scalar1 },
1276 { SK_Scalar1 - SK_OffEps, SK_ScalarTanPIOver8 - SK_OffEps }, 1282 { SK_MID_RRECT_OFFSET, -SK_MID_RRECT_OFFSET },
1277 { SK_ScalarRoot2Over2, SK_ScalarRoot2Over2 }, 1283 { SK_Scalar1, -SK_ScalarTanPIOver8 },
1278 { SK_ScalarTanPIOver8 - SK_OffEps, SK_Scalar1 - SK_OffEps },
1279 1284
1280 { 0, SK_Scalar1 }, 1285 { SK_Scalar1, 0 }
1281 { -SK_ScalarTanPIOver8 + SK_OffEps,SK_Scalar1 - SK_OffEps }, 1286 #undef SK_MID_RRECT_OFFSET
1282 { -SK_ScalarRoot2Over2, SK_ScalarRoot2Over2 },
1283 { -SK_Scalar1 + SK_OffEps, SK_ScalarTanPIOver8 - SK_OffEps },
1284
1285 { -SK_Scalar1, 0 },
1286 { -SK_Scalar1 + SK_OffEps, -SK_ScalarTanPIOver8 + SK_OffEps },
1287 { -SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2 },
1288 { -SK_ScalarTanPIOver8 + SK_OffEps,-SK_Scalar1 + SK_OffEps },
1289
1290 { 0, -SK_Scalar1 },
1291 { SK_ScalarTanPIOver8 - SK_OffEps, -SK_Scalar1 + SK_OffEps },
1292 { SK_ScalarRoot2Over2, -SK_ScalarRoot2Over2 },
1293 { SK_Scalar1 - SK_OffEps, -SK_ScalarTanPIOver8 + SK_OffEps },
1294
1295 { SK_Scalar1, 0 }
1296 }; 1287 };
1297 1288
1298 int SkBuildQuadArc(const SkVector& uStart, const SkVector& uStop, 1289 int SkBuildQuadArc(const SkVector& uStart, const SkVector& uStop,
1299 SkRotationDirection dir, const SkMatrix* userMatrix, 1290 SkRotationDirection dir, const SkMatrix* userMatrix,
1300 SkPoint quadPoints[]) 1291 SkPoint quadPoints[])
1301 { 1292 {
1302 // rotate by x,y so that uStart is (1.0) 1293 // rotate by x,y so that uStart is (1.0)
1303 SkScalar x = SkPoint::DotProduct(uStart, uStop); 1294 SkScalar x = SkPoint::DotProduct(uStart, uStop);
1304 SkScalar y = SkPoint::CrossProduct(uStart, uStop); 1295 SkScalar y = SkPoint::CrossProduct(uStart, uStop);
1305 1296
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 } 1641 }
1651 if (this->findYExtrema(&t)) { 1642 if (this->findYExtrema(&t)) {
1652 this->evalAt(t, &pts[count++]); 1643 this->evalAt(t, &pts[count++]);
1653 } 1644 }
1654 bounds->set(pts, count); 1645 bounds->set(pts, count);
1655 } 1646 }
1656 1647
1657 void SkConic::computeFastBounds(SkRect* bounds) const { 1648 void SkConic::computeFastBounds(SkRect* bounds) const {
1658 bounds->set(fPts, 3); 1649 bounds->set(fPts, 3);
1659 } 1650 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/core/SkPath.cpp » ('j') | src/core/SkPath.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698