Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
PathOpsDPointTest.cpp
Go to the documentation of this file.
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 */
12#include "tests/Test.h"
13
14#include <array>
15#include <cmath>
16#include <cstddef>
17
18static 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
28static const size_t tests_count = std::size(tests);
29
30DEF_TEST(PathOpsDPoint, reporter) {
31 for (size_t index = 0; index < tests_count; ++index) {
32 const SkDPoint& pt = tests[index];
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);
53 sqrt(pt.fX * pt.fX + pt.fY * pt.fY)));
54 }
55}
reporter
static const size_t tests_count
static const SkDPoint tests[]
bool ValidPoint(const SkDPoint &pt)
#define SkASSERT(cond)
Definition SkAssert.h:116
bool approximately_equal(double x, double y)
#define DEF_TEST(name, reporter)
Definition Test.h:312
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
double distanceSquared(const SkDPoint &a) const
SkPoint asSkPoint() const
double distance(const SkDPoint &a) const