OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 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 "SkPoint.h" | 10 #include "SkPoint.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 * doubles, which is much slower (3x in a desktop test) but will not overflow. | 156 * doubles, which is much slower (3x in a desktop test) but will not overflow. |
157 */ | 157 */ |
158 bool SkPoint::setLength(float x, float y, float length) { | 158 bool SkPoint::setLength(float x, float y, float length) { |
159 float mag2; | 159 float mag2; |
160 if (isLengthNearlyZero(x, y, &mag2)) { | 160 if (isLengthNearlyZero(x, y, &mag2)) { |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 float scale; | 164 float scale; |
165 if (SkScalarIsFinite(mag2)) { | 165 if (SkScalarIsFinite(mag2)) { |
166 scale = length / sk_float_sqrt(mag2); | 166 scale = length * sk_float_rsqrt(mag2); |
reed1
2013/11/07 22:28:44
not prepared to land this, until we know more abou
| |
167 } else { | 167 } else { |
168 // our mag2 step overflowed to infinity, so use doubles instead. | 168 // our mag2 step overflowed to infinity, so use doubles instead. |
169 // much slower, but needed when x or y are very large, other wise we | 169 // much slower, but needed when x or y are very large, other wise we |
170 // divide by inf. and return (0,0) vector. | 170 // divide by inf. and return (0,0) vector. |
171 double xx = x; | 171 double xx = x; |
172 double yy = y; | 172 double yy = y; |
173 scale = (float)(length / sqrt(xx * xx + yy * yy)); | 173 scale = (float)(length / sqrt(xx * xx + yy * yy)); |
174 } | 174 } |
175 fX = x * scale; | 175 fX = x * scale; |
176 fY = y * scale; | 176 fY = y * scale; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 | 508 |
509 if (uDotV <= 0) { | 509 if (uDotV <= 0) { |
510 return v.lengthSqd(); | 510 return v.lengthSqd(); |
511 } else if (uDotV > uLengthSqd) { | 511 } else if (uDotV > uLengthSqd) { |
512 return b.distanceToSqd(*this); | 512 return b.distanceToSqd(*this); |
513 } else { | 513 } else { |
514 SkScalar det = u.cross(v); | 514 SkScalar det = u.cross(v); |
515 return SkScalarMulDiv(det, det, uLengthSqd); | 515 return SkScalarMulDiv(det, det, uLengthSqd); |
516 } | 516 } |
517 } | 517 } |
OLD | NEW |