| 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 | 9 |
| 10 #include "SkRect.h" | 10 #include "SkRect.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { | 73 bool SkRect::setBoundsCheck(const SkPoint pts[], int count) { |
| 74 SkASSERT((pts && count > 0) || count == 0); | 74 SkASSERT((pts && count > 0) || count == 0); |
| 75 | 75 |
| 76 bool isFinite = true; | 76 bool isFinite = true; |
| 77 | 77 |
| 78 if (count <= 0) { | 78 if (count <= 0) { |
| 79 sk_bzero(this, sizeof(SkRect)); | 79 sk_bzero(this, sizeof(SkRect)); |
| 80 } else { | 80 } else { |
| 81 #ifdef SK_SCALAR_SLOW_COMPARES | |
| 82 int32_t l, t, r, b; | |
| 83 | |
| 84 l = r = SkScalarAs2sCompliment(pts[0].fX); | |
| 85 t = b = SkScalarAs2sCompliment(pts[0].fY); | |
| 86 | |
| 87 for (int i = 1; i < count; i++) { | |
| 88 int32_t x = SkScalarAs2sCompliment(pts[i].fX); | |
| 89 int32_t y = SkScalarAs2sCompliment(pts[i].fY); | |
| 90 | |
| 91 if (x < l) l = x; else if (x > r) r = x; | |
| 92 if (y < t) t = y; else if (y > b) b = y; | |
| 93 } | |
| 94 this->set(Sk2sComplimentAsScalar(l), | |
| 95 Sk2sComplimentAsScalar(t), | |
| 96 Sk2sComplimentAsScalar(r), | |
| 97 Sk2sComplimentAsScalar(b)); | |
| 98 #else | |
| 99 SkScalar l, t, r, b; | 81 SkScalar l, t, r, b; |
| 100 | 82 |
| 101 l = r = pts[0].fX; | 83 l = r = pts[0].fX; |
| 102 t = b = pts[0].fY; | 84 t = b = pts[0].fY; |
| 103 | 85 |
| 104 // If all of the points are finite, accum should stay 0. If we encounter | 86 // If all of the points are finite, accum should stay 0. If we encounter |
| 105 // a NaN or infinity, then accum should become NaN. | 87 // a NaN or infinity, then accum should become NaN. |
| 106 SkFLOATCODE(float accum = 0;) | 88 SkFLOATCODE(float accum = 0;) |
| 107 SkFLOATCODE(accum *= l; accum *= t;) | 89 SkFLOATCODE(accum *= l; accum *= t;) |
| 108 | 90 |
| 109 for (int i = 1; i < count; i++) { | 91 for (int i = 1; i < count; i++) { |
| 110 SkScalar x = pts[i].fX; | 92 SkScalar x = pts[i].fX; |
| 111 SkScalar y = pts[i].fY; | 93 SkScalar y = pts[i].fY; |
| 112 | 94 |
| 113 SkFLOATCODE(accum *= x; accum *= y;) | 95 SkFLOATCODE(accum *= x; accum *= y;) |
| 114 | 96 |
| 115 if (x < l) l = x; MINMAX_ELSE if (x > r) r = x; | 97 if (x < l) l = x; MINMAX_ELSE if (x > r) r = x; |
| 116 if (y < t) t = y; MINMAX_ELSE if (y > b) b = y; | 98 if (y < t) t = y; MINMAX_ELSE if (y > b) b = y; |
| 117 } | 99 } |
| 118 | 100 |
| 119 #ifdef SK_SCALAR_IS_FLOAT | |
| 120 SkASSERT(!accum || !SkScalarIsFinite(accum)); | 101 SkASSERT(!accum || !SkScalarIsFinite(accum)); |
| 121 if (accum) { | 102 if (accum) { |
| 122 l = t = r = b = 0; | 103 l = t = r = b = 0; |
| 123 isFinite = false; | 104 isFinite = false; |
| 124 } | 105 } |
| 125 #endif | |
| 126 this->set(l, t, r, b); | 106 this->set(l, t, r, b); |
| 127 #endif | |
| 128 } | 107 } |
| 129 | 108 |
| 130 return isFinite; | 109 return isFinite; |
| 131 } | 110 } |
| 132 | 111 |
| 133 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, | 112 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, |
| 134 SkScalar bottom) { | 113 SkScalar bottom) { |
| 135 if (left < right && top < bottom && !this->isEmpty() && // check for empties | 114 if (left < right && top < bottom && !this->isEmpty() && // check for empties |
| 136 fLeft < right && left < fRight && fTop < bottom && top < fBottom) | 115 fLeft < right && left < fRight && fTop < bottom && top < fBottom) |
| 137 { | 116 { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // if we are empty, just assign | 153 // if we are empty, just assign |
| 175 if (fLeft >= fRight || fTop >= fBottom) { | 154 if (fLeft >= fRight || fTop >= fBottom) { |
| 176 this->set(left, top, right, bottom); | 155 this->set(left, top, right, bottom); |
| 177 } else { | 156 } else { |
| 178 if (left < fLeft) fLeft = left; | 157 if (left < fLeft) fLeft = left; |
| 179 if (top < fTop) fTop = top; | 158 if (top < fTop) fTop = top; |
| 180 if (right > fRight) fRight = right; | 159 if (right > fRight) fRight = right; |
| 181 if (bottom > fBottom) fBottom = bottom; | 160 if (bottom > fBottom) fBottom = bottom; |
| 182 } | 161 } |
| 183 } | 162 } |
| OLD | NEW |