* Simplified contour parity check routine, formula courtesy of Guillaume Bittoun.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 787ff77..49a5ed9 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -213,19 +213,26 @@ void FTVectoriser::ProcessContours()
FTPoint p1 = c2->Point(n);
FTPoint p2 = c2->Point((n + 1) % c2->PointCount());
+ /* FIXME: combinations of >= > <= and < do not seem stable */
if((p1.Y() < leftmost.Y() && p2.Y() < leftmost.Y())
- || (p1.Y() >= leftmost.Y() && p2.Y() >= leftmost.Y()))
+ || (p1.Y() >= leftmost.Y() && p2.Y() >= leftmost.Y())
+ || (p1.X() > leftmost.X() && p2.X() > leftmost.X()))
{
continue;
}
-
- double K = (p2.Y() - leftmost.Y()) / (p1.Y() - leftmost.Y());
- double K2 = (p2.X() - p1.X()) / (K - 1.);
-
- if(leftmost.X() > p1.X() - K2)
+ else if(p1.X() < leftmost.X() && p2.X() < leftmost.X())
{
parity++;
}
+ else
+ {
+ FTPoint a = p1 - leftmost;
+ FTPoint b = p2 - leftmost;
+ if(b.X() * a.Y() > b.Y() * a.X())
+ {
+ parity++;
+ }
+ }
}
}