caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 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 "SkDQuadImplicit.h" |
| 8 | #include "SkPathOpsQuad.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | static bool point_on_parameterized_curve(const SkDQuad& quad, const SkDPoint& point) { |
| 12 | SkDQuadImplicit q(quad); |
| 13 | double xx = q.x2() * point.fX * point.fX; |
| 14 | double xy = q.xy() * point.fX * point.fY; |
| 15 | double yy = q.y2() * point.fY * point.fY; |
| 16 | double x = q.x() * point.fX; |
| 17 | double y = q.y() * point.fY; |
| 18 | double c = q.c(); |
| 19 | double sum = xx + xy + yy + x + y + c; |
| 20 | return approximately_zero(sum); |
| 21 | } |
| 22 | |
| 23 | static const SkDQuad quadratics[] = { |
| 24 | {{{0, 0}, {1, 0}, {1, 1}}}, |
| 25 | }; |
| 26 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 27 | static const int quadratics_count = (int) SK_ARRAY_COUNT(quadratics); |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 28 | |
tfarina@chromium.org | 78e7b4e | 2014-01-02 21:45:03 +0000 | [diff] [blame] | 29 | DEF_TEST(PathOpsQuadImplicit, reporter) { |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 30 | // split large quadratic |
| 31 | // compare original, parts, to see if the are coincident |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 32 | for (int index = 0; index < quadratics_count; ++index) { |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 33 | const SkDQuad& test = quadratics[index]; |
| 34 | SkDQuadPair split = test.chopAt(0.5); |
| 35 | SkDQuad midThird = test.subDivide(1.0/3, 2.0/3); |
| 36 | const SkDQuad* quads[] = { |
| 37 | &test, &midThird, &split.first(), &split.second() |
| 38 | }; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 39 | int quadsCount = (int) SK_ARRAY_COUNT(quads); |
| 40 | for (int one = 0; one < quadsCount; ++one) { |
| 41 | for (int two = 0; two < quadsCount; ++two) { |
| 42 | for (int inner = 0; inner < 3; inner += 2) { |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 43 | REPORTER_ASSERT(reporter, point_on_parameterized_curve(*quads[one], |
| 44 | (*quads[two])[inner])); |
| 45 | } |
| 46 | REPORTER_ASSERT(reporter, SkDQuadImplicit::Match(*quads[one], *quads[two])); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |