blob: 1579f988846c6d928bd6786470df97d7734142e0 [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +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.comc6825902012-02-03 22:07:47 +00007#include "CurveIntersection.h"
caryclark@google.com27accef2012-01-25 18:57:23 +00008#include "Intersection_Tests.h"
9#include "QuadraticIntersection_TestData.h"
caryclark@google.com639df892012-01-10 21:46:10 +000010
caryclark@google.comb45a1b42012-05-18 20:50:33 +000011static const Quadratic testSet[] = {
caryclark@google.coma7e483d2012-08-28 20:44:43 +000012 // data for oneOffTest
caryclark@google.comb45a1b42012-05-18 20:50:33 +000013 {{8.0000000000000071, 8.0000000000000071},
14 {8.7289570079366854, 8.7289570079366889},
15 {9.3914917259458743, 9.0593802763083691}},
16 {{8.0000000000000142, 8.0000000000000142},
17 {8.1250000000000107, 8.1250000000000071},
caryclark@google.coma7e483d2012-08-28 20:44:43 +000018 {8.2500000000000071, 8.2187500000000053}},
19 // data for oneAtEndTest
20 {{0.91292418204644155, 0.41931201426549197},
21 {0.70491388044579517, 0.64754305977710236},
22 {0, 1 }},
23 {{0.21875, 0.765625 },
24 {0.125, 0.875 },
25 {0, 1 }}
caryclark@google.comb45a1b42012-05-18 20:50:33 +000026};
27
caryclark@google.coma7e483d2012-08-28 20:44:43 +000028static void oneAtEndTest() {
29 const Quadratic& quad1 = testSet[2];
30 const Quadratic& quad2 = testSet[3];
31 double minT = 0;
32 double maxT = 1;
33 bezier_clip(quad1, quad2, minT, maxT);
34}
35
36
caryclark@google.comb45a1b42012-05-18 20:50:33 +000037static void oneOffTest() {
38 const Quadratic& quad1 = testSet[0];
39 const Quadratic& quad2 = testSet[1];
40 double minT = 0;
41 double maxT = 1;
42 bezier_clip(quad1, quad2, minT, maxT);
43}
44
caryclark@google.coma3f05fa2012-06-01 17:44:28 +000045static void standardTestCases() {
caryclark@google.com27accef2012-01-25 18:57:23 +000046 for (size_t index = 0; index < quadraticTests_count; ++index) {
47 const Quadratic& quad1 = quadraticTests[index][0];
48 const Quadratic& quad2 = quadraticTests[index][1];
49 Quadratic reduce1, reduce2;
caryclark@google.com47d73da2013-02-17 01:41:25 +000050 int order1 = reduceOrder(quad1, reduce1, kReduceOrder_TreatAsFill);
51 int order2 = reduceOrder(quad2, reduce2, kReduceOrder_TreatAsFill);
caryclark@google.com27accef2012-01-25 18:57:23 +000052 if (order1 < 3) {
caryclark@google.comaa358312013-01-29 20:28:49 +000053 SkDebugf("%s [%d] quad1 order=%d\n", __FUNCTION__, (int)index, order1);
caryclark@google.com27accef2012-01-25 18:57:23 +000054 }
55 if (order2 < 3) {
caryclark@google.comaa358312013-01-29 20:28:49 +000056 SkDebugf("%s [%d] quad2 order=%d\n", __FUNCTION__, (int)index, order2);
caryclark@google.com27accef2012-01-25 18:57:23 +000057 }
58 if (order1 == 3 && order2 == 3) {
59 double minT = 0;
60 double maxT = 1;
61 bezier_clip(reduce1, reduce2, minT, maxT);
62 }
63 }
64}
caryclark@google.comb45a1b42012-05-18 20:50:33 +000065
66void QuadraticBezierClip_Test() {
caryclark@google.coma7e483d2012-08-28 20:44:43 +000067 oneAtEndTest();
caryclark@google.comb45a1b42012-05-18 20:50:33 +000068 oneOffTest();
69 standardTestCases();
70}