diff options
author | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-15 18:04:58 +0000 |
---|---|---|
committer | epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-06-15 18:04:58 +0000 |
commit | 1fd56dc6e189ea0e94b5df9af959c243573f8883 (patch) | |
tree | bd8aa15599b99c4af90fb49340420071abd8d773 /src/core | |
parent | 129b8e3237b80b9d258a8f48e8f54c0073cafbdc (diff) |
Implement SkPoint::Normalize() for SK_SCALAR_IS_FIXED and add performance warning to its declaration
http://codereview.appspot.com/4582043/
git-svn-id: http://skia.googlecode.com/svn/trunk@1602 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPoint.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp index b5941d589e..c4163592b9 100644 --- a/src/core/SkPoint.cpp +++ b/src/core/SkPoint.cpp @@ -82,8 +82,6 @@ void SkPoint::scale(SkScalar scale, SkPoint* dst) const { dst->set(SkScalarMul(fX, scale), SkScalarMul(fY, scale)); } -#define kNearlyZero (SK_Scalar1 / 8092) - bool SkPoint::normalize() { return this->setLength(fX, fY, SK_Scalar1); } @@ -96,26 +94,26 @@ bool SkPoint::setLength(SkScalar length) { return this->setLength(fX, fY, length); } -#ifdef SK_SCALAR_IS_FLOAT - -SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) { - return sk_float_sqrt(dx * dx + dy * dy); -} - SkScalar SkPoint::Normalize(SkPoint* pt) { - float mag = SkPoint::Length(pt->fX, pt->fY); - if (mag > kNearlyZero) { - float scale = 1 / mag; - pt->fX *= scale; - pt->fY *= scale; + SkScalar mag = SkPoint::Length(pt->fX, pt->fY); + if (mag > SK_ScalarNearlyZero) { + SkScalar scale = SkScalarInvert(mag); + pt->fX = SkScalarMul(pt->fX, scale); + pt->fY = SkScalarMul(pt->fY, scale); return mag; } return 0; } +#ifdef SK_SCALAR_IS_FLOAT + +SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) { + return sk_float_sqrt(dx * dx + dy * dy); +} + bool SkPoint::setLength(float x, float y, float length) { float mag = sk_float_sqrt(x * x + y * y); - if (mag > kNearlyZero) { + if (mag > SK_ScalarNearlyZero) { length /= mag; fX = x * length; fY = y * length; @@ -401,4 +399,3 @@ SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a, return SkScalarMulDiv(det, det, uLengthSqd); } } - |