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 "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 | 9 |
10 void SkIntersections::append(const SkIntersections& i) { | 10 void SkIntersections::append(const SkIntersections& i) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 double oldOne = fT[0][index]; | 72 double oldOne = fT[0][index]; |
73 double oldTwo = fT[1][index]; | 73 double oldTwo = fT[1][index]; |
74 if (one == oldOne && two == oldTwo) { | 74 if (one == oldOne && two == oldTwo) { |
75 return -1; | 75 return -1; |
76 } | 76 } |
77 if (more_roughly_equal(oldOne, one) && more_roughly_equal(oldTwo, two))
{ | 77 if (more_roughly_equal(oldOne, one) && more_roughly_equal(oldTwo, two))
{ |
78 if ((precisely_zero(one) && !precisely_zero(oldOne)) | 78 if ((precisely_zero(one) && !precisely_zero(oldOne)) |
79 || (precisely_equal(one, 1) && !precisely_equal(oldOne, 1)) | 79 || (precisely_equal(one, 1) && !precisely_equal(oldOne, 1)) |
80 || (precisely_zero(two) && !precisely_zero(oldTwo)) | 80 || (precisely_zero(two) && !precisely_zero(oldTwo)) |
81 || (precisely_equal(two, 1) && !precisely_equal(oldTwo, 1)))
{ | 81 || (precisely_equal(two, 1) && !precisely_equal(oldTwo, 1)))
{ |
82 SkASSERT(one >= 0 && one <= 1); | |
83 SkASSERT(two >= 0 && two <= 1); | |
84 fT[0][index] = one; | 82 fT[0][index] = one; |
85 fT[1][index] = two; | 83 fT[1][index] = two; |
86 fPt[index] = pt; | 84 fPt[index] = pt; |
87 } | 85 } |
88 return -1; | 86 return -1; |
89 } | 87 } |
90 #if ONE_OFF_DEBUG | 88 #if ONE_OFF_DEBUG |
91 if (pt.roughlyEqual(fPt[index])) { | 89 if (pt.roughlyEqual(fPt[index])) { |
92 SkDebugf("%s t=%1.9g pts roughly equal\n", __FUNCTION__, one); | 90 SkDebugf("%s t=%1.9g pts roughly equal\n", __FUNCTION__, one); |
93 } | 91 } |
(...skipping 12 matching lines...) Expand all Loading... |
106 if (remaining > 0) { | 104 if (remaining > 0) { |
107 memmove(&fPt[index + 1], &fPt[index], sizeof(fPt[0]) * remaining); | 105 memmove(&fPt[index + 1], &fPt[index], sizeof(fPt[0]) * remaining); |
108 memmove(&fPt2[index + 1], &fPt2[index], sizeof(fPt2[0]) * remaining); | 106 memmove(&fPt2[index + 1], &fPt2[index], sizeof(fPt2[0]) * remaining); |
109 memmove(&fT[0][index + 1], &fT[0][index], sizeof(fT[0][0]) * remaining); | 107 memmove(&fT[0][index + 1], &fT[0][index], sizeof(fT[0][0]) * remaining); |
110 memmove(&fT[1][index + 1], &fT[1][index], sizeof(fT[1][0]) * remaining); | 108 memmove(&fT[1][index + 1], &fT[1][index], sizeof(fT[1][0]) * remaining); |
111 int clearMask = ~((1 << index) - 1); | 109 int clearMask = ~((1 << index) - 1); |
112 fIsCoincident[0] += fIsCoincident[0] & clearMask; | 110 fIsCoincident[0] += fIsCoincident[0] & clearMask; |
113 fIsCoincident[1] += fIsCoincident[1] & clearMask; | 111 fIsCoincident[1] += fIsCoincident[1] & clearMask; |
114 } | 112 } |
115 fPt[index] = pt; | 113 fPt[index] = pt; |
116 SkASSERT(one >= 0 && one <= 1); | |
117 SkASSERT(two >= 0 && two <= 1); | |
118 fT[0][index] = one; | 114 fT[0][index] = one; |
119 fT[1][index] = two; | 115 fT[1][index] = two; |
120 ++fUsed; | 116 ++fUsed; |
121 return index; | 117 return index; |
122 } | 118 } |
123 | 119 |
124 void SkIntersections::insertNear(double one, double two, const SkDPoint& pt1, co
nst SkDPoint& pt2) { | 120 void SkIntersections::insertNear(double one, double two, const SkDPoint& pt1, co
nst SkDPoint& pt2) { |
125 SkASSERT(one == 0 || one == 1); | 121 SkASSERT(one == 0 || one == 1); |
126 SkASSERT(two == 0 || two == 1); | 122 SkASSERT(two == 0 || two == 1); |
127 SkASSERT(pt1 != pt2); | 123 SkASSERT(pt1 != pt2); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 164 |
169 void SkIntersections::removeOne(int index) { | 165 void SkIntersections::removeOne(int index) { |
170 int remaining = --fUsed - index; | 166 int remaining = --fUsed - index; |
171 if (remaining <= 0) { | 167 if (remaining <= 0) { |
172 return; | 168 return; |
173 } | 169 } |
174 memmove(&fPt[index], &fPt[index + 1], sizeof(fPt[0]) * remaining); | 170 memmove(&fPt[index], &fPt[index + 1], sizeof(fPt[0]) * remaining); |
175 memmove(&fPt2[index], &fPt2[index + 1], sizeof(fPt2[0]) * remaining); | 171 memmove(&fPt2[index], &fPt2[index + 1], sizeof(fPt2[0]) * remaining); |
176 memmove(&fT[0][index], &fT[0][index + 1], sizeof(fT[0][0]) * remaining); | 172 memmove(&fT[0][index], &fT[0][index + 1], sizeof(fT[0][0]) * remaining); |
177 memmove(&fT[1][index], &fT[1][index + 1], sizeof(fT[1][0]) * remaining); | 173 memmove(&fT[1][index], &fT[1][index + 1], sizeof(fT[1][0]) * remaining); |
178 // SkASSERT(fIsCoincident[0] == 0); | 174 SkASSERT(fIsCoincident[0] == 0); |
179 int coBit = fIsCoincident[0] & (1 << index); | 175 int coBit = fIsCoincident[0] & (1 << index); |
180 fIsCoincident[0] -= ((fIsCoincident[0] >> 1) & ~((1 << index) - 1)) + coBit; | 176 fIsCoincident[0] -= ((fIsCoincident[0] >> 1) & ~((1 << index) - 1)) + coBit; |
181 SkASSERT(!(coBit ^ (fIsCoincident[1] & (1 << index)))); | 177 SkASSERT(!(coBit ^ (fIsCoincident[1] & (1 << index)))); |
182 fIsCoincident[1] -= ((fIsCoincident[1] >> 1) & ~((1 << index) - 1)) + coBit; | 178 fIsCoincident[1] -= ((fIsCoincident[1] >> 1) & ~((1 << index) - 1)) + coBit; |
183 } | 179 } |
184 | 180 |
185 void SkIntersections::swapPts() { | 181 void SkIntersections::swapPts() { |
186 int index; | 182 int index; |
187 for (index = 0; index < fUsed; ++index) { | 183 for (index = 0; index < fUsed; ++index) { |
188 SkTSwap(fT[0][index], fT[1][index]); | 184 SkTSwap(fT[0][index], fT[1][index]); |
(...skipping 13 matching lines...) Expand all Loading... |
202 quad.set(a); | 198 quad.set(a); |
203 return vertical(quad, top, bottom, x, flipped); | 199 return vertical(quad, top, bottom, x, flipped); |
204 } | 200 } |
205 | 201 |
206 int SkIntersections::verticalCubic(const SkPoint a[4], SkScalar top, SkScalar bo
ttom, | 202 int SkIntersections::verticalCubic(const SkPoint a[4], SkScalar top, SkScalar bo
ttom, |
207 SkScalar x, bool flipped) { | 203 SkScalar x, bool flipped) { |
208 SkDCubic cubic; | 204 SkDCubic cubic; |
209 cubic.set(a); | 205 cubic.set(a); |
210 return vertical(cubic, top, bottom, x, flipped); | 206 return vertical(cubic, top, bottom, x, flipped); |
211 } | 207 } |
OLD | NEW |