I have run into a strange performance issue, and it would be great with an explanation to the behavior I\'m experiencing.
I\'m using System.Drawing.Region.IsVisible
We've have been struggling with the same issue: with a 50k points polygon it tooks 45 seconds to build the rectangles behind the IsVisible() method. We tried to cache this data, but finally we had over 1 millions rectangles; with multiple regions we had hundreds megabytes of data to cache.
Finally we moved to the PNPoly algorithm, that takes just few ms:
https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
Here the c# version:
public bool IsVisible(Point p, List points)
{
int i, j = points.Count - 1;
bool isVisible = false;
for (i = 0; i < points.Count; i++)
{
if (points[i].Y < p.Y && points[j].Y >= p.Y
|| points[j].Y < p.Y && points[i].Y >= p.Y)
{
if (points[i].X + (p.Y - points[i].Y) / (points[j].Y - points[i].Y)
* (points[j].X - points[i].X) < p.X)
{
isVisible = !isVisible;
}
}
j = i;
}
return isVisible;
}