aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-23 14:39:01 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-23 14:39:01 +0000
commit647a804c3dd53b6743091ec97dd12111f90efec3 (patch)
tree9f1afde2e721e34695d33271e8e13e00789c6e08 /src
parent8214587a79c0a4398664289c4d1ce2c0bf542b42 (diff)
Core skia changes to prepare for Gr AA Hairline renderer
Review URL: http://codereview.appspot.com/4940045/ git-svn-id: http://skia.googlecode.com/svn/trunk@2160 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/core/SkPath.cpp12
-rw-r--r--src/core/SkPoint.cpp20
-rw-r--r--src/views/SkTouchGesture.cpp8
3 files changed, 24 insertions, 16 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index e0d5b69cb8..e3eda6b7f4 100644
--- a/src/core/SkPath.cpp
+++ b/src/core/SkPath.cpp
@@ -1419,21 +1419,11 @@ void SkPath::validate() const {
///////////////////////////////////////////////////////////////////////////////
-/**
- * Returns -1 || 0 || 1 depending on the sign of value:
- * -1 if value < 0
- * 0 if vlaue == 0
- * 1 if value > 0
- */
-static int SkScalarSign(SkScalar value) {
- return value < 0 ? -1 : (value > 0);
-}
-
static int sign(SkScalar x) { return x < 0; }
#define kValueNeverReturnedBySign 2
static int CrossProductSign(const SkVector& a, const SkVector& b) {
- return SkScalarSign(SkPoint::CrossProduct(a, b));
+ return SkScalarSignAsInt(SkPoint::CrossProduct(a, b));
}
// only valid for a single contour
diff --git a/src/core/SkPoint.cpp b/src/core/SkPoint.cpp
index 2ad171fc89..d6e6b318bf 100644
--- a/src/core/SkPoint.cpp
+++ b/src/core/SkPoint.cpp
@@ -359,7 +359,25 @@ bool SkPoint::setLength(SkFixed ox, SkFixed oy, SkFixed length) {
///////////////////////////////////////////////////////////////////////////////
-SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a,
+SkScalar SkPoint::distanceToLineBetweenSqd(const SkPoint& a,
+ const SkPoint& b,
+ Side* side) const {
+
+ SkVector u = b - a;
+ SkVector v = *this - a;
+
+ SkScalar uLengthSqd = u.lengthSqd();
+ SkScalar det = u.cross(v);
+ if (NULL != side) {
+ SkASSERT(-1 == SkPoint::kLeft_Side &&
+ 0 == SkPoint::kOn_Side &&
+ 1 == kRight_Side);
+ *side = (Side) SkScalarSignAsInt(det);
+ }
+ return SkScalarMulDiv(det, det, uLengthSqd);
+}
+
+SkScalar SkPoint::distanceToLineSegmentBetweenSqd(const SkPoint& a,
const SkPoint& b) const {
// See comments to distanceToLineBetweenSqd. If the projection of c onto
// u is between a and b then this returns the same result as that
diff --git a/src/views/SkTouchGesture.cpp b/src/views/SkTouchGesture.cpp
index bcfaf892c5..31adc74b38 100644
--- a/src/views/SkTouchGesture.cpp
+++ b/src/views/SkTouchGesture.cpp
@@ -28,8 +28,8 @@ static double getseconds() {
}
// returns +1 or -1, depending on the sign of x
-// returns +1 if x is zero
-static SkScalar SkScalarSign(SkScalar x) {
+// returns +1 if z is zero
+static SkScalar SkScalarSignNonZero(SkScalar x) {
SkScalar sign = SK_Scalar1;
if (x < 0) {
sign = -sign;
@@ -41,9 +41,9 @@ static void unit_axis_align(SkVector* unit) {
const SkScalar TOLERANCE = SkDoubleToScalar(0.15);
if (SkScalarAbs(unit->fX) < TOLERANCE) {
unit->fX = 0;
- unit->fY = SkScalarSign(unit->fY);
+ unit->fY = SkScalarSignNonZero(unit->fY);
} else if (SkScalarAbs(unit->fY) < TOLERANCE) {
- unit->fX = SkScalarSign(unit->fX);
+ unit->fX = SkScalarSignNonZero(unit->fX);
unit->fY = 0;
}
}