From 55b5f4bd6a69e70feeaf6018171882ab9cd250ae Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 7 Sep 2011 12:23:41 +0000 Subject: add SkPoint::CanNormalize to unify decisions about when a vector is degenerate git-svn-id: http://skia.googlecode.com/svn/trunk@2236 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/core/SkPoint.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'include/core/SkPoint.h') diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h index 7b9fdf99ca..8ba2cbcaa6 100644 --- a/include/core/SkPoint.h +++ b/include/core/SkPoint.h @@ -199,6 +199,16 @@ struct SK_API SkPoint { SkScalar length() const { return SkPoint::Length(fX, fY); } SkScalar distanceToOrigin() const { return this->length(); } + /** + * Return true if the computed length of the vector is >= the internal + * tolerance (used to avoid dividing by tiny values). + */ + static bool CanNormalize(SkScalar dx, SkScalar dy); + + bool canNormalize() const { + return CanNormalize(fX, fY); + } + /** Set the point (vector) to be unit-length in the same direction as it already points. If the point has a degenerate length (i.e. nearly 0) then return false and do nothing; otherwise return true. @@ -317,7 +327,8 @@ struct SK_API SkPoint { static SkScalar Length(SkScalar x, SkScalar y); /** Normalize pt, returning its previous length. If the prev length is too - small (degenerate), return 0 and leave pt unchanged. + small (degenerate), return 0 and leave pt unchanged. This uses the same + tolerance as CanNormalize. Note that this method may be significantly more expensive than the non-static normalize(), because it has to return the previous length -- cgit v1.2.3