I write a program that draws strings over/on/under given path. The problem is that I need to check intersections between actually drawing letter and all the previous letters. I do it and it works fine. The only thing is about performance.
private void RemoveOverlapping(Graphics gr, float angle, float x, float y, GraphicsPath graphicsPath)
{
Matrix matrix = new Matrix();
for (;;)
{
matrix.Reset();
matrix.RotateAt(angle, new PointF(x, y));
graphicsPath.Transform(matrix);
bool isOverlapping = false;
Region letterRegion = new Region(graphicsPath);
foreach (Region region in _previousRegions)
{
region.Intersect(letterRegion);
if (!region.IsEmpty(gr))
{
matrix.Reset();
matrix.RotateAt(360f - angle, new PointF(x, y));
graphicsPath.Transform(matrix);
matrix.Reset();
matrix.Translate(1, 0);
graphicsPath.Transform(matrix);
isOverlapping = true;
break;
}
}
letterRegion.Dispose();
if (!isOverlapping)
return;
}
}
I did Alt+F2
tests and it told me that region.IsEmpty()
takes most of calculation time... Is there any another way (without implementing additional algorithms) to check two Regions/GraphicsPaths
intersections?
It's how it looks like: