OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 | 7 |
8 #ifndef SkPoint_DEFINED | 8 #ifndef SkPoint_DEFINED |
9 #define SkPoint_DEFINED | 9 #define SkPoint_DEFINED |
10 | 10 |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 404 |
405 /** Returns the euclidian distance between a and b | 405 /** Returns the euclidian distance between a and b |
406 */ | 406 */ |
407 static SkScalar Distance(const SkPoint& a, const SkPoint& b) { | 407 static SkScalar Distance(const SkPoint& a, const SkPoint& b) { |
408 return Length(a.fX - b.fX, a.fY - b.fY); | 408 return Length(a.fX - b.fX, a.fY - b.fY); |
409 } | 409 } |
410 | 410 |
411 /** Returns the dot product of a and b, treating them as 2D vectors | 411 /** Returns the dot product of a and b, treating them as 2D vectors |
412 */ | 412 */ |
413 static SkScalar DotProduct(const SkPoint& a, const SkPoint& b) { | 413 static SkScalar DotProduct(const SkPoint& a, const SkPoint& b) { |
414 return SkScalarMul(a.fX, b.fX) + SkScalarMul(a.fY, b.fY); | 414 return a.fX * b.fX + a.fY * b.fY; |
415 } | 415 } |
416 | 416 |
417 /** Returns the cross product of a and b, treating them as 2D vectors | 417 /** Returns the cross product of a and b, treating them as 2D vectors |
418 */ | 418 */ |
419 static SkScalar CrossProduct(const SkPoint& a, const SkPoint& b) { | 419 static SkScalar CrossProduct(const SkPoint& a, const SkPoint& b) { |
420 return SkScalarMul(a.fX, b.fY) - SkScalarMul(a.fY, b.fX); | 420 return a.fX * b.fY - a.fY * b.fX; |
421 } | 421 } |
422 | 422 |
423 SkScalar cross(const SkPoint& vec) const { | 423 SkScalar cross(const SkPoint& vec) const { |
424 return CrossProduct(*this, vec); | 424 return CrossProduct(*this, vec); |
425 } | 425 } |
426 | 426 |
427 SkScalar dot(const SkPoint& vec) const { | 427 SkScalar dot(const SkPoint& vec) const { |
428 return DotProduct(*this, vec); | 428 return DotProduct(*this, vec); |
429 } | 429 } |
430 | 430 |
431 SkScalar lengthSqd() const { | 431 SkScalar lengthSqd() const { |
432 return DotProduct(*this, *this); | 432 return DotProduct(*this, *this); |
433 } | 433 } |
434 | 434 |
435 SkScalar distanceToSqd(const SkPoint& pt) const { | 435 SkScalar distanceToSqd(const SkPoint& pt) const { |
436 SkScalar dx = fX - pt.fX; | 436 SkScalar dx = fX - pt.fX; |
437 SkScalar dy = fY - pt.fY; | 437 SkScalar dy = fY - pt.fY; |
438 return SkScalarMul(dx, dx) + SkScalarMul(dy, dy); | 438 return dx * dx + dy * dy; |
439 } | 439 } |
440 | 440 |
441 /** | 441 /** |
442 * The side of a point relative to a line. If the line is from a to b then | 442 * The side of a point relative to a line. If the line is from a to b then |
443 * the values are consistent with the sign of (b-a) cross (pt-a) | 443 * the values are consistent with the sign of (b-a) cross (pt-a) |
444 */ | 444 */ |
445 enum Side { | 445 enum Side { |
446 kLeft_Side = -1, | 446 kLeft_Side = -1, |
447 kOn_Side = 0, | 447 kOn_Side = 0, |
448 kRight_Side = 1 | 448 kRight_Side = 1 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 | 502 |
503 /** | 503 /** |
504 * cast-safe way to treat the point as an array of (2) SkScalars. | 504 * cast-safe way to treat the point as an array of (2) SkScalars. |
505 */ | 505 */ |
506 const SkScalar* asScalars() const { return &fX; } | 506 const SkScalar* asScalars() const { return &fX; } |
507 }; | 507 }; |
508 | 508 |
509 typedef SkPoint SkVector; | 509 typedef SkPoint SkVector; |
510 | 510 |
511 #endif | 511 #endif |
OLD | NEW |