1 /*
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 */
7 #include "include/core/SkPoint.h"
8 #include "include/core/SkTypes.h"
9 #include "src/pathops/SkPathOpsPoint.h"
10 #include "src/pathops/SkPathOpsTypes.h"
11 #include "tests/PathOpsTestCommon.h"
12 #include "tests/Test.h"
13
14 #include <array>
15 #include <cmath>
16 #include <cstddef>
17
18 static const SkDPoint tests[] = {
19 {0, 0},
20 {1, 0},
21 {0, 1},
22 {2, 1},
23 {1, 2},
24 {1, 1},
25 {2, 2}
26 };
27
28 static const size_t tests_count = std::size(tests);
29
DEF_TEST(PathOpsDPoint,reporter)30 DEF_TEST(PathOpsDPoint, reporter) {
31 for (size_t index = 0; index < tests_count; ++index) {
32 const SkDPoint& pt = tests[index];
33 SkASSERT(ValidPoint(pt));
34 SkDPoint p = pt;
35 REPORTER_ASSERT(reporter, p == pt);
36 REPORTER_ASSERT(reporter, !(pt != pt));
37 SkDVector v = p - pt;
38 p += v;
39 REPORTER_ASSERT(reporter, p == pt);
40 p -= v;
41 REPORTER_ASSERT(reporter, p == pt);
42 REPORTER_ASSERT(reporter, p.approximatelyEqual(pt));
43 SkPoint sPt = pt.asSkPoint();
44 p.set(sPt);
45 REPORTER_ASSERT(reporter, p == pt);
46 REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt));
47 REPORTER_ASSERT(reporter, p.roughlyEqual(pt));
48 p.fX = p.fY = 0;
49 REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0);
50 REPORTER_ASSERT(reporter, p.approximatelyZero());
51 REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY);
52 REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p),
53 sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
54 }
55 }
56