diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPoint.cpp | 11 |
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) { |