blob: 042730779c85c68e020dc47dd24ee19f1540d792 [file] [log] [blame]
caryclark@google.com9166dcb2013-04-08 11:50:00 +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 */
7#include "SkDQuadImplicit.h"
8#include "SkPathOpsQuad.h"
9#include "Test.h"
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000010#include "TestClassDef.h"
caryclark@google.com9166dcb2013-04-08 11:50:00 +000011
12static bool point_on_parameterized_curve(const SkDQuad& quad, const SkDPoint& point) {
13 SkDQuadImplicit q(quad);
14 double xx = q.x2() * point.fX * point.fX;
15 double xy = q.xy() * point.fX * point.fY;
16 double yy = q.y2() * point.fY * point.fY;
17 double x = q.x() * point.fX;
18 double y = q.y() * point.fY;
19 double c = q.c();
20 double sum = xx + xy + yy + x + y + c;
21 return approximately_zero(sum);
22}
23
24static const SkDQuad quadratics[] = {
25 {{{0, 0}, {1, 0}, {1, 1}}},
26};
27
caryclark@google.comad65a3e2013-04-15 19:13:59 +000028static const size_t quadratics_count = SK_ARRAY_COUNT(quadratics);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000029
tfarina@chromium.org78e7b4e2014-01-02 21:45:03 +000030DEF_TEST(PathOpsQuadImplicit, reporter) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +000031 // split large quadratic
32 // compare original, parts, to see if the are coincident
33 for (size_t index = 0; index < quadratics_count; ++index) {
34 const SkDQuad& test = quadratics[index];
35 SkDQuadPair split = test.chopAt(0.5);
36 SkDQuad midThird = test.subDivide(1.0/3, 2.0/3);
37 const SkDQuad* quads[] = {
38 &test, &midThird, &split.first(), &split.second()
39 };
caryclark@google.comad65a3e2013-04-15 19:13:59 +000040 size_t quadsCount = SK_ARRAY_COUNT(quads);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000041 for (size_t one = 0; one < quadsCount; ++one) {
42 for (size_t two = 0; two < quadsCount; ++two) {
43 for (size_t inner = 0; inner < 3; inner += 2) {
44 REPORTER_ASSERT(reporter, point_on_parameterized_curve(*quads[one],
45 (*quads[two])[inner]));
46 }
47 REPORTER_ASSERT(reporter, SkDQuadImplicit::Match(*quads[one], *quads[two]));
48 }
49 }
50 }
51}