aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-01-28 21:34:33 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-01-28 21:34:33 +0000
commitac753098e8af4a17e5df97b3a4dd0ce123f8d70c (patch)
tree91274eee1dcda52ebe6233f24c71cf8c4394ecb0 /src
parent2736a69077af6016f71ecbb2bb98e311aea0da01 (diff)
add some utils to SkPoint
git-svn-id: http://skia.googlecode.com/svn/trunk@485 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPoint.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index 704c2baa63..feca12f7ff 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -79,6 +79,17 @@ 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;
+ return mag;
+ }
+ return 0;
+}
+
bool SkPoint::setLength(float x, float y, float length) {
float mag = sk_float_sqrt(x * x + y * y);
if (mag > kNearlyZero) {