OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkLineClipper.h" | 8 #include "SkLineClipper.h" |
9 | 9 |
10 template <typename T> T pin_unsorted(T value, T limit0, T limit1) { | 10 template <typename T> T pin_unsorted(T value, T limit0, T limit1) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static inline bool containsNoEmptyCheck(const SkRect& outer, | 71 static inline bool containsNoEmptyCheck(const SkRect& outer, |
72 const SkRect& inner) { | 72 const SkRect& inner) { |
73 return outer.fLeft <= inner.fLeft && outer.fTop <= inner.fTop && | 73 return outer.fLeft <= inner.fLeft && outer.fTop <= inner.fTop && |
74 outer.fRight >= inner.fRight && outer.fBottom >= inner.fBottom; | 74 outer.fRight >= inner.fRight && outer.fBottom >= inner.fBottom; |
75 } | 75 } |
76 | 76 |
77 bool SkLineClipper::IntersectLine(const SkPoint src[2], const SkRect& clip, | 77 bool SkLineClipper::IntersectLine(const SkPoint src[2], const SkRect& clip, |
78 SkPoint dst[2]) { | 78 SkPoint dst[2]) { |
79 SkRect bounds; | 79 SkRect bounds; |
80 | 80 |
81 bounds.set(src, 2); | 81 bounds.set(src[0], src[1]); |
82 if (containsNoEmptyCheck(clip, bounds)) { | 82 if (containsNoEmptyCheck(clip, bounds)) { |
83 if (src != dst) { | 83 if (src != dst) { |
84 memcpy(dst, src, 2 * sizeof(SkPoint)); | 84 memcpy(dst, src, 2 * sizeof(SkPoint)); |
85 } | 85 } |
86 return true; | 86 return true; |
87 } | 87 } |
88 // check for no overlap, and only permit coincident edges if the line | 88 // check for no overlap, and only permit coincident edges if the line |
89 // and the edge are colinear | 89 // and the edge are colinear |
90 if (nestedLT(bounds.fRight, clip.fLeft, bounds.width()) || | 90 if (nestedLT(bounds.fRight, clip.fLeft, bounds.width()) || |
91 nestedLT(clip.fRight, bounds.fLeft, bounds.width()) || | 91 nestedLT(clip.fRight, bounds.fLeft, bounds.width()) || |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return false; | 130 return false; |
131 } | 131 } |
132 | 132 |
133 if (tmp[index0].fX < clip.fLeft) { | 133 if (tmp[index0].fX < clip.fLeft) { |
134 tmp[index0].set(clip.fLeft, sect_with_vertical(src, clip.fLeft)); | 134 tmp[index0].set(clip.fLeft, sect_with_vertical(src, clip.fLeft)); |
135 } | 135 } |
136 if (tmp[index1].fX > clip.fRight) { | 136 if (tmp[index1].fX > clip.fRight) { |
137 tmp[index1].set(clip.fRight, sect_with_vertical(src, clip.fRight)); | 137 tmp[index1].set(clip.fRight, sect_with_vertical(src, clip.fRight)); |
138 } | 138 } |
139 #ifdef SK_DEBUG | 139 #ifdef SK_DEBUG |
140 bounds.set(tmp, 2); | 140 bounds.set(tmp[0], tmp[1]); |
141 SkASSERT(containsNoEmptyCheck(clip, bounds)); | 141 SkASSERT(containsNoEmptyCheck(clip, bounds)); |
142 #endif | 142 #endif |
143 memcpy(dst, tmp, sizeof(tmp)); | 143 memcpy(dst, tmp, sizeof(tmp)); |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
148 // return value between the two limits, where the limits are either ascending | 148 // return value between the two limits, where the limits are either ascending |
149 // or descending. | 149 // or descending. |
150 static bool is_between_unsorted(SkScalar value, | 150 static bool is_between_unsorted(SkScalar value, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 if (reverse) { | 278 if (reverse) { |
279 // copy the pts in reverse order to maintain winding order | 279 // copy the pts in reverse order to maintain winding order |
280 for (int i = 0; i <= lineCount; i++) { | 280 for (int i = 0; i <= lineCount; i++) { |
281 lines[lineCount - i] = result[i]; | 281 lines[lineCount - i] = result[i]; |
282 } | 282 } |
283 } else { | 283 } else { |
284 memcpy(lines, result, (lineCount + 1) * sizeof(SkPoint)); | 284 memcpy(lines, result, (lineCount + 1) * sizeof(SkPoint)); |
285 } | 285 } |
286 return lineCount; | 286 return lineCount; |
287 } | 287 } |
OLD | NEW |