| OLD | NEW |
| (Empty) |
| 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 */ | |
| 7 #include "Simplify.h" | |
| 8 | |
| 9 namespace UnitTest { | |
| 10 | |
| 11 #include "EdgeWalker.cpp" | |
| 12 | |
| 13 } // end of UnitTest namespace | |
| 14 | |
| 15 #include "Intersection_Tests.h" | |
| 16 | |
| 17 SkPoint leftRight[][4] = { | |
| 18 // equal length | |
| 19 {{10, 10}, {10, 50}, {20, 10}, {20, 50}}, | |
| 20 {{10, 10}, {10, 50}, {10, 10}, {20, 50}}, | |
| 21 {{10, 10}, {10, 50}, {20, 10}, {10, 50}}, | |
| 22 // left top higher | |
| 23 {{10, 0}, {10, 50}, {20, 10}, {20, 50}}, | |
| 24 {{10, 0}, {10, 50}, {10, 10}, {20, 50}}, | |
| 25 {{10, 0}, {10, 50}, {20, 10}, {10, 50}}, | |
| 26 {{10, 0}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}}, | |
| 27 // left top lower | |
| 28 {{10, 20}, {10, 50}, {20, 10}, {20, 50}}, | |
| 29 {{10, 20}, {10, 50}, {10, 10}, {20, 50}}, | |
| 30 {{10, 20}, {10, 50}, {20, 10}, {10, 50}}, | |
| 31 {{10, 20}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}}, | |
| 32 {{10, 20}, {10, 50}, { 0, 0}, {50, 50}}, | |
| 33 // left bottom higher | |
| 34 {{10, 10}, {10, 40}, {20, 10}, {20, 50}}, | |
| 35 {{10, 10}, {10, 40}, {10, 10}, {20, 50}}, | |
| 36 {{10, 10}, {10, 40}, {20, 10}, {10, 50}}, | |
| 37 {{10, 10}, {10, 40}, {20, 10}, { 0 + 0.000001f, 70}}, | |
| 38 // left bottom lower | |
| 39 {{10, 10}, {10, 60}, {20, 10}, {20, 50}}, | |
| 40 {{10, 10}, {10, 60}, {10, 10}, {20, 50}}, | |
| 41 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 50}}, | |
| 42 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 40}}, | |
| 43 {{10, 10}, {10, 60}, { 0, 0}, {20 + 0.000001f, 20}}, | |
| 44 }; | |
| 45 | |
| 46 size_t leftRightCount = sizeof(leftRight) / sizeof(leftRight[0]); | |
| 47 | |
| 48 // older code that worked mostly | |
| 49 static bool operator_less_than(const UnitTest::ActiveEdge& lh, | |
| 50 const UnitTest::ActiveEdge& rh) { | |
| 51 if ((rh.fAbove.fY - lh.fAbove.fY > lh.fBelow.fY - rh.fAbove.fY | |
| 52 && lh.fBelow.fY < rh.fBelow.fY) | |
| 53 || (lh.fAbove.fY - rh.fAbove.fY < rh.fBelow.fY - lh.fAbove.fY | |
| 54 && rh.fBelow.fY < lh.fBelow.fY)) { | |
| 55 const SkPoint& check = rh.fBelow.fY <= lh.fBelow.fY | |
| 56 && lh.fBelow != rh.fBelow ? rh.fBelow : | |
| 57 rh.fAbove; | |
| 58 return (check.fY - lh.fAbove.fY) * (lh.fBelow.fX - lh.fAbove.fX) | |
| 59 < (lh.fBelow.fY - lh.fAbove.fY) * (check.fX - lh.fAbove.fX); | |
| 60 } | |
| 61 const SkPoint& check = lh.fBelow.fY <= rh.fBelow.fY | |
| 62 && lh.fBelow != rh.fBelow ? lh.fBelow : lh.fAbove; | |
| 63 return (rh.fBelow.fY - rh.fAbove.fY) * (check.fX - rh.fAbove.fX) | |
| 64 < (check.fY - rh.fAbove.fY) * (rh.fBelow.fX - rh.fAbove.fX); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 void ActiveEdge_Test() { | |
| 69 UnitTest::InEdge leftIn, rightIn; | |
| 70 UnitTest::ActiveEdge left, right; | |
| 71 left.fWorkEdge.fEdge = &leftIn; | |
| 72 right.fWorkEdge.fEdge = &rightIn; | |
| 73 for (size_t x = 0; x < leftRightCount; ++x) { | |
| 74 left.fAbove = leftRight[x][0]; | |
| 75 left.fTangent = left.fBelow = leftRight[x][1]; | |
| 76 right.fAbove = leftRight[x][2]; | |
| 77 right.fTangent = right.fBelow = leftRight[x][3]; | |
| 78 SkASSERT(left < right); | |
| 79 SkASSERT(operator_less_than(left, right)); | |
| 80 SkASSERT(!(right < left)); | |
| 81 SkASSERT(!operator_less_than(right, left)); | |
| 82 } | |
| 83 } | |
| OLD | NEW |