blob: d460ba0644473cfb670bea03f0425ec9db90d26c [file] [log] [blame]
caryclark@google.com8dcf1142012-07-02 20:27:02 +00001#include "Simplify.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00002
3namespace UnitTest {
4
5#include "EdgeWalker.cpp"
6
7} // end of UnitTest namespace
8
9#include "Intersection_Tests.h"
10
11SkPoint leftRight[][4] = {
12// equal length
13 {{10, 10}, {10, 50}, {20, 10}, {20, 50}},
14 {{10, 10}, {10, 50}, {10, 10}, {20, 50}},
15 {{10, 10}, {10, 50}, {20, 10}, {10, 50}},
16// left top higher
17 {{10, 0}, {10, 50}, {20, 10}, {20, 50}},
18 {{10, 0}, {10, 50}, {10, 10}, {20, 50}},
19 {{10, 0}, {10, 50}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000020 {{10, 0}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000021// left top lower
22 {{10, 20}, {10, 50}, {20, 10}, {20, 50}},
23 {{10, 20}, {10, 50}, {10, 10}, {20, 50}},
24 {{10, 20}, {10, 50}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000025 {{10, 20}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000026 {{10, 20}, {10, 50}, { 0, 0}, {50, 50}},
27// left bottom higher
28 {{10, 10}, {10, 40}, {20, 10}, {20, 50}},
29 {{10, 10}, {10, 40}, {10, 10}, {20, 50}},
30 {{10, 10}, {10, 40}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000031 {{10, 10}, {10, 40}, {20, 10}, { 0 + 0.000001f, 70}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000032// left bottom lower
33 {{10, 10}, {10, 60}, {20, 10}, {20, 50}},
34 {{10, 10}, {10, 60}, {10, 10}, {20, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000035 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 50}},
36 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 40}},
37 {{10, 10}, {10, 60}, { 0, 0}, {20 + 0.000001f, 20}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000038};
39
40size_t leftRightCount = sizeof(leftRight) / sizeof(leftRight[0]);
41
caryclark@google.com78e17132012-04-17 11:40:34 +000042// older code that worked mostly
43static bool operator_less_than(const UnitTest::ActiveEdge& lh,
44 const UnitTest::ActiveEdge& rh) {
45 if (rh.fAbove.fY - lh.fAbove.fY > lh.fBelow.fY - rh.fAbove.fY
46 && lh.fBelow.fY < rh.fBelow.fY
47 || lh.fAbove.fY - rh.fAbove.fY < rh.fBelow.fY - lh.fAbove.fY
48 && rh.fBelow.fY < lh.fBelow.fY) {
49 const SkPoint& check = rh.fBelow.fY <= lh.fBelow.fY
50 && lh.fBelow != rh.fBelow ? rh.fBelow :
51 rh.fAbove;
52 return (check.fY - lh.fAbove.fY) * (lh.fBelow.fX - lh.fAbove.fX)
53 < (lh.fBelow.fY - lh.fAbove.fY) * (check.fX - lh.fAbove.fX);
54 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000055 const SkPoint& check = lh.fBelow.fY <= rh.fBelow.fY
caryclark@google.com78e17132012-04-17 11:40:34 +000056 && lh.fBelow != rh.fBelow ? lh.fBelow : lh.fAbove;
57 return (rh.fBelow.fY - rh.fAbove.fY) * (check.fX - rh.fAbove.fX)
58 < (check.fY - rh.fAbove.fY) * (rh.fBelow.fX - rh.fAbove.fX);
59}
60
61
caryclark@google.comd88e0892012-03-27 13:23:51 +000062void ActiveEdge_Test() {
63 UnitTest::InEdge leftIn, rightIn;
64 UnitTest::ActiveEdge left, right;
65 left.fWorkEdge.fEdge = &leftIn;
66 right.fWorkEdge.fEdge = &rightIn;
67 for (size_t x = 0; x < leftRightCount; ++x) {
68 left.fAbove = leftRight[x][0];
rmistry@google.comd6176b02012-08-23 18:14:13 +000069 left.fTangent = left.fBelow = leftRight[x][1];
caryclark@google.comd88e0892012-03-27 13:23:51 +000070 right.fAbove = leftRight[x][2];
caryclark@google.comfa0588f2012-04-26 21:01:06 +000071 right.fTangent = right.fBelow = leftRight[x][3];
caryclark@google.comd88e0892012-03-27 13:23:51 +000072 SkASSERT(left < right);
caryclark@google.com78e17132012-04-17 11:40:34 +000073 SkASSERT(operator_less_than(left, right));
caryclark@google.comd88e0892012-03-27 13:23:51 +000074 SkASSERT(!(right < left));
caryclark@google.com78e17132012-04-17 11:40:34 +000075 SkASSERT(!operator_less_than(right, left));
caryclark@google.comd88e0892012-03-27 13:23:51 +000076 }
77}
78
79
80
81