blob: 8ded8ff046063c90eb8e42af39790f434f445bac [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +00001/*
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.com8dcf1142012-07-02 20:27:02 +00007#include "Simplify.h"
caryclark@google.comd88e0892012-03-27 13:23:51 +00008
9namespace UnitTest {
10
11#include "EdgeWalker.cpp"
12
13} // end of UnitTest namespace
14
15#include "Intersection_Tests.h"
16
17SkPoint 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}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000026 {{10, 0}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000027// 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}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000031 {{10, 20}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000032 {{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}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000037 {{10, 10}, {10, 40}, {20, 10}, { 0 + 0.000001f, 70}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000038// left bottom lower
39 {{10, 10}, {10, 60}, {20, 10}, {20, 50}},
40 {{10, 10}, {10, 60}, {10, 10}, {20, 50}},
caryclark@google.comb45a1b42012-05-18 20:50:33 +000041 {{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}},
caryclark@google.comd88e0892012-03-27 13:23:51 +000044};
45
46size_t leftRightCount = sizeof(leftRight) / sizeof(leftRight[0]);
47
caryclark@google.com78e17132012-04-17 11:40:34 +000048// older code that worked mostly
49static 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 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000061 const SkPoint& check = lh.fBelow.fY <= rh.fBelow.fY
caryclark@google.com78e17132012-04-17 11:40:34 +000062 && 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
caryclark@google.comd88e0892012-03-27 13:23:51 +000068void 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];
rmistry@google.comd6176b02012-08-23 18:14:13 +000075 left.fTangent = left.fBelow = leftRight[x][1];
caryclark@google.comd88e0892012-03-27 13:23:51 +000076 right.fAbove = leftRight[x][2];
caryclark@google.comfa0588f2012-04-26 21:01:06 +000077 right.fTangent = right.fBelow = leftRight[x][3];
caryclark@google.comd88e0892012-03-27 13:23:51 +000078 SkASSERT(left < right);
caryclark@google.com78e17132012-04-17 11:40:34 +000079 SkASSERT(operator_less_than(left, right));
caryclark@google.comd88e0892012-03-27 13:23:51 +000080 SkASSERT(!(right < left));
caryclark@google.com78e17132012-04-17 11:40:34 +000081 SkASSERT(!operator_less_than(right, left));
caryclark@google.comd88e0892012-03-27 13:23:51 +000082 }
83}
84
85
86
87