mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-19 19:07:56 +08:00
tidy up code and use EvenOdd as default in PointInPaths()
This commit is contained in:
@@ -829,27 +829,26 @@
|
|||||||
return (pt2.X - pt1.X) * (pt3.Y - pt2.Y) - (pt2.Y - pt1.Y) * (pt3.X - pt2.X);
|
return (pt2.X - pt1.X) * (pt3.Y - pt2.Y) - (pt2.Y - pt1.Y) * (pt3.X - pt2.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// nb: returns MaxInt ((2^32)-1) when pt is on a line
|
||||||
|
/// </summary>
|
||||||
private static int PointInPathsWindingCount(ClipperIntPoint pt, List<List<ClipperIntPoint>> paths)
|
private static int PointInPathsWindingCount(ClipperIntPoint pt, List<List<ClipperIntPoint>> paths)
|
||||||
{
|
{
|
||||||
int i, j, len;
|
var result = 0;
|
||||||
List<ClipperIntPoint> p;
|
for (int i = 0; i < paths.Count; i++)
|
||||||
ClipperIntPoint prevPt;
|
|
||||||
bool isAbove;
|
|
||||||
double crossProd;
|
|
||||||
|
|
||||||
//nb: returns MaxInt ((2^32)-1) when pt is on a line
|
|
||||||
|
|
||||||
var Result = 0; // /!\
|
|
||||||
for (i = 0; i < paths.Count; i++)
|
|
||||||
{
|
{
|
||||||
j = 0;
|
int j = 0;
|
||||||
p = paths[i];
|
List<ClipperIntPoint> p = paths[i];
|
||||||
len = p.Count;
|
int len = p.Count;
|
||||||
|
|
||||||
if (len < 3) continue;
|
if (len < 3) continue;
|
||||||
prevPt = p[len - 1];
|
ClipperIntPoint prevPt = p[len - 1];
|
||||||
|
|
||||||
while ((j < len) && (p[j].Y == prevPt.Y)) j++;
|
while ((j < len) && (p[j].Y == prevPt.Y)) j++;
|
||||||
if (j == len) continue;
|
if (j == len) continue;
|
||||||
isAbove = (prevPt.Y < pt.Y);
|
|
||||||
|
bool isAbove = prevPt.Y < pt.Y;
|
||||||
|
|
||||||
while (j < len)
|
while (j < len)
|
||||||
{
|
{
|
||||||
if (isAbove)
|
if (isAbove)
|
||||||
@@ -863,16 +862,15 @@
|
|||||||
{
|
{
|
||||||
prevPt = p[j - 1];
|
prevPt = p[j - 1];
|
||||||
}
|
}
|
||||||
crossProd = CrossProduct(prevPt, p[j], pt);
|
|
||||||
|
double crossProd = CrossProduct(prevPt, p[j], pt);
|
||||||
if (crossProd == 0)
|
if (crossProd == 0)
|
||||||
{
|
{
|
||||||
return int.MaxValue;
|
return int.MaxValue;
|
||||||
//result:= MaxInt;
|
|
||||||
//Exit;
|
|
||||||
}
|
}
|
||||||
else if (crossProd < 0)
|
else if (crossProd < 0)
|
||||||
{
|
{
|
||||||
Result--;
|
result--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -886,23 +884,23 @@
|
|||||||
{
|
{
|
||||||
prevPt = p[j - 1];
|
prevPt = p[j - 1];
|
||||||
}
|
}
|
||||||
crossProd = CrossProduct(prevPt, p[j], pt);
|
|
||||||
|
double crossProd = CrossProduct(prevPt, p[j], pt);
|
||||||
if (crossProd == 0)
|
if (crossProd == 0)
|
||||||
{
|
{
|
||||||
return int.MaxValue;
|
return int.MaxValue;
|
||||||
//result:= MaxInt;
|
|
||||||
//Exit;
|
|
||||||
}
|
}
|
||||||
else if (crossProd > 0)
|
else if (crossProd > 0)
|
||||||
{
|
{
|
||||||
Result++;
|
result++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
j++;
|
j++;
|
||||||
isAbove = !isAbove;
|
isAbove = !isAbove;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool PointInPaths(ClipperIntPoint pt, List<List<ClipperIntPoint>> paths, ClipperPolyFillType fillRule, bool includeBorder)
|
private static bool PointInPaths(ClipperIntPoint pt, List<List<ClipperIntPoint>> paths, ClipperPolyFillType fillRule, bool includeBorder)
|
||||||
@@ -915,11 +913,11 @@
|
|||||||
|
|
||||||
switch (fillRule)
|
switch (fillRule)
|
||||||
{
|
{
|
||||||
|
default:
|
||||||
case ClipperPolyFillType.EvenOdd:
|
case ClipperPolyFillType.EvenOdd:
|
||||||
return wc % 2 != 0; // Odd()
|
return wc % 2 != 0;
|
||||||
|
|
||||||
case ClipperPolyFillType.NonZero:
|
case ClipperPolyFillType.NonZero:
|
||||||
default:
|
|
||||||
return wc != 0;
|
return wc != 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user