blob: 4d350373f94776a97cf610ab7e6ada69ff8587da [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
caryclark@google.com8d0a5242013-07-16 16:11:16 +00007#include "PathOpsTestCommon.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +00008#include "SkPathOpsPoint.h"
9#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000010#include "TestClassDef.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000011
12static const SkDPoint tests[] = {
13 {0, 0},
14 {1, 0},
15 {0, 1},
16 {2, 1},
17 {1, 2},
18 {1, 1},
19 {2, 2}
20};
21
caryclark@google.comad65a3e2013-04-15 19:13:59 +000022static const size_t tests_count = SK_ARRAY_COUNT(tests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000023
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000024DEF_TEST(PathOpsDVector, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000025 for (size_t index = 0; index < tests_count - 1; ++index) {
26 SkDVector v1 = tests[index + 1] - tests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000027 SkASSERT(ValidVector(v1));
caryclark@google.com07393ca2013-04-08 11:47:37 +000028 SkDVector v2 = tests[index] - tests[index + 1];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000029 SkASSERT(ValidVector(v2));
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 v1 += v2;
31 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
32 SkDPoint p = tests[index + 1] + v2;
33 REPORTER_ASSERT(reporter, p == tests[index]);
34 v2 -= v2;
35 REPORTER_ASSERT(reporter, v2.fX == 0 && v2.fY == 0);
36 v1 = tests[index + 1] - tests[index];
37 v1 /= 2;
38 v1 *= 2;
39 v1 -= tests[index + 1] - tests[index];
40 REPORTER_ASSERT(reporter, v1.fX == 0 && v1.fY == 0);
41 SkVector sv = v1.asSkVector();
42 REPORTER_ASSERT(reporter, sv.fX == 0 && sv.fY == 0);
43 v1 = tests[index + 1] - tests[index];
44 double lenSq = v1.lengthSquared();
45 double v1Dot = v1.dot(v1);
46 REPORTER_ASSERT(reporter, lenSq == v1Dot);
47 REPORTER_ASSERT(reporter, approximately_equal(sqrt(lenSq), v1.length()));
48 double v1Cross = v1.cross(v1);
49 REPORTER_ASSERT(reporter, v1Cross == 0);
50 }
51}