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

Side by Side Diff: src/utils/SkDashPath.cpp

Issue 1766243004: don't create zero length intervals (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months 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
« no previous file with comments | « gm/bug530095.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkDashPathPriv.h" 8 #include "SkDashPathPriv.h"
9 #include "SkPathMeasure.h" 9 #include "SkPathMeasure.h"
10 #include "SkStrokeRec.h" 10 #include "SkStrokeRec.h"
11 11
12 static inline int is_even(int x) { 12 static inline int is_even(int x) {
13 return !(x & 1); 13 return !(x & 1);
14 } 14 }
15 15
16 static SkScalar find_first_interval(const SkScalar intervals[], SkScalar phase, 16 static SkScalar find_first_interval(const SkScalar intervals[], SkScalar phase,
17 int32_t* index, int count) { 17 int32_t* index, int count) {
18 for (int i = 0; i < count; ++i) { 18 for (int i = 0; i < count; ++i) {
19 if (phase > intervals[i]) { 19 SkScalar gap = intervals[i];
20 phase -= intervals[i]; 20 if (phase > gap || (phase == gap && gap)) {
21 phase -= gap;
21 } else { 22 } else {
22 *index = i; 23 *index = i;
23 return intervals[i] - phase; 24 return gap - phase;
24 } 25 }
25 } 26 }
26 // If we get here, phase "appears" to be larger than our length. This 27 // If we get here, phase "appears" to be larger than our length. This
27 // shouldn't happen with perfect precision, but we can accumulate errors 28 // shouldn't happen with perfect precision, but we can accumulate errors
28 // during the initial length computation (rounding can make our sum be too 29 // during the initial length computation (rounding can make our sum be too
29 // big or too small. In that event, we just have to eat the error here. 30 // big or too small. In that event, we just have to eat the error here.
30 *index = 0; 31 *index = 0;
31 return intervals[0]; 32 return intervals[0];
32 } 33 }
33 34
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec , 322 bool SkDashPath::FilterDashPath(SkPath* dst, const SkPath& src, SkStrokeRec* rec ,
322 const SkRect* cullRect, const SkPathEffect::Dash Info& info) { 323 const SkRect* cullRect, const SkPathEffect::Dash Info& info) {
323 SkScalar initialDashLength = 0; 324 SkScalar initialDashLength = 0;
324 int32_t initialDashIndex = 0; 325 int32_t initialDashIndex = 0;
325 SkScalar intervalLength = 0; 326 SkScalar intervalLength = 0;
326 CalcDashParameters(info.fPhase, info.fIntervals, info.fCount, 327 CalcDashParameters(info.fPhase, info.fIntervals, info.fCount,
327 &initialDashLength, &initialDashIndex, &intervalLength); 328 &initialDashLength, &initialDashIndex, &intervalLength);
328 return FilterDashPath(dst, src, rec, cullRect, info.fIntervals, info.fCount, initialDashLength, 329 return FilterDashPath(dst, src, rec, cullRect, info.fIntervals, info.fCount, initialDashLength,
329 initialDashIndex, intervalLength); 330 initialDashIndex, intervalLength);
330 } 331 }
OLDNEW
« no previous file with comments | « gm/bug530095.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698