aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkPoint.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-07 12:23:41 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-07 12:23:41 +0000
commit55b5f4bd6a69e70feeaf6018171882ab9cd250ae (patch)
treec6c81cac1737319a8742973f114728ea18fe96da /include/core/SkPoint.h
parent11f6380510f40fdf83289976e51962306aac8ce4 (diff)
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
Diffstat (limited to 'include/core/SkPoint.h')
-rw-r--r--include/core/SkPoint.h13
1 files changed, 12 insertions, 1 deletions
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