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/SkPathOpsLine.h"
10 #include "src/pathops/SkPathOpsPoint.h"
11 #include "src/pathops/SkPathOpsTypes.h"
12 #include "tests/PathOpsTestCommon.h"
13 #include "tests/Test.h"
14
15 #include <array>
16 #include <cstddef>
17
18 static const SkDLine tests[] = {
19 {{{2, 1}, {2, 1}}},
20 {{{2, 1}, {1, 1}}},
21 {{{2, 1}, {2, 2}}},
22 {{{1, 1}, {2, 2}}},
23 {{{3, 0}, {2, 1}}},
24 {{{3, 2}, {1, 1}}},
25 };
26
27 static const size_t tests_count = std::size(tests);
28
DEF_TEST(PathOpsLineUtilities,reporter)29 DEF_TEST(PathOpsLineUtilities, reporter) {
30 for (size_t index = 0; index < tests_count; ++index) {
31 const SkDLine& line = tests[index];
32 SkASSERT(ValidLine(line));
33 SkDLine line2;
34 SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()};
35 line2.set(pts);
36 REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]);
37 SkDPoint mid = line.ptAtT(.5);
38 REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX) / 2, mid.fX));
39 REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY) / 2, mid.fY));
40 }
41 }
42