2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #include "PathOpsTestCommon.h"
8 #include "SkPathOpsPoint.h"
11 static const SkDPoint tests[] = {
21 static const size_t tests_count = SK_ARRAY_COUNT(tests);
23 DEF_TEST(PathOpsDVector, reporter) {
24 for (size_t index = 0; index < tests_count - 1; ++index) {
25 SkDVector v1 = tests[index + 1] - tests[index];
26 SkASSERT(ValidVector(v1));
27 SkDVector v2 = tests[index] - tests[index + 1];
28 SkASSERT(ValidVector(v2));
30 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
31 SkDPoint p = tests[index + 1] + v2;
32 REPORTER_ASSERT(reporter, p == tests[index]);
34 REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0);
35 v1 = tests[index + 1] - tests[index];
38 v1 -= tests[index + 1] - tests[index];
39 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
40 SkVector sv = v1.asSkVector();
41 REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0);
42 v1 = tests[index + 1] - tests[index];
43 double lenSq = v1.lengthSquared();
44 double v1Dot = v1.dot(v1);
45 REPORTER_ASSERT(reporter, lenSq == v1Dot);
46 REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length()));
47 double v1Cross = v1.cross(v1);
48 REPORTER_ASSERT(reporter, v1Cross == 0);