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 "SkMathPriv.h" | 10 #include "SkMathPriv.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 SkVector v = *this - a; | 216 SkVector v = *this - a; |
217 | 217 |
218 SkScalar uLengthSqd = u.lengthSqd(); | 218 SkScalar uLengthSqd = u.lengthSqd(); |
219 SkScalar det = u.cross(v); | 219 SkScalar det = u.cross(v); |
220 if (side) { | 220 if (side) { |
221 SkASSERT(-1 == SkPoint::kLeft_Side && | 221 SkASSERT(-1 == SkPoint::kLeft_Side && |
222 0 == SkPoint::kOn_Side && | 222 0 == SkPoint::kOn_Side && |
223 1 == kRight_Side); | 223 1 == kRight_Side); |
224 *side = (Side) SkScalarSignAsInt(det); | 224 *side = (Side) SkScalarSignAsInt(det); |
225 } | 225 } |
226 return SkScalarMulDiv(det, det, uLengthSqd); | 226 SkScalar temp = det / uLengthSqd; |
| 227 temp *= det; |
| 228 return temp; |
227 } | 229 } |
228 | 230 |
229 SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a, | 231 SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a, |
230 const SkPoint& b) const { | 232 const SkPoint& b) const { |
231 // See comments to distanceToLineBetweenSqd. If the projection of c onto | 233 // See comments to distanceToLineBetweenSqd. If the projection of c onto |
232 // u is between a and b then this returns the same result as that | 234 // u is between a and b then this returns the same result as that |
233 // function. Otherwise, it returns the distance to the closer of a and | 235 // function. Otherwise, it returns the distance to the closer of a and |
234 // b. Let the projection of v onto u be v'. There are three cases: | 236 // b. Let the projection of v onto u be v'. There are three cases: |
235 // 1. v' points opposite to u. c is not between a and b and is closer | 237 // 1. v' points opposite to u. c is not between a and b and is closer |
236 // to a than b. | 238 // to a than b. |
(...skipping 12 matching lines...) Expand all Loading... |
249 | 251 |
250 SkScalar uLengthSqd = u.lengthSqd(); | 252 SkScalar uLengthSqd = u.lengthSqd(); |
251 SkScalar uDotV = SkPoint::DotProduct(u, v); | 253 SkScalar uDotV = SkPoint::DotProduct(u, v); |
252 | 254 |
253 if (uDotV <= 0) { | 255 if (uDotV <= 0) { |
254 return v.lengthSqd(); | 256 return v.lengthSqd(); |
255 } else if (uDotV > uLengthSqd) { | 257 } else if (uDotV > uLengthSqd) { |
256 return b.distanceToSqd(*this); | 258 return b.distanceToSqd(*this); |
257 } else { | 259 } else { |
258 SkScalar det = u.cross(v); | 260 SkScalar det = u.cross(v); |
259 return SkScalarMulDiv(det, det, uLengthSqd); | 261 SkScalar temp = det / uLengthSqd; |
| 262 temp *= det; |
| 263 return temp; |
260 } | 264 } |
261 } | 265 } |
OLD | NEW |