OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 <cmath> | 8 #include <cmath> |
9 #include "SkBuffer.h" | 9 #include "SkBuffer.h" |
10 #include "SkCubicClipper.h" | 10 #include "SkCubicClipper.h" |
(...skipping 3227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3238 } | 3238 } |
3239 } while (!done); | 3239 } while (!done); |
3240 return SkToBool(tangents.count()) ^ isInverse; | 3240 return SkToBool(tangents.count()) ^ isInverse; |
3241 } | 3241 } |
3242 | 3242 |
3243 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2, | 3243 int SkPath::ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPo int& p2, |
3244 SkScalar w, SkPoint pts[], int pow2) { | 3244 SkScalar w, SkPoint pts[], int pow2) { |
3245 const SkConic conic(p0, p1, p2, w); | 3245 const SkConic conic(p0, p1, p2, w); |
3246 return conic.chopIntoQuadsPOW2(pts, pow2); | 3246 return conic.chopIntoQuadsPOW2(pts, pow2); |
3247 } | 3247 } |
3248 | |
3249 bool SkPathPriv::IsSimpleClosedRect(const SkPath& path, SkRect* rect, SkPath::Di rection* direction, | |
3250 unsigned* start) { | |
robertphillips
2016/05/31 21:48:36
Would it be worth having a quick out for is there
bsalomon
2016/06/03 14:49:06
Done.
| |
3251 SkPath::RawIter iter(path); | |
3252 SkPoint verbPts[4]; | |
3253 SkPath::Verb v; | |
3254 SkPoint rectPts[5]; | |
3255 int rectPtCnt = 0; | |
3256 while ((v = iter.next(verbPts)) != SkPath::kDone_Verb) { | |
3257 switch (v) { | |
3258 case SkPath::kMove_Verb: | |
3259 if (0 != rectPtCnt) { | |
3260 return false; | |
3261 } | |
3262 rectPts[0] = verbPts[0]; | |
3263 ++rectPtCnt; | |
3264 break; | |
3265 case SkPath::kLine_Verb: | |
3266 if (5 == rectPtCnt) { | |
3267 return false; | |
3268 } | |
3269 rectPts[rectPtCnt] = verbPts[1]; | |
3270 ++rectPtCnt; | |
3271 break; | |
3272 case SkPath::kClose_Verb: | |
3273 if (4 == rectPtCnt) { | |
3274 rectPts[4] = rectPts[0]; | |
3275 rectPtCnt = 5; | |
3276 } | |
3277 break; | |
3278 default: | |
3279 return false; | |
3280 } | |
3281 } | |
robertphillips
2016/05/31 21:48:36
Don't we just want to say "if (rectPtCnt < 5) { re
bsalomon
2016/06/03 14:49:05
Done, nice catch.
| |
3282 SkASSERT(rectPtCnt <= 5); | |
3283 if (rectPts[0] != rectPts[4]) { | |
3284 return false; | |
3285 } | |
3286 int verticalCnt = 0; | |
3287 int horizontalCnt = 0; | |
3288 // dirs are 0 - right, 1 - down, 2 - left, 3 - up. | |
3289 int firstDir; | |
3290 int secondDir; | |
3291 SkRect tempRect; | |
3292 for (int i = 0; i < 4; ++i) { | |
3293 int sameCnt = 0; | |
3294 if (rectPts[i].fX == rectPts[i + 1].fX) { | |
3295 verticalCnt += 1; | |
3296 sameCnt = 1; | |
3297 if (0 == i) { | |
3298 if (rectPts[1].fY > rectPts[0].fY) { | |
3299 firstDir = 1; | |
3300 tempRect.fTop = rectPts[0].fY; | |
3301 tempRect.fBottom = rectPts[1].fY; | |
3302 } else { | |
3303 firstDir = 3; | |
3304 tempRect.fTop = rectPts[1].fY; | |
3305 tempRect.fBottom = rectPts[0].fY; | |
3306 } | |
3307 } else if (1 == i) { | |
3308 if (rectPts[2].fY > rectPts[1].fY) { | |
3309 secondDir = 1; | |
3310 tempRect.fTop = rectPts[1].fY; | |
3311 tempRect.fBottom = rectPts[2].fY; | |
3312 } else { | |
3313 secondDir = 3; | |
3314 tempRect.fTop = rectPts[2].fY; | |
3315 tempRect.fBottom = rectPts[1].fY; | |
3316 } | |
3317 } | |
3318 } | |
3319 if (rectPts[i].fY == rectPts[i + 1].fY) { | |
3320 horizontalCnt += 1; | |
3321 sameCnt += 1; | |
3322 if (0 == i) { | |
3323 if (rectPts[1].fX > rectPts[0].fX) { | |
3324 firstDir = 0; | |
3325 tempRect.fLeft = rectPts[0].fX; | |
3326 tempRect.fRight = rectPts[1].fX; | |
3327 } else { | |
3328 firstDir = 2; | |
3329 tempRect.fLeft = rectPts[1].fX; | |
3330 tempRect.fRight = rectPts[0].fX; | |
3331 } | |
3332 } else if (1 == i) { | |
3333 if (rectPts[2].fX > rectPts[1].fX) { | |
3334 secondDir = 0; | |
3335 tempRect.fLeft = rectPts[1].fX; | |
3336 tempRect.fRight = rectPts[2].fX; | |
3337 } else { | |
3338 secondDir = 2; | |
3339 tempRect.fLeft = rectPts[2].fX; | |
3340 tempRect.fRight = rectPts[1].fX; | |
3341 } | |
3342 } | |
3343 } | |
3344 if (sameCnt != 1) { | |
3345 return false; | |
3346 } | |
3347 } | |
3348 if (2 != horizontalCnt || 2 != verticalCnt) { | |
3349 return false; | |
3350 } | |
3351 // low bit indicates a vertical dir | |
3352 SkASSERT((firstDir ^ secondDir) & 0b1); | |
3353 if (((firstDir + 1) & 0b11) == secondDir) { | |
3354 *direction = SkPath::kCW_Direction; | |
3355 *start = firstDir; | |
3356 } else { | |
3357 SkASSERT(((secondDir + 1) & 0b11) == firstDir); | |
3358 *direction = SkPath::kCCW_Direction; | |
3359 *start = secondDir; | |
3360 } | |
3361 *rect = tempRect; | |
3362 return true; | |
3363 } | |
OLD | NEW |