blob: 3e1b958ab665cd79e15d6cace4da1e325b0fb83c [file] [log] [blame]
caryclark@google.comd88e0892012-03-27 13:23:51 +00001#include "CurveIntersection.h"
caryclark@google.coma5764232012-03-28 16:20:21 +00002#include "Intersections.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00003#include "LineIntersection.h"
4#include "SkPath.h"
5#include "SkRect.h"
6#include "SkTArray.h"
7#include "SkTDArray.h"
caryclark@google.coma5764232012-03-28 16:20:21 +00008#include "ShapeOps.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00009#include "TSearch.h"
10
11namespace UnitTest {
12
13#include "EdgeWalker.cpp"
14
15} // end of UnitTest namespace
16
17#include "Intersection_Tests.h"
18
19SkPoint leftRight[][4] = {
20// equal length
21 {{10, 10}, {10, 50}, {20, 10}, {20, 50}},
22 {{10, 10}, {10, 50}, {10, 10}, {20, 50}},
23 {{10, 10}, {10, 50}, {20, 10}, {10, 50}},
24// left top higher
25 {{10, 0}, {10, 50}, {20, 10}, {20, 50}},
26 {{10, 0}, {10, 50}, {10, 10}, {20, 50}},
27 {{10, 0}, {10, 50}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000028 {{10, 0}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000029// left top lower
30 {{10, 20}, {10, 50}, {20, 10}, {20, 50}},
31 {{10, 20}, {10, 50}, {10, 10}, {20, 50}},
32 {{10, 20}, {10, 50}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000033 {{10, 20}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000034 {{10, 20}, {10, 50}, { 0, 0}, {50, 50}},
35// left bottom higher
36 {{10, 10}, {10, 40}, {20, 10}, {20, 50}},
37 {{10, 10}, {10, 40}, {10, 10}, {20, 50}},
38 {{10, 10}, {10, 40}, {20, 10}, {10, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000039 {{10, 10}, {10, 40}, {20, 10}, { 0 + 0.000001f, 70}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000040// left bottom lower
41 {{10, 10}, {10, 60}, {20, 10}, {20, 50}},
42 {{10, 10}, {10, 60}, {10, 10}, {20, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000043 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 50}},
44 {{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 40}},
45 {{10, 10}, {10, 60}, { 0, 0}, {20 + 0.000001f, 20}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000046};
47
48size_t leftRightCount = sizeof(leftRight) / sizeof(leftRight[0]);
49
caryclark@google.com78e17132012-04-17 11:40:34 +000050// older code that worked mostly
51static bool operator_less_than(const UnitTest::ActiveEdge& lh,
52 const UnitTest::ActiveEdge& rh) {
53 if (rh.fAbove.fY - lh.fAbove.fY > lh.fBelow.fY - rh.fAbove.fY
54 && lh.fBelow.fY < rh.fBelow.fY
55 || lh.fAbove.fY - rh.fAbove.fY < rh.fBelow.fY - lh.fAbove.fY
56 && rh.fBelow.fY < lh.fBelow.fY) {
57 const SkPoint& check = rh.fBelow.fY <= lh.fBelow.fY
58 && lh.fBelow != rh.fBelow ? rh.fBelow :
59 rh.fAbove;
60 return (check.fY - lh.fAbove.fY) * (lh.fBelow.fX - lh.fAbove.fX)
61 < (lh.fBelow.fY - lh.fAbove.fY) * (check.fX - lh.fAbove.fX);
62 }
63 const SkPoint& check = lh.fBelow.fY <= rh.fBelow.fY
64 && lh.fBelow != rh.fBelow ? lh.fBelow : lh.fAbove;
65 return (rh.fBelow.fY - rh.fAbove.fY) * (check.fX - rh.fAbove.fX)
66 < (check.fY - rh.fAbove.fY) * (rh.fBelow.fX - rh.fAbove.fX);
67}
68
69
caryclark@google.comd88e0892012-03-27 13:23:51 +000070void ActiveEdge_Test() {
71 UnitTest::InEdge leftIn, rightIn;
72 UnitTest::ActiveEdge left, right;
73 left.fWorkEdge.fEdge = &leftIn;
74 right.fWorkEdge.fEdge = &rightIn;
75 for (size_t x = 0; x < leftRightCount; ++x) {
76 left.fAbove = leftRight[x][0];
caryclark@google.comfa0588f2012-04-26 21:01:06 +000077 left.fTangent = left.fBelow = leftRight[x][1];
caryclark@google.comd88e0892012-03-27 13:23:51 +000078 right.fAbove = leftRight[x][2];
caryclark@google.comfa0588f2012-04-26 21:01:06 +000079 right.fTangent = right.fBelow = leftRight[x][3];
caryclark@google.comd88e0892012-03-27 13:23:51 +000080 SkASSERT(left < right);
caryclark@google.com78e17132012-04-17 11:40:34 +000081 SkASSERT(operator_less_than(left, right));
caryclark@google.comd88e0892012-03-27 13:23:51 +000082 SkASSERT(!(right < left));
caryclark@google.com78e17132012-04-17 11:40:34 +000083 SkASSERT(!operator_less_than(right, left));
caryclark@google.comd88e0892012-03-27 13:23:51 +000084 }
85}
86
87
88
89