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