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 | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 8 | #include "CurveUtilities.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 9 | #include "Intersection_Tests.h" |
| 10 | #include "Intersections.h" |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 11 | #include "TestUtilities.h" |
| 12 | |
| 13 | struct lineCubic { |
| 14 | Cubic cubic; |
| 15 | _Line line; |
| 16 | } lineCubicTests[] = { |
| 17 | {{{0, 0}, {0, 1}, {0, 1}, {1, 1}}, {{0, 1}, {1, 0}}} |
| 18 | }; |
| 19 | |
| 20 | size_t lineCubicTests_count = sizeof(lineCubicTests) / sizeof(lineCubicTests[0]); |
| 21 | |
| 22 | const int firstLineCubicIntersectionTest = 0; |
| 23 | |
| 24 | void LineCubicIntersection_Test() { |
| 25 | for (size_t index = firstLineCubicIntersectionTest; index < lineCubicTests_count; ++index) { |
| 26 | const Cubic& cubic = lineCubicTests[index].cubic; |
| 27 | const _Line& line = lineCubicTests[index].line; |
| 28 | Cubic reduce1; |
| 29 | _Line reduce2; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 30 | int order1 = reduceOrder(cubic, reduce1, kReduceOrder_NoQuadraticsAllowed, |
| 31 | kReduceOrder_TreatAsFill); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 32 | int order2 = reduceOrder(line, reduce2); |
| 33 | if (order1 < 4) { |
| 34 | printf("[%d] cubic order=%d\n", (int) index, order1); |
| 35 | } |
| 36 | if (order2 < 2) { |
| 37 | printf("[%d] line order=%d\n", (int) index, order2); |
| 38 | } |
| 39 | if (order1 == 4 && order2 == 2) { |
caryclark@google.com | 73ca624 | 2013-01-17 21:02:47 +0000 | [diff] [blame] | 40 | Intersections i; |
| 41 | double* range1 = i.fT[0]; |
| 42 | double* range2 = i.fT[1]; |
| 43 | int roots = intersect(reduce1, reduce2, i); |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 44 | for (int pt = 0; pt < roots; ++pt) { |
| 45 | double tt1 = range1[pt]; |
| 46 | double tx1, ty1; |
| 47 | xy_at_t(cubic, tt1, tx1, ty1); |
| 48 | double tt2 = range2[pt]; |
| 49 | double tx2, ty2; |
| 50 | xy_at_t(line, tt2, tx2, ty2); |
caryclark@google.com | 6d0032a | 2013-01-04 19:41:13 +0000 | [diff] [blame] | 51 | if (!AlmostEqualUlps(tx1, tx2)) { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 52 | printf("%s [%d,%d] x!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 53 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
| 54 | } |
caryclark@google.com | 6d0032a | 2013-01-04 19:41:13 +0000 | [diff] [blame] | 55 | if (!AlmostEqualUlps(ty1, ty2)) { |
caryclark@google.com | c682590 | 2012-02-03 22:07:47 +0000 | [diff] [blame] | 56 | printf("%s [%d,%d] y!= t1=%g (%g,%g) t2=%g (%g,%g)\n", |
| 57 | __FUNCTION__, (int)index, pt, tt1, tx1, ty1, tt2, tx2, ty2); |
caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |