blob: 114331aca63a222038dd1775f5f9c4f5797a03b4 [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"
caryclark@google.comc6825902012-02-03 22:07:47 +00009#include "Parameterization_Test.h"
caryclark@google.com639df892012-01-10 21:46:10 +000010#include "TestUtilities.h"
11
12const Quadratic quadratics[] = {
13 {{0, 0}, {1, 0}, {1, 1}},
14};
15
16const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]);
17
18int firstCubicCoincidenceTest = 0;
19
20void CubicCoincidence_Test() {
21 // split large quadratic
22 // upscale quadratics to cubics
23 // compare original, parts, to see if the are coincident
24 for (size_t index = firstCubicCoincidenceTest; index < quadratics_count; ++index) {
25 const Quadratic& test = quadratics[index];
26 QuadraticPair split;
27 chop_at(test, split, 0.5);
28 Quadratic midThird;
29 sub_divide(test, 1.0/3, 2.0/3, midThird);
30 Cubic whole, first, second, mid;
31 quad_to_cubic(test, whole);
32 quad_to_cubic(split.first(), first);
33 quad_to_cubic(split.second(), second);
34 quad_to_cubic(midThird, mid);
35 if (!implicit_matches(whole, first)) {
36 printf("%s-1 %d\n", __FUNCTION__, (int)index);
37 }
38 if (!implicit_matches(whole, second)) {
39 printf("%s-2 %d\n", __FUNCTION__, (int)index);
40 }
41 if (!implicit_matches(mid, first)) {
42 printf("%s-3 %d\n", __FUNCTION__, (int)index);
43 }
44 if (!implicit_matches(mid, second)) {
45 printf("%s-4 %d\n", __FUNCTION__, (int)index);
46 }
47 if (!implicit_matches(first, second)) {
48 printf("%s-5 %d\n", __FUNCTION__, (int)index);
49 }
50 }
51}
caryclark@google.com27accef2012-01-25 18:57:23 +000052
53// pairs of coincident cubics
54// The on curve points of each cubic should be on both parameterized cubics.
55const Cubic cubics[] = {
56 {
caryclark@google.comc6825902012-02-03 22:07:47 +000057 { 1, -1},
58 { 1.0/3, 1},
59 {-1.0/3, -1},
60 {-1, 1}
caryclark@google.com27accef2012-01-25 18:57:23 +000061 },
62 {
caryclark@google.comc6825902012-02-03 22:07:47 +000063 {-1, 1},
64 {-1.0/3, -1},
65 { 1.0/3, 1},
66 { 1, -1}
caryclark@google.com27accef2012-01-25 18:57:23 +000067 },
68 {
69 {0, 2},
70 {0, 1},
71 {1, 0},
72 {2, 0}
73 }, {
74 {2, 0},
75 {1, 0},
76 {0, 1},
77 {0, 2}
78 },
79 {
80 {315.74799999999999, 312.83999999999997},
81 {312.64400000000001, 318.13400000000001},
82 {305.83600000000001, 319.90899999999999},
83 {300.54199999999997, 316.80399999999997}
84 }, {
85 {317.12200000000001, 309.05000000000001},
86 {316.11200000000002, 315.10199999999998},
87 {310.38499999999999, 319.19},
88 {304.33199999999999, 318.17899999999997}
89 }
90};
91
92const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]);
93
94int firstCubicParameterizationTest = 0;
95
96void CubicParameterization_Test() {
97 for (size_t index = firstCubicParameterizationTest; index < cubics_count; ++index) {
98 for (size_t inner = 0; inner < 4; inner += 3) {
99 if (!point_on_parameterized_curve(cubics[index], cubics[index][inner])) {
rmistry@google.comd6176b02012-08-23 18:14:13 +0000100 printf("%s [%zu,%zu] 1 parameterization failed\n",
caryclark@google.com27accef2012-01-25 18:57:23 +0000101 __FUNCTION__, index, inner);
102 }
103 if (!point_on_parameterized_curve(cubics[index], cubics[index ^ 1][inner])) {
104 printf("%s [%zu,%zu] 2 parameterization failed\n",
105 __FUNCTION__, index, inner);
106 }
107 }
caryclark@google.comc6825902012-02-03 22:07:47 +0000108 if (!implicit_matches(cubics[index], cubics[index ^ 1])) {
109 printf("%s %d\n", __FUNCTION__, (int)index);
110 }
caryclark@google.com27accef2012-01-25 18:57:23 +0000111 }
112}