caryclark@google.com | 9e49fb6 | 2012-08-27 14:11:33 +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 | */ |
caryclark@google.com | 9d5f99b | 2013-01-22 12:55:54 +0000 | [diff] [blame] | 7 | #include "QuadraticUtilities.h" |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 8 | #include "CurveIntersection.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 9 | #include "Intersection_Tests.h" |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 10 | #include "Parameterization_Test.h" |
caryclark@google.com | 639df89 | 2012-01-10 21:46:10 +0000 | [diff] [blame] | 11 | #include "TestUtilities.h" |
| 12 | |
| 13 | const Quadratic quadratics[] = { |
| 14 | {{0, 0}, {1, 0}, {1, 1}}, |
| 15 | }; |
| 16 | |
| 17 | const size_t quadratics_count = sizeof(quadratics) / sizeof(quadratics[0]); |
| 18 | |
| 19 | int firstCubicCoincidenceTest = 0; |
| 20 | |
| 21 | void 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.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 53 | |
| 54 | // pairs of coincident cubics |
| 55 | // The on curve points of each cubic should be on both parameterized cubics. |
| 56 | const Cubic cubics[] = { |
| 57 | { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 58 | { 1, -1}, |
| 59 | { 1.0/3, 1}, |
| 60 | {-1.0/3, -1}, |
| 61 | {-1, 1} |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 62 | }, |
| 63 | { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 64 | {-1, 1}, |
| 65 | {-1.0/3, -1}, |
| 66 | { 1.0/3, 1}, |
| 67 | { 1, -1} |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 68 | }, |
| 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 | |
| 93 | const size_t cubics_count = sizeof(cubics) / sizeof(cubics[0]); |
| 94 | |
| 95 | int firstCubicParameterizationTest = 0; |
| 96 | |
| 97 | void 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.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 101 | printf("%s [%zu,%zu] 1 parameterization failed\n", |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 102 | __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.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 109 | if (!implicit_matches(cubics[index], cubics[index ^ 1])) { |
| 110 | printf("%s %d\n", __FUNCTION__, (int)index); |
| 111 | } |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 112 | } |
| 113 | } |