blob: 507a32029a30bdba96fc48a441956ab87ba31d32 [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(PathOpsDPoint, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000025 for (size_t index = 0; index < tests_count; ++index) {
26 const SkDPoint& pt = tests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000027 SkASSERT(ValidPoint(pt));
caryclark@google.com07393ca2013-04-08 11:47:37 +000028 SkDPoint p = pt;
29 REPORTER_ASSERT(reporter, p == pt);
30 REPORTER_ASSERT(reporter, !(pt != pt));
31 SkDVector v = p - pt;
32 p += v;
33 REPORTER_ASSERT(reporter, p == pt);
34 p -= v;
35 REPORTER_ASSERT(reporter, p == pt);
36 REPORTER_ASSERT(reporter, p.approximatelyEqual(pt));
37 SkPoint sPt = pt.asSkPoint();
38 p.set(sPt);
39 REPORTER_ASSERT(reporter, p == pt);
40 REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt));
41 REPORTER_ASSERT(reporter, p.roughlyEqual(pt));
42 REPORTER_ASSERT(reporter, p.moreRoughlyEqual(pt));
43 p.fX = p.fY = 0;
44 REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0);
45 REPORTER_ASSERT(reporter, p.approximatelyZero());
46 REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY);
47 REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p),
48 sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
49 }
50}