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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 && approximately_equal(fY * inv, a.fY * inv); | 110 && approximately_equal(fY * inv, a.fY * inv); |
111 } | 111 } |
112 | 112 |
113 bool approximatelyEqual(const SkPoint& a) const { | 113 bool approximatelyEqual(const SkPoint& a) const { |
114 double denom = SkTMax(fabs(fX), SkTMax(fabs(fY), | 114 double denom = SkTMax(fabs(fX), SkTMax(fabs(fY), |
115 SkScalarToDouble(SkTMax(fabsf(a.fX), fabsf(a.fY))))); | 115 SkScalarToDouble(SkTMax(fabsf(a.fX), fabsf(a.fY))))); |
116 if (denom == 0) { | 116 if (denom == 0) { |
117 return true; | 117 return true; |
118 } | 118 } |
119 double inv = 1 / denom; | 119 double inv = 1 / denom; |
120 return approximately_equal(fX * inv, a.fX * inv) | 120 return approximately_equal_double(fX * inv, a.fX * inv) |
121 && approximately_equal(fY * inv, a.fY * inv); | 121 && approximately_equal_double(fY * inv, a.fY * inv); |
122 } | 122 } |
123 | 123 |
124 bool approximatelyEqualHalf(const SkDPoint& a) const { | 124 bool approximatelyEqualHalf(const SkDPoint& a) const { |
125 double denom = SkTMax(fabs(fX), SkTMax(fabs(fY), | 125 double denom = SkTMax(fabs(fX), SkTMax(fabs(fY), |
126 SkTMax(fabs(a.fX), fabs(a.fY)))); | 126 SkTMax(fabs(a.fX), fabs(a.fY)))); |
127 if (denom == 0) { | 127 if (denom == 0) { |
128 return true; | 128 return true; |
129 } | 129 } |
130 double inv = 1 / denom; | 130 double inv = 1 / denom; |
131 return approximately_equal_half(fX * inv, a.fX * inv) | 131 return approximately_equal_half(fX * inv, a.fX * inv) |
(...skipping 12 matching lines...) Expand all Loading... |
144 double distance(const SkDPoint& a) const { | 144 double distance(const SkDPoint& a) const { |
145 SkDVector temp = *this - a; | 145 SkDVector temp = *this - a; |
146 return temp.length(); | 146 return temp.length(); |
147 } | 147 } |
148 | 148 |
149 double distanceSquared(const SkDPoint& a) const { | 149 double distanceSquared(const SkDPoint& a) const { |
150 SkDVector temp = *this - a; | 150 SkDVector temp = *this - a; |
151 return temp.lengthSquared(); | 151 return temp.lengthSquared(); |
152 } | 152 } |
153 | 153 |
| 154 static SkDPoint Mid(const SkDPoint& a, const SkDPoint& b) { |
| 155 SkDPoint result; |
| 156 result.fX = (a.fX + b.fX) / 2; |
| 157 result.fY = (a.fY + b.fY) / 2; |
| 158 return result; |
| 159 } |
| 160 |
154 double moreRoughlyEqual(const SkDPoint& a) const { | 161 double moreRoughlyEqual(const SkDPoint& a) const { |
155 return more_roughly_equal(a.fY, fY) && more_roughly_equal(a.fX, fX); | 162 return more_roughly_equal(a.fY, fY) && more_roughly_equal(a.fX, fX); |
156 } | 163 } |
157 | 164 |
158 double roughlyEqual(const SkDPoint& a) const { | 165 double roughlyEqual(const SkDPoint& a) const { |
159 return roughly_equal(a.fY, fY) && roughly_equal(a.fX, fX); | 166 return roughly_equal(a.fY, fY) && roughly_equal(a.fX, fX); |
160 } | 167 } |
161 }; | 168 }; |
162 | 169 |
163 #endif | 170 #endif |
OLD | NEW |