aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-08 11:47:37 +0000
committerGravatar caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-08 11:47:37 +0000
commit07393cab57ce74a4aae89a31fae9aaa9780fc19d (patch)
tree2923009427914f3da107d4797e7e7fd2b9266f9a /tests
parent390c6d7a9018e233a6519397ac6c739fb21a99ef (diff)
Add base types for path ops
Paths contain lines, quads, and cubics, which are collectively curves. To work with path intersections, intermediary curves are constructed. For now, those intermediates use doubles to guarantee sufficient precision. The DVector, DPoint, DLine, DQuad, and DCubic structs encapsulate these intermediate curves. The DRect and DTriangle structs are created to describe intersectable areas of interest. The Bounds struct inherits from SkRect to create a SkScalar-based rectangle that intersects shared edges. This also includes common math equalities and debugging that the remainder of path ops builds on, as well as a temporary top-level interface in include/pathops/SkPathOps.h. Review URL: https://codereview.chromium.org/12827020 git-svn-id: http://skia.googlecode.com/svn/trunk@8551 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/PathOpsBoundsTest.cpp106
-rw-r--r--tests/PathOpsDCubicTest.cpp30
-rw-r--r--tests/PathOpsDLineTest.cpp54
-rw-r--r--tests/PathOpsDPointTest.cpp50
-rw-r--r--tests/PathOpsDQuadTest.cpp53
-rw-r--r--tests/PathOpsDRectTest.cpp100
-rw-r--r--tests/PathOpsDTriangleTest.cpp47
-rw-r--r--tests/PathOpsDVectorTest.cpp50
8 files changed, 490 insertions, 0 deletions
diff --git a/tests/PathOpsBoundsTest.cpp b/tests/PathOpsBoundsTest.cpp
new file mode 100644
index 0000000000..0ed19540ed
--- /dev/null
+++ b/tests/PathOpsBoundsTest.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsBounds.h"
+#include "Test.h"
+
+static const SkRect sectTests[][2] = {
+ {{2, 0, 4, 1}, {4, 0, 6, 1}},
+ {{2, 0, 4, 1}, {3, 0, 5, 1}},
+ {{2, 0, 4, 1}, {3, 0, 5, 0}},
+ {{2, 0, 4, 1}, {3, 1, 5, 2}},
+ {{2, 1, 4, 2}, {1, 0, 5, 3}},
+ {{2, 1, 5, 3}, {3, 1, 4, 2}},
+ {{2, 0, 4, 1}, {3, 0, 3, 0}}, // intersecting an empty bounds is OK
+ {{2, 0, 4, 1}, {4, 1, 5, 2}}, // touching just on a corner is OK
+};
+
+static const size_t sectTestsCount = sizeof(sectTests) / sizeof(sectTests[0]);
+
+static const SkRect noSectTests[][2] = {
+ {{2, 0, 4, 1}, {5, 0, 6, 1}},
+ {{2, 0, 4, 1}, {3, 2, 5, 2}},
+};
+
+static const size_t noSectTestsCount = sizeof(noSectTests) / sizeof(noSectTests[0]);
+
+static const SkRect reallyEmpty[] = {
+ {0, 0, 0, 0},
+ {1, 1, 1, 0},
+ {1, 1, 0, 1},
+ {1, 1, 0, 0},
+ {1, 2, 3, SK_ScalarNaN},
+};
+
+static const size_t emptyTestsCount = sizeof(reallyEmpty) / sizeof(reallyEmpty[0]);
+
+static const SkRect notReallyEmpty[] = {
+ {0, 0, 1, 0},
+ {0, 0, 0, 1},
+ {0, 0, 1, 1},
+};
+
+static const size_t notEmptyTestsCount = sizeof(notReallyEmpty) / sizeof(notReallyEmpty[0]);
+
+static void OpBoundsTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < sectTestsCount; ++index) {
+ const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(sectTests[index][0]);
+ const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(sectTests[index][1]);
+ bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
+ REPORTER_ASSERT(reporter, touches);
+ }
+ for (size_t index = 0; index < noSectTestsCount; ++index) {
+ const SkPathOpsBounds& bounds1 = static_cast<const SkPathOpsBounds&>(noSectTests[index][0]);
+ const SkPathOpsBounds& bounds2 = static_cast<const SkPathOpsBounds&>(noSectTests[index][1]);
+ bool touches = SkPathOpsBounds::Intersects(bounds1, bounds2);
+ REPORTER_ASSERT(reporter, !touches);
+ }
+ SkPathOpsBounds bounds;
+ bounds.setEmpty();
+ bounds.add(1, 2, 3, 4);
+ SkPathOpsBounds expected;
+ expected.set(0, 0, 3, 4);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setEmpty();
+ SkPathOpsBounds ordinal;
+ ordinal.set(1, 2, 3, 4);
+ bounds.add(ordinal);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ SkPoint topLeft = {0, 0};
+ bounds.setPointBounds(topLeft);
+ SkPoint botRight = {3, 4};
+ bounds.add(botRight);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ for (size_t index = 0; index < emptyTestsCount; ++index) {
+ const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(reallyEmpty[index]);
+ bool empty = bounds.isReallyEmpty();
+ REPORTER_ASSERT(reporter, empty);
+ }
+ for (size_t index = 0; index < notEmptyTestsCount; ++index) {
+ const SkPathOpsBounds& bounds = static_cast<const SkPathOpsBounds&>(notReallyEmpty[index]);
+ bool empty = bounds.isReallyEmpty();
+ REPORTER_ASSERT(reporter, !empty);
+ }
+ const SkPoint curvePts[] = {{0, 0}, {1, 2}, {3, 4}, {5, 6}};
+ bounds.setLineBounds(curvePts);
+ expected.set(0, 0, 1, 2);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[1])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setQuadBounds(curvePts);
+ expected.set(0, 0, 3, 4);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[2])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ bounds.setCubicBounds(curvePts);
+ expected.set(0, 0, 5, 6);
+ REPORTER_ASSERT(reporter, bounds == expected);
+ (bounds.*SetCurveBounds[3])(curvePts);
+ REPORTER_ASSERT(reporter, bounds == expected);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsBounds", PathOpsBoundsClass, OpBoundsTest)
diff --git a/tests/PathOpsDCubicTest.cpp b/tests/PathOpsDCubicTest.cpp
new file mode 100644
index 0000000000..60b92dfa84
--- /dev/null
+++ b/tests/PathOpsDCubicTest.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsCubic.h"
+#include "Test.h"
+
+static const SkDCubic tests[] = {
+ {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
+ {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
+ {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void DCubicTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count; ++index) {
+ const SkDCubic& cubic = tests[index];
+ bool result = cubic.clockwise();
+ if (!result) {
+ SkDebugf("%s [%d] expected clockwise\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsDCubic", PathOpsDCubic, DCubicTest)
diff --git a/tests/PathOpsDLineTest.cpp b/tests/PathOpsDLineTest.cpp
new file mode 100644
index 0000000000..4108f70afd
--- /dev/null
+++ b/tests/PathOpsDLineTest.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsLine.h"
+#include "Test.h"
+
+static const SkDLine tests[] = {
+ {{{2, 1}, {2, 1}}},
+ {{{2, 1}, {1, 1}}},
+ {{{2, 1}, {2, 2}}},
+ {{{1, 1}, {2, 2}}},
+ {{{3, 0}, {2, 1}}},
+ {{{3, 2}, {1, 1}}},
+};
+
+static const SkDPoint left[] = {
+ {2, 1},
+ {1, 0},
+ {1, 1},
+ {1, 2},
+ {2, 0},
+ {2, 1}
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void DLineTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count; ++index) {
+ const SkDLine& line = tests[index];
+ SkDLine line2;
+ SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()};
+ line2.set(pts);
+ REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]);
+ const SkDPoint& pt = left[index];
+ double result = line.isLeft(pt);
+ if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) {
+ SkDebugf("%s [%d] expected left\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ line2 = line.subDivide(1, 0);
+ REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]);
+ line2 = SkDLine::SubDivide(pts, 1, 0);
+ REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]);
+ SkDPoint mid = line.xyAtT(.5);
+ REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX) / 2, mid.fX));
+ REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY) / 2, mid.fY));
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsLineUtilities", PathOpsLineUtilitiesClass, DLineTest)
diff --git a/tests/PathOpsDPointTest.cpp b/tests/PathOpsDPointTest.cpp
new file mode 100644
index 0000000000..551609be33
--- /dev/null
+++ b/tests/PathOpsDPointTest.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsPoint.h"
+#include "Test.h"
+
+static const SkDPoint tests[] = {
+ {0, 0},
+ {1, 0},
+ {0, 1},
+ {2, 1},
+ {1, 2},
+ {1, 1},
+ {2, 2}
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void DPointTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count; ++index) {
+ const SkDPoint& pt = tests[index];
+ SkDPoint p = pt;
+ REPORTER_ASSERT(reporter, p == pt);
+ REPORTER_ASSERT(reporter, !(pt != pt));
+ SkDVector v = p - pt;
+ p += v;
+ REPORTER_ASSERT(reporter, p == pt);
+ p -= v;
+ REPORTER_ASSERT(reporter, p == pt);
+ REPORTER_ASSERT(reporter, p.approximatelyEqual(pt));
+ SkPoint sPt = pt.asSkPoint();
+ p.set(sPt);
+ REPORTER_ASSERT(reporter, p == pt);
+ REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt));
+ REPORTER_ASSERT(reporter, p.roughlyEqual(pt));
+ REPORTER_ASSERT(reporter, p.moreRoughlyEqual(pt));
+ p.fX = p.fY = 0;
+ REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0);
+ REPORTER_ASSERT(reporter, p.approximatelyZero());
+ REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY);
+ REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p),
+ sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsDPoint", PathOpsDPointClass, DPointTest)
diff --git a/tests/PathOpsDQuadTest.cpp b/tests/PathOpsDQuadTest.cpp
new file mode 100644
index 0000000000..f78e2aa3e2
--- /dev/null
+++ b/tests/PathOpsDQuadTest.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsQuad.h"
+#include "Test.h"
+
+static const SkDQuad tests[] = {
+ {{{1, 1}, {2, 1}, {0, 2}}},
+ {{{0, 0}, {1, 1}, {3, 1}}},
+ {{{2, 0}, {1, 1}, {2, 2}}},
+ {{{4, 0}, {0, 1}, {4, 2}}},
+ {{{0, 0}, {0, 1}, {1, 1}}},
+};
+
+static const SkDPoint inPoint[]= {
+ {1, 1.2},
+ {1, 0.8},
+ {1.8, 1},
+ {1.5, 1},
+ {0.5, 0.5},
+};
+
+static const SkDPoint outPoint[]= {
+ {1, 1.6},
+ {1, 1.5},
+ {2.2, 1},
+ {1.5, 1.5},
+ {1.1, 0.5},
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void DQuadTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count; ++index) {
+ const SkDQuad& quad = tests[index];
+ bool result = quad.pointInHull(inPoint[index]);
+ if (!result) {
+ SkDebugf("%s [%d] expected in hull\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ result = quad.pointInHull(outPoint[index]);
+ if (result) {
+ SkDebugf("%s [%d] expected outside hull\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsDQuad", PathOpsDQuadClass, DQuadTest)
diff --git a/tests/PathOpsDRectTest.cpp b/tests/PathOpsDRectTest.cpp
new file mode 100644
index 0000000000..881ee0b86b
--- /dev/null
+++ b/tests/PathOpsDRectTest.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsCubic.h"
+#include "SkPathOpsLine.h"
+#include "SkPathOpsQuad.h"
+#include "SkPathOpsRect.h"
+#include "Test.h"
+
+static const SkDLine lineTests[] = {
+ {{{2, 1}, {2, 1}}},
+ {{{2, 1}, {1, 1}}},
+ {{{2, 1}, {2, 2}}},
+ {{{1, 1}, {2, 2}}},
+ {{{3, 0}, {2, 1}}},
+ {{{3, 2}, {1, 1}}},
+};
+
+static const SkDQuad quadTests[] = {
+ {{{1, 1}, {2, 1}, {0, 2}}},
+ {{{0, 0}, {1, 1}, {3, 1}}},
+ {{{2, 0}, {1, 1}, {2, 2}}},
+ {{{4, 0}, {0, 1}, {4, 2}}},
+ {{{0, 0}, {0, 1}, {1, 1}}},
+};
+
+static const SkDCubic cubicTests[] = {
+ {{{2, 0}, {3, 1}, {2, 2}, {1, 1}}},
+ {{{3, 1}, {2, 2}, {1, 1}, {2, 0}}},
+ {{{3, 0}, {2, 1}, {3, 2}, {1, 1}}},
+};
+
+static const size_t lineTests_count = sizeof(lineTests) / sizeof(lineTests[0]);
+static const size_t quadTests_count = sizeof(quadTests) / sizeof(quadTests[0]);
+static const size_t cubicTests_count = sizeof(cubicTests) / sizeof(cubicTests[0]);
+
+static void DRectTest(skiatest::Reporter* reporter) {
+ size_t index;
+ SkDRect rect, rect2;
+ for (index = 0; index < lineTests_count; ++index) {
+ const SkDLine& line = lineTests[index];
+ rect.setBounds(line);
+ REPORTER_ASSERT(reporter, rect.fLeft == SkTMin<double>(line[0].fX, line[1].fX));
+ REPORTER_ASSERT(reporter, rect.fTop == SkTMin<double>(line[0].fY, line[1].fY));
+ REPORTER_ASSERT(reporter, rect.fRight == SkTMax<double>(line[0].fX, line[1].fX));
+ REPORTER_ASSERT(reporter, rect.fBottom == SkTMax<double>(line[0].fY, line[1].fY));
+ rect2.set(line[0]);
+ rect2.add(line[1]);
+ REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin<double>(line[0].fX, line[1].fX));
+ REPORTER_ASSERT(reporter, rect2.fTop == SkTMin<double>(line[0].fY, line[1].fY));
+ REPORTER_ASSERT(reporter, rect2.fRight == SkTMax<double>(line[0].fX, line[1].fX));
+ REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax<double>(line[0].fY, line[1].fY));
+ REPORTER_ASSERT(reporter, rect.contains(line[0]));
+ REPORTER_ASSERT(reporter, rect.intersects(&rect2));
+ }
+ for (index = 0; index < quadTests_count; ++index) {
+ const SkDQuad& quad = quadTests[index];
+ rect.setRawBounds(quad);
+ REPORTER_ASSERT(reporter, rect.fLeft == SkTMin<double>(quad[0].fX,
+ SkTMin<double>(quad[1].fX, quad[2].fX)));
+ REPORTER_ASSERT(reporter, rect.fTop == SkTMin<double>(quad[0].fY,
+ SkTMin<double>(quad[1].fY, quad[2].fY)));
+ REPORTER_ASSERT(reporter, rect.fRight == SkTMax<double>(quad[0].fX,
+ SkTMax<double>(quad[1].fX, quad[2].fX)));
+ REPORTER_ASSERT(reporter, rect.fBottom == SkTMax<double>(quad[0].fY,
+ SkTMax<double>(quad[1].fY, quad[2].fY)));
+ rect2.setBounds(quad);
+ REPORTER_ASSERT(reporter, rect.intersects(&rect2));
+ // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
+ SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
+ REPORTER_ASSERT(reporter, rect.contains(leftTop));
+ SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
+ REPORTER_ASSERT(reporter, rect.contains(rightBottom));
+ }
+ for (index = 0; index < cubicTests_count; ++index) {
+ const SkDCubic& cubic = cubicTests[index];
+ rect.setRawBounds(cubic);
+ REPORTER_ASSERT(reporter, rect.fLeft == SkTMin<double>(cubic[0].fX,
+ SkTMin<double>(cubic[1].fX, SkTMin<double>(cubic[2].fX, cubic[3].fX))));
+ REPORTER_ASSERT(reporter, rect.fTop == SkTMin<double>(cubic[0].fY,
+ SkTMin<double>(cubic[1].fY, SkTMin<double>(cubic[2].fY, cubic[3].fY))));
+ REPORTER_ASSERT(reporter, rect.fRight == SkTMax<double>(cubic[0].fX,
+ SkTMax<double>(cubic[1].fX, SkTMax<double>(cubic[2].fX, cubic[3].fX))));
+ REPORTER_ASSERT(reporter, rect.fBottom == SkTMax<double>(cubic[0].fY,
+ SkTMax<double>(cubic[1].fY, SkTMax<double>(cubic[2].fY, cubic[3].fY))));
+ rect2.setBounds(cubic);
+ REPORTER_ASSERT(reporter, rect.intersects(&rect2));
+ // FIXME: add a recursive box subdivision method to verify that tight bounds is correct
+ SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
+ REPORTER_ASSERT(reporter, rect.contains(leftTop));
+ SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
+ REPORTER_ASSERT(reporter, rect.contains(rightBottom));
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsDRect", PathOpsDRectClass, DRectTest)
diff --git a/tests/PathOpsDTriangleTest.cpp b/tests/PathOpsDTriangleTest.cpp
new file mode 100644
index 0000000000..3ca797df38
--- /dev/null
+++ b/tests/PathOpsDTriangleTest.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsTriangle.h"
+#include "Test.h"
+
+static const SkDTriangle tests[] = {
+ {{{2, 0}, {3, 1}, {2, 2}}},
+ {{{3, 1}, {2, 2}, {1, 1}}},
+ {{{3, 0}, {2, 1}, {3, 2}}},
+};
+
+static const SkDPoint inPoint[] = {
+ {2.5, 1},
+ {2, 1.5},
+ {2.5, 1},
+};
+
+static const SkDPoint outPoint[] = {
+ {3, 0},
+ {2.5, 2},
+ {2.5, 2},
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void TriangleUtilitiesTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count; ++index) {
+ const SkDTriangle& triangle = tests[index];
+ bool result = triangle.contains(inPoint[index]);
+ if (!result) {
+ SkDebugf("%s [%d] expected point in triangle\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ result = triangle.contains(outPoint[index]);
+ if (result) {
+ SkDebugf("%s [%d] expected point outside triangle\n", __FUNCTION__, index);
+ REPORTER_ASSERT(reporter, 0);
+ }
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsTriangleUtilities", PathOpsTriangleUtilitiesClass, TriangleUtilitiesTest)
diff --git a/tests/PathOpsDVectorTest.cpp b/tests/PathOpsDVectorTest.cpp
new file mode 100644
index 0000000000..48df753a06
--- /dev/null
+++ b/tests/PathOpsDVectorTest.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "SkPathOpsPoint.h"
+#include "Test.h"
+
+static const SkDPoint tests[] = {
+ {0, 0},
+ {1, 0},
+ {0, 1},
+ {2, 1},
+ {1, 2},
+ {1, 1},
+ {2, 2}
+};
+
+static const size_t tests_count = sizeof(tests) / sizeof(tests[0]);
+
+static void DVectorTest(skiatest::Reporter* reporter) {
+ for (size_t index = 0; index < tests_count - 1; ++index) {
+ SkDVector v1 = tests[index + 1] - tests[index];
+ SkDVector v2 = tests[index] - tests[index + 1];
+ v1 += v2;
+ REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
+ SkDPoint p = tests[index + 1] + v2;
+ REPORTER_ASSERT(reporter, p == tests[index]);
+ v2 -= v2;
+ REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0);
+ v1 = tests[index + 1] - tests[index];
+ v1 /= 2;
+ v1 *= 2;
+ v1 -= tests[index + 1] - tests[index];
+ REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
+ SkVector sv = v1.asSkVector();
+ REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0);
+ v1 = tests[index + 1] - tests[index];
+ double lenSq = v1.lengthSquared();
+ double v1Dot = v1.dot(v1);
+ REPORTER_ASSERT(reporter, lenSq == v1Dot);
+ REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length()));
+ double v1Cross = v1.cross(v1);
+ REPORTER_ASSERT(reporter, v1Cross == 0);
+ }
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PathOpsDVector", PathOpsDVectorClass, DVectorTest)