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

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

Issue 48783002: perpendicular round rects; fuzzy convexity (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: use std skia types 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
« src/core/SkGeometry.cpp ('K') | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBuffer.h" 10 #include "SkBuffer.h"
(...skipping 2265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 SkASSERT(mask == fSegmentMask); 2276 SkASSERT(mask == fSegmentMask);
2277 #endif // SK_DEBUG_PATH 2277 #endif // SK_DEBUG_PATH
2278 } 2278 }
2279 #endif // SK_DEBUG 2279 #endif // SK_DEBUG
2280 2280
2281 /////////////////////////////////////////////////////////////////////////////// 2281 ///////////////////////////////////////////////////////////////////////////////
2282 2282
2283 static int sign(SkScalar x) { return x < 0; } 2283 static int sign(SkScalar x) { return x < 0; }
2284 #define kValueNeverReturnedBySign 2 2284 #define kValueNeverReturnedBySign 2
2285 2285
2286 static int CrossProductSign(const SkVector& a, const SkVector& b) { 2286 static bool AlmostEqual(SkScalar compA, SkScalar compB) {
2287 return SkScalarSignAsInt(SkPoint::CrossProduct(a, b)); 2287 const int epsilon = 16;
2288 if (!SkScalarIsFinite(compA) || !SkScalarIsFinite(compB)) {
2289 return false;
2290 }
2291 if (sk_float_abs(compA) <= FLT_EPSILON && sk_float_abs(compB) <= FLT_EPSILON ) {
2292 return true;
2293 }
2294 int aBits = SkFloatAs2sCompliment(compA);
2295 int bBits = SkFloatAs2sCompliment(compB);
2296 return aBits < bBits + epsilon && bBits < aBits + epsilon;
2288 } 2297 }
2289 2298
2290 // only valid for a single contour 2299 // only valid for a single contour
2291 struct Convexicator { 2300 struct Convexicator {
2292 Convexicator() 2301 Convexicator()
2293 : fPtCount(0) 2302 : fPtCount(0)
2294 , fConvexity(SkPath::kConvex_Convexity) 2303 , fConvexity(SkPath::kConvex_Convexity)
2295 , fDirection(SkPath::kUnknown_Direction) { 2304 , fDirection(SkPath::kUnknown_Direction) {
2296 fSign = 0; 2305 fSign = 0;
2297 // warnings 2306 // warnings
(...skipping 15 matching lines...) Expand all
2313 if (SkPath::kConcave_Convexity == fConvexity) { 2322 if (SkPath::kConcave_Convexity == fConvexity) {
2314 return; 2323 return;
2315 } 2324 }
2316 2325
2317 if (0 == fPtCount) { 2326 if (0 == fPtCount) {
2318 fCurrPt = pt; 2327 fCurrPt = pt;
2319 ++fPtCount; 2328 ++fPtCount;
2320 } else { 2329 } else {
2321 SkVector vec = pt - fCurrPt; 2330 SkVector vec = pt - fCurrPt;
2322 if (vec.fX || vec.fY) { 2331 if (vec.fX || vec.fY) {
2332 fLastPt = fCurrPt;
2323 fCurrPt = pt; 2333 fCurrPt = pt;
2324 if (++fPtCount == 2) { 2334 if (++fPtCount == 2) {
2325 fFirstVec = fVec1 = vec; 2335 fFirstVec = fVec1 = vec;
2326 } else { 2336 } else {
2327 SkASSERT(fPtCount > 2); 2337 SkASSERT(fPtCount > 2);
2328 this->addVec(vec); 2338 this->addVec(vec);
2329 } 2339 }
2330 2340
2331 int sx = sign(vec.fX); 2341 int sx = sign(vec.fX);
2332 int sy = sign(vec.fY); 2342 int sy = sign(vec.fY);
(...skipping 13 matching lines...) Expand all
2346 if (fPtCount > 2) { 2356 if (fPtCount > 2) {
2347 this->addVec(fFirstVec); 2357 this->addVec(fFirstVec);
2348 } 2358 }
2349 } 2359 }
2350 2360
2351 private: 2361 private:
2352 void addVec(const SkVector& vec) { 2362 void addVec(const SkVector& vec) {
2353 SkASSERT(vec.fX || vec.fY); 2363 SkASSERT(vec.fX || vec.fY);
2354 fVec0 = fVec1; 2364 fVec0 = fVec1;
2355 fVec1 = vec; 2365 fVec1 = vec;
2356 int sign = CrossProductSign(fVec0, fVec1); 2366 SkScalar cross = SkPoint::CrossProduct(fVec0, fVec1);
2367 SkScalar smallest = SkTMin(fCurrPt.fX, SkTMin(fCurrPt.fY, SkTMin(fLastPt .fX, fLastPt.fY)));
2368 SkScalar largest = SkTMax(fCurrPt.fX, SkTMax(fCurrPt.fY, SkTMax(fLastPt. fX, fLastPt.fY)));
2369 largest = SkTMax(largest, -smallest);
2370 int sign = AlmostEqual(largest, largest + cross) ? 0 : SkScalarSignAsInt (cross);
2357 if (0 == fSign) { 2371 if (0 == fSign) {
2358 fSign = sign; 2372 fSign = sign;
2359 if (1 == sign) { 2373 if (1 == sign) {
2360 fDirection = SkPath::kCW_Direction; 2374 fDirection = SkPath::kCW_Direction;
2361 } else if (-1 == sign) { 2375 } else if (-1 == sign) {
2362 fDirection = SkPath::kCCW_Direction; 2376 fDirection = SkPath::kCCW_Direction;
2363 } 2377 }
2364 } else if (sign) { 2378 } else if (sign) {
2365 if (fSign != sign) { 2379 if (fSign != sign) {
2366 fConvexity = SkPath::kConcave_Convexity; 2380 fConvexity = SkPath::kConcave_Convexity;
2367 fDirection = SkPath::kUnknown_Direction; 2381 fDirection = SkPath::kUnknown_Direction;
2368 } 2382 }
2369 } 2383 }
2370 } 2384 }
2371 2385
2386 SkPoint fLastPt;
2372 SkPoint fCurrPt; 2387 SkPoint fCurrPt;
2373 SkVector fVec0, fVec1, fFirstVec; 2388 SkVector fVec0, fVec1, fFirstVec;
2374 int fPtCount; // non-degenerate points 2389 int fPtCount; // non-degenerate points
2375 int fSign; 2390 int fSign;
2376 SkPath::Convexity fConvexity; 2391 SkPath::Convexity fConvexity;
2377 SkPath::Direction fDirection; 2392 SkPath::Direction fDirection;
2378 int fDx, fDy, fSx, fSy; 2393 int fDx, fDy, fSx, fSy;
2379 }; 2394 };
2380 2395
2381 SkPath::Convexity SkPath::internalGetConvexity() const { 2396 SkPath::Convexity SkPath::internalGetConvexity() const {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
3002 switch (this->getFillType()) { 3017 switch (this->getFillType()) {
3003 case SkPath::kEvenOdd_FillType: 3018 case SkPath::kEvenOdd_FillType:
3004 case SkPath::kInverseEvenOdd_FillType: 3019 case SkPath::kInverseEvenOdd_FillType:
3005 w &= 1; 3020 w &= 1;
3006 break; 3021 break;
3007 default: 3022 default:
3008 break; 3023 break;
3009 } 3024 }
3010 return SkToBool(w); 3025 return SkToBool(w);
3011 } 3026 }
OLDNEW
« src/core/SkGeometry.cpp ('K') | « src/core/SkGeometry.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698