| 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 #ifndef SkPathOpsPoint_DEFINED | 7 #ifndef SkPathOpsPoint_DEFINED |
| 8 #define SkPathOpsPoint_DEFINED | 8 #define SkPathOpsPoint_DEFINED |
| 9 | 9 |
| 10 #include "SkPathOpsTypes.h" | 10 #include "SkPathOpsTypes.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 fY += v.fY; | 91 fY += v.fY; |
| 92 } | 92 } |
| 93 | 93 |
| 94 void operator-=(const SkDVector& v) { | 94 void operator-=(const SkDVector& v) { |
| 95 fX -= v.fX; | 95 fX -= v.fX; |
| 96 fY -= v.fY; | 96 fY -= v.fY; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // note: this can not be implemented with | 99 // note: this can not be implemented with |
| 100 // return approximately_equal(a.fY, fY) && approximately_equal(a.fX, fX); | 100 // return approximately_equal(a.fY, fY) && approximately_equal(a.fX, fX); |
| 101 // because that will not take the magnitude of the values | 101 // because that will not take the magnitude of the values into account |
| 102 bool approximatelyEqual(const SkDPoint& a) const { | 102 bool approximatelyEqual(const SkDPoint& a) const { |
| 103 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { | 103 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { | 106 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 double dist = distance(a); // OPTIMIZATION: can we compare against dist
Sq instead ? | 109 double dist = distance(a); // OPTIMIZATION: can we compare against dist
Sq instead ? |
| 110 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); | 110 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
| 111 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); | 111 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 SkDPoint dA, dB; | 129 SkDPoint dA, dB; |
| 130 dA.set(a); | 130 dA.set(a); |
| 131 dB.set(b); | 131 dB.set(b); |
| 132 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? | 132 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? |
| 133 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); | 133 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); |
| 134 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); | 134 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); |
| 135 largest = SkTMax(largest, -tiniest); | 135 largest = SkTMax(largest, -tiniest); |
| 136 return AlmostBequalUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? | 136 return AlmostBequalUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? |
| 137 } | 137 } |
| 138 | 138 |
| 139 bool approximatelyPEqual(const SkDPoint& a) const { |
| 140 if (approximately_equal(fX, a.fX) && approximately_equal(fY, a.fY)) { |
| 141 return true; |
| 142 } |
| 143 if (!RoughlyEqualUlps(fX, a.fX) || !RoughlyEqualUlps(fY, a.fY)) { |
| 144 return false; |
| 145 } |
| 146 double dist = distance(a); // OPTIMIZATION: can we compare against dist
Sq instead ? |
| 147 double tiniest = SkTMin(SkTMin(SkTMin(fX, a.fX), fY), a.fY); |
| 148 double largest = SkTMax(SkTMax(SkTMax(fX, a.fX), fY), a.fY); |
| 149 largest = SkTMax(largest, -tiniest); |
| 150 return AlmostPequalUlps(largest, largest + dist); // is the dist within
ULPS tolerance? |
| 151 } |
| 152 |
| 139 bool approximatelyZero() const { | 153 bool approximatelyZero() const { |
| 140 return approximately_zero(fX) && approximately_zero(fY); | 154 return approximately_zero(fX) && approximately_zero(fY); |
| 141 } | 155 } |
| 142 | 156 |
| 143 SkPoint asSkPoint() const { | 157 SkPoint asSkPoint() const { |
| 144 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; | 158 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; |
| 145 return pt; | 159 return pt; |
| 146 } | 160 } |
| 147 | 161 |
| 148 double distance(const SkDPoint& a) const { | 162 double distance(const SkDPoint& a) const { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 179 | 193 |
| 180 #ifdef SK_DEBUG | 194 #ifdef SK_DEBUG |
| 181 void dump() { | 195 void dump() { |
| 182 SkDebugf("{"); | 196 SkDebugf("{"); |
| 183 DebugDumpDouble(fX); | 197 DebugDumpDouble(fX); |
| 184 SkDebugf(", "); | 198 SkDebugf(", "); |
| 185 DebugDumpDouble(fY); | 199 DebugDumpDouble(fY); |
| 186 SkDebugf("}"); | 200 SkDebugf("}"); |
| 187 } | 201 } |
| 188 | 202 |
| 189 static void DumpSkPoint(const SkPoint& pt) { | 203 static void dump(const SkPoint& pt) { |
| 190 SkDebugf("{"); | 204 SkDebugf("{"); |
| 191 DebugDumpFloat(pt.fX); | 205 DebugDumpFloat(pt.fX); |
| 192 SkDebugf(", "); | 206 SkDebugf(", "); |
| 193 DebugDumpFloat(pt.fY); | 207 DebugDumpFloat(pt.fY); |
| 194 SkDebugf("}"); | 208 SkDebugf("}"); |
| 195 } | 209 } |
| 196 #endif | 210 #endif |
| 197 }; | 211 }; |
| 198 | 212 |
| 199 #endif | 213 #endif |
| OLD | NEW |