| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 SkVector v = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; | 51 SkVector v = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; |
| 52 return v; | 52 return v; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // only used by testing | 55 // only used by testing |
| 56 double cross(const SkDVector& a) const { | 56 double cross(const SkDVector& a) const { |
| 57 return fX * a.fY - fY * a.fX; | 57 return fX * a.fY - fY * a.fX; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // similar to cross, this bastardization considers nearly coincident to be z
ero | 60 // similar to cross, this bastardization considers nearly coincident to be z
ero |
| 61 // uses ulps epsilon == 16 |
| 61 double crossCheck(const SkDVector& a) const { | 62 double crossCheck(const SkDVector& a) const { |
| 62 double xy = fX * a.fY; | 63 double xy = fX * a.fY; |
| 63 double yx = fY * a.fX; | 64 double yx = fY * a.fX; |
| 64 return AlmostEqualUlps(xy, yx) ? 0 : xy - yx; | 65 return AlmostEqualUlps(xy, yx) ? 0 : xy - yx; |
| 65 } | 66 } |
| 66 | 67 |
| 68 // allow tinier numbers |
| 69 double crossNoNormalCheck(const SkDVector& a) const { |
| 70 double xy = fX * a.fY; |
| 71 double yx = fY * a.fX; |
| 72 return AlmostEqualUlpsNoNormalCheck(xy, yx) ? 0 : xy - yx; |
| 73 } |
| 74 |
| 67 double dot(const SkDVector& a) const { | 75 double dot(const SkDVector& a) const { |
| 68 return fX * a.fX + fY * a.fY; | 76 return fX * a.fX + fY * a.fY; |
| 69 } | 77 } |
| 70 | 78 |
| 71 double length() const { | 79 double length() const { |
| 72 return sqrt(lengthSquared()); | 80 return sqrt(lengthSquared()); |
| 73 } | 81 } |
| 74 | 82 |
| 75 double lengthSquared() const { | 83 double lengthSquared() const { |
| 76 return fX * fX + fY * fY; | 84 return fX * fX + fY * fY; |
| 77 } | 85 } |
| 86 |
| 87 void normalize() { |
| 88 double inverseLength = 1 / this->length(); |
| 89 fX *= inverseLength; |
| 90 fY *= inverseLength; |
| 91 } |
| 78 }; | 92 }; |
| 79 | 93 |
| 80 struct SkDPoint { | 94 struct SkDPoint { |
| 81 double fX; | 95 double fX; |
| 82 double fY; | 96 double fY; |
| 83 | 97 |
| 84 void set(const SkPoint& pt) { | 98 void set(const SkPoint& pt) { |
| 85 fX = pt.fX; | 99 fX = pt.fX; |
| 86 fY = pt.fY; | 100 fY = pt.fY; |
| 87 } | 101 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (!RoughlyEqualUlps(a.fX, b.fX) || !RoughlyEqualUlps(a.fY, b.fY)) { | 171 if (!RoughlyEqualUlps(a.fX, b.fX) || !RoughlyEqualUlps(a.fY, b.fY)) { |
| 158 return false; | 172 return false; |
| 159 } | 173 } |
| 160 SkDPoint dA, dB; | 174 SkDPoint dA, dB; |
| 161 dA.set(a); | 175 dA.set(a); |
| 162 dB.set(b); | 176 dB.set(b); |
| 163 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? | 177 double dist = dA.distance(dB); // OPTIMIZATION: can we compare against
distSq instead ? |
| 164 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); | 178 float tiniest = SkTMin(SkTMin(SkTMin(a.fX, b.fX), a.fY), b.fY); |
| 165 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); | 179 float largest = SkTMax(SkTMax(SkTMax(a.fX, b.fX), a.fY), b.fY); |
| 166 largest = SkTMax(largest, -tiniest); | 180 largest = SkTMax(largest, -tiniest); |
| 167 return AlmostPequalUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? | 181 return AlmostDequalUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? |
| 168 } | 182 } |
| 169 | 183 |
| 170 // only used by testing | 184 // only used by testing |
| 171 bool approximatelyZero() const { | 185 bool approximatelyZero() const { |
| 172 return approximately_zero(fX) && approximately_zero(fY); | 186 return approximately_zero(fX) && approximately_zero(fY); |
| 173 } | 187 } |
| 174 | 188 |
| 175 SkPoint asSkPoint() const { | 189 SkPoint asSkPoint() const { |
| 176 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; | 190 SkPoint pt = {SkDoubleToScalar(fX), SkDoubleToScalar(fY)}; |
| 177 return pt; | 191 return pt; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return RoughlyEqualUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? | 233 return RoughlyEqualUlps((double) largest, largest + dist); // is dist wi
thin ULPS tolerance? |
| 220 } | 234 } |
| 221 | 235 |
| 222 // utilities callable by the user from the debugger when the implementation
code is linked in | 236 // utilities callable by the user from the debugger when the implementation
code is linked in |
| 223 void dump() const; | 237 void dump() const; |
| 224 static void Dump(const SkPoint& pt); | 238 static void Dump(const SkPoint& pt); |
| 225 static void DumpHex(const SkPoint& pt); | 239 static void DumpHex(const SkPoint& pt); |
| 226 }; | 240 }; |
| 227 | 241 |
| 228 #endif | 242 #endif |
| OLD | NEW |