OLD | NEW |
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 #include "SkRect.h" | 9 #include "SkRect.h" |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 54 } |
55 | 55 |
56 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { | 56 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { |
57 SkASSERT((pts && count > 0) || count == 0); | 57 SkASSERT((pts && count > 0) || count == 0); |
58 | 58 |
59 bool isFinite = true; | 59 bool isFinite = true; |
60 | 60 |
61 if (count <= 0) { | 61 if (count <= 0) { |
62 sk_bzero(this, sizeof(SkRect)); | 62 sk_bzero(this, sizeof(SkRect)); |
63 } else { | 63 } else { |
64 #if 0 | |
65 SkScalar l, t, r, b; | |
66 | |
67 l = r = pts[0].fX; | |
68 t = b = pts[0].fY; | |
69 | |
70 // If all of the points are finite, accum should stay 0. If we encounter | |
71 // a NaN or infinity, then accum should become NaN. | |
72 float accum = 0; | |
73 accum *= l; accum *= t; | |
74 | |
75 for (int i = 1; i < count; i++) { | |
76 SkScalar x = pts[i].fX; | |
77 SkScalar y = pts[i].fY; | |
78 | |
79 accum *= x; accum *= y; | |
80 | |
81 // we use if instead of if/else, so we can generate min/max | |
82 // float instructions (at least on SSE) | |
83 if (x < l) l = x; | |
84 if (x > r) r = x; | |
85 | |
86 if (y < t) t = y; | |
87 if (y > b) b = y; | |
88 } | |
89 | |
90 SkASSERT(!accum || !SkScalarIsFinite(accum)); | |
91 accum = 0; | |
92 if (accum) { | |
93 l = t = r = b = 0; | |
94 isFinite = false; | |
95 } | |
96 this->set(l, t, r, b); | |
97 #else | |
98 Sk4f min, max, accum; | 64 Sk4f min, max, accum; |
99 | 65 |
100 if (count & 1) { | 66 if (count & 1) { |
101 min = Sk4f(pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY); | 67 min = Sk4f(pts[0].fX, pts[0].fY, pts[0].fX, pts[0].fY); |
102 pts += 1; | 68 pts += 1; |
103 count -= 1; | 69 count -= 1; |
104 } else { | 70 } else { |
105 min = Sk4f::Load(&pts[0].fX); | 71 min = Sk4f::Load(&pts[0].fX); |
106 pts += 2; | 72 pts += 2; |
107 count -= 2; | 73 count -= 2; |
(...skipping 19 matching lines...) Expand all Loading... |
127 float minArray[4], maxArray[4]; | 93 float minArray[4], maxArray[4]; |
128 min.store(minArray); | 94 min.store(minArray); |
129 max.store(maxArray); | 95 max.store(maxArray); |
130 this->set(SkTMin(minArray[0], minArray[2]), SkTMin(minArray[1], minA
rray[3]), | 96 this->set(SkTMin(minArray[0], minArray[2]), SkTMin(minArray[1], minA
rray[3]), |
131 SkTMax(maxArray[0], maxArray[2]), SkTMax(maxArray[1], maxA
rray[3])); | 97 SkTMax(maxArray[0], maxArray[2]), SkTMax(maxArray[1], maxA
rray[3])); |
132 } else { | 98 } else { |
133 // we hit a non-finite value, so zero everything and return false | 99 // we hit a non-finite value, so zero everything and return false |
134 this->setEmpty(); | 100 this->setEmpty(); |
135 isFinite = false; | 101 isFinite = false; |
136 } | 102 } |
137 #endif | |
138 } | 103 } |
139 | |
140 return isFinite; | 104 return isFinite; |
141 } | 105 } |
142 | 106 |
143 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ | 107 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ |
144 SkScalar L = SkMaxScalar(al, bl); \ | 108 SkScalar L = SkMaxScalar(al, bl); \ |
145 SkScalar R = SkMinScalar(ar, br); \ | 109 SkScalar R = SkMinScalar(ar, br); \ |
146 SkScalar T = SkMaxScalar(at, bt); \ | 110 SkScalar T = SkMaxScalar(at, bt); \ |
147 SkScalar B = SkMinScalar(ab, bb); \ | 111 SkScalar B = SkMinScalar(ab, bb); \ |
148 do { if (L >= R || T >= B) return false; } while (0) | 112 do { if (L >= R || T >= B) return false; } while (0) |
149 | 113 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 SkString strL, strT, strR, strB; | 169 SkString strL, strT, strR, strB; |
206 SkAppendScalarDec(&strL, fLeft); | 170 SkAppendScalarDec(&strL, fLeft); |
207 SkAppendScalarDec(&strT, fTop); | 171 SkAppendScalarDec(&strT, fTop); |
208 SkAppendScalarDec(&strR, fRight); | 172 SkAppendScalarDec(&strR, fRight); |
209 SkAppendScalarDec(&strB, fBottom); | 173 SkAppendScalarDec(&strB, fBottom); |
210 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", | 174 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", |
211 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); | 175 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); |
212 } | 176 } |
213 SkDebugf("%s\n", line.c_str()); | 177 SkDebugf("%s\n", line.c_str()); |
214 } | 178 } |
OLD | NEW |