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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a, | 218 SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a, |
219 const SkPoint& b, | 219 const SkPoint& b, |
220 Side* side) const { | 220 Side* side) const { |
221 | 221 |
222 SkVector u = b - a; | 222 SkVector u = b - a; |
223 SkVector v = *this - a; | 223 SkVector v = *this - a; |
224 | 224 |
225 SkScalar uLengthSqd = u.lengthSqd(); | 225 SkScalar uLengthSqd = u.lengthSqd(); |
226 SkScalar det = u.cross(v); | 226 SkScalar det = u.cross(v); |
227 if (NULL != side) { | 227 if (side) { |
228 SkASSERT(-1 == SkPoint::kLeft_Side && | 228 SkASSERT(-1 == SkPoint::kLeft_Side && |
229 0 == SkPoint::kOn_Side && | 229 0 == SkPoint::kOn_Side && |
230 1 == kRight_Side); | 230 1 == kRight_Side); |
231 *side = (Side) SkScalarSignAsInt(det); | 231 *side = (Side) SkScalarSignAsInt(det); |
232 } | 232 } |
233 return SkScalarMulDiv(det, det, uLengthSqd); | 233 return SkScalarMulDiv(det, det, uLengthSqd); |
234 } | 234 } |
235 | 235 |
236 SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a, | 236 SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a, |
237 const SkPoint& b) const { | 237 const SkPoint& b) const { |
(...skipping 21 matching lines...) Expand all Loading... |
259 | 259 |
260 if (uDotV <= 0) { | 260 if (uDotV <= 0) { |
261 return v.lengthSqd(); | 261 return v.lengthSqd(); |
262 } else if (uDotV > uLengthSqd) { | 262 } else if (uDotV > uLengthSqd) { |
263 return b.distanceToSqd(*this); | 263 return b.distanceToSqd(*this); |
264 } else { | 264 } else { |
265 SkScalar det = u.cross(v); | 265 SkScalar det = u.cross(v); |
266 return SkScalarMulDiv(det, det, uLengthSqd); | 266 return SkScalarMulDiv(det, det, uLengthSqd); |
267 } | 267 } |
268 } | 268 } |
OLD | NEW |