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