fix: remove self-intersecting loops from polygon offset
Polygon offset at concave corners creates geometry that folds back through itself. Added RemoveSelfIntersections() to Polygon that detects non-adjacent edge crossings and removes the smaller loop at each crossing. Applied to both collision detection and rendering. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -459,9 +459,20 @@ namespace OpenNest.Controls
|
||||
if (offsetEntity == null)
|
||||
continue;
|
||||
|
||||
offsetEntity.Offset(part.Location);
|
||||
var polygon = offsetEntity.ToPolygonWithTolerance(0.01);
|
||||
polygon.RemoveSelfIntersections();
|
||||
polygon.Offset(part.Location);
|
||||
|
||||
var path = GraphicsHelper.GetGraphicsPath(offsetEntity);
|
||||
if (polygon.Vertices.Count < 2)
|
||||
continue;
|
||||
|
||||
var pts = new PointF[polygon.Vertices.Count];
|
||||
|
||||
for (int j = 0; j < pts.Length; j++)
|
||||
pts[j] = new PointF((float)polygon.Vertices[j].X, (float)polygon.Vertices[j].Y);
|
||||
|
||||
var path = new GraphicsPath();
|
||||
path.AddLines(pts);
|
||||
path.Transform(Matrix);
|
||||
g.DrawPath(offsetPen, path);
|
||||
path.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user