2012-08-27 14:11:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2012-07-02 20:27:02 +00:00
|
|
|
#include "Simplify.h"
|
2012-03-27 13:23:51 +00:00
|
|
|
|
|
|
|
namespace UnitTest {
|
|
|
|
|
|
|
|
#include "EdgeWalker.cpp"
|
|
|
|
|
|
|
|
} // end of UnitTest namespace
|
|
|
|
|
|
|
|
#include "Intersection_Tests.h"
|
|
|
|
|
|
|
|
SkPoint leftRight[][4] = {
|
|
|
|
// equal length
|
|
|
|
{{10, 10}, {10, 50}, {20, 10}, {20, 50}},
|
|
|
|
{{10, 10}, {10, 50}, {10, 10}, {20, 50}},
|
|
|
|
{{10, 10}, {10, 50}, {20, 10}, {10, 50}},
|
|
|
|
// left top higher
|
|
|
|
{{10, 0}, {10, 50}, {20, 10}, {20, 50}},
|
|
|
|
{{10, 0}, {10, 50}, {10, 10}, {20, 50}},
|
|
|
|
{{10, 0}, {10, 50}, {20, 10}, {10, 50}},
|
2012-05-18 20:50:33 +00:00
|
|
|
{{10, 0}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
|
2012-03-27 13:23:51 +00:00
|
|
|
// left top lower
|
|
|
|
{{10, 20}, {10, 50}, {20, 10}, {20, 50}},
|
|
|
|
{{10, 20}, {10, 50}, {10, 10}, {20, 50}},
|
|
|
|
{{10, 20}, {10, 50}, {20, 10}, {10, 50}},
|
2012-05-18 20:50:33 +00:00
|
|
|
{{10, 20}, {10, 50}, {20, 10}, {10 + 0.000001f, 40}},
|
2012-03-27 13:23:51 +00:00
|
|
|
{{10, 20}, {10, 50}, { 0, 0}, {50, 50}},
|
|
|
|
// left bottom higher
|
|
|
|
{{10, 10}, {10, 40}, {20, 10}, {20, 50}},
|
|
|
|
{{10, 10}, {10, 40}, {10, 10}, {20, 50}},
|
|
|
|
{{10, 10}, {10, 40}, {20, 10}, {10, 50}},
|
2012-05-18 20:50:33 +00:00
|
|
|
{{10, 10}, {10, 40}, {20, 10}, { 0 + 0.000001f, 70}},
|
2012-03-27 13:23:51 +00:00
|
|
|
// left bottom lower
|
|
|
|
{{10, 10}, {10, 60}, {20, 10}, {20, 50}},
|
|
|
|
{{10, 10}, {10, 60}, {10, 10}, {20, 50}},
|
2012-05-18 20:50:33 +00:00
|
|
|
{{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 50}},
|
|
|
|
{{10, 10}, {10, 60}, {20, 10}, {10 + 0.000001f, 40}},
|
|
|
|
{{10, 10}, {10, 60}, { 0, 0}, {20 + 0.000001f, 20}},
|
2012-03-27 13:23:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
size_t leftRightCount = sizeof(leftRight) / sizeof(leftRight[0]);
|
|
|
|
|
2012-04-17 11:40:34 +00:00
|
|
|
// older code that worked mostly
|
|
|
|
static bool operator_less_than(const UnitTest::ActiveEdge& lh,
|
|
|
|
const UnitTest::ActiveEdge& rh) {
|
2012-12-10 12:50:53 +00:00
|
|
|
if ((rh.fAbove.fY - lh.fAbove.fY > lh.fBelow.fY - rh.fAbove.fY
|
|
|
|
&& lh.fBelow.fY < rh.fBelow.fY)
|
|
|
|
|| (lh.fAbove.fY - rh.fAbove.fY < rh.fBelow.fY - lh.fAbove.fY
|
|
|
|
&& rh.fBelow.fY < lh.fBelow.fY)) {
|
2012-04-17 11:40:34 +00:00
|
|
|
const SkPoint& check = rh.fBelow.fY <= lh.fBelow.fY
|
|
|
|
&& lh.fBelow != rh.fBelow ? rh.fBelow :
|
|
|
|
rh.fAbove;
|
|
|
|
return (check.fY - lh.fAbove.fY) * (lh.fBelow.fX - lh.fAbove.fX)
|
|
|
|
< (lh.fBelow.fY - lh.fAbove.fY) * (check.fX - lh.fAbove.fX);
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
const SkPoint& check = lh.fBelow.fY <= rh.fBelow.fY
|
2012-04-17 11:40:34 +00:00
|
|
|
&& lh.fBelow != rh.fBelow ? lh.fBelow : lh.fAbove;
|
|
|
|
return (rh.fBelow.fY - rh.fAbove.fY) * (check.fX - rh.fAbove.fX)
|
|
|
|
< (check.fY - rh.fAbove.fY) * (rh.fBelow.fX - rh.fAbove.fX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-27 13:23:51 +00:00
|
|
|
void ActiveEdge_Test() {
|
|
|
|
UnitTest::InEdge leftIn, rightIn;
|
|
|
|
UnitTest::ActiveEdge left, right;
|
|
|
|
left.fWorkEdge.fEdge = &leftIn;
|
|
|
|
right.fWorkEdge.fEdge = &rightIn;
|
|
|
|
for (size_t x = 0; x < leftRightCount; ++x) {
|
|
|
|
left.fAbove = leftRight[x][0];
|
2012-08-23 18:14:13 +00:00
|
|
|
left.fTangent = left.fBelow = leftRight[x][1];
|
2012-03-27 13:23:51 +00:00
|
|
|
right.fAbove = leftRight[x][2];
|
2012-04-26 21:01:06 +00:00
|
|
|
right.fTangent = right.fBelow = leftRight[x][3];
|
2012-03-27 13:23:51 +00:00
|
|
|
SkASSERT(left < right);
|
2012-04-17 11:40:34 +00:00
|
|
|
SkASSERT(operator_less_than(left, right));
|
2012-03-27 13:23:51 +00:00
|
|
|
SkASSERT(!(right < left));
|
2012-04-17 11:40:34 +00:00
|
|
|
SkASSERT(!operator_less_than(right, left));
|
2012-03-27 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|