blob: c7edb29f7d92ccc9d0474579d00a618ec65b7483 [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 "SkPathOpsLine.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 SkDLine tests[] = {
13 {{{2, 1}, {2, 1}}},
14 {{{2, 1}, {1, 1}}},
15 {{{2, 1}, {2, 2}}},
16 {{{1, 1}, {2, 2}}},
17 {{{3, 0}, {2, 1}}},
18 {{{3, 2}, {1, 1}}},
19};
20
21static const SkDPoint left[] = {
22 {2, 1},
23 {1, 0},
24 {1, 1},
25 {1, 2},
26 {2, 0},
27 {2, 1}
28};
29
caryclark@google.comad65a3e2013-04-15 19:13:59 +000030static const size_t tests_count = SK_ARRAY_COUNT(tests);
caryclark@google.com07393ca2013-04-08 11:47:37 +000031
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000032DEF_TEST(PathOpsLineUtilities, reporter) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000033 for (size_t index = 0; index < tests_count; ++index) {
34 const SkDLine& line = tests[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000035 SkASSERT(ValidLine(line));
caryclark@google.com07393ca2013-04-08 11:47:37 +000036 SkDLine line2;
37 SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()};
38 line2.set(pts);
39 REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]);
40 const SkDPoint& pt = left[index];
caryclark@google.com8d0a5242013-07-16 16:11:16 +000041 SkASSERT(ValidPoint(pt));
caryclark@google.com07393ca2013-04-08 11:47:37 +000042 double result = line.isLeft(pt);
43 if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) {
44 SkDebugf("%s [%d] expected left\n", __FUNCTION__, index);
45 REPORTER_ASSERT(reporter, 0);
46 }
47 line2 = line.subDivide(1, 0);
48 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]);
49 line2 = SkDLine::SubDivide(pts, 1, 0);
50 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]);
caryclark@google.com4fdbb222013-07-23 15:27:41 +000051 SkDPoint mid = line.ptAtT(.5);
caryclark@google.com07393ca2013-04-08 11:47:37 +000052 REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX) / 2, mid.fX));
53 REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY) / 2, mid.fY));
54 }
55}