AngusJohnson / Clipper2

Polygon Clipping and Offsetting - C++, C# and Delphi
Boost Software License 1.0
1.52k stars 273 forks source link

Unnecessary point added #914

Open ThatBrianDude opened 5 days ago

ThatBrianDude commented 5 days ago

There is a case where this library adds an unnecessary point when executing a clipperOffset.

In the image you can see a point being generated right in the center of the road. This only happens in a specific positioning of the path. image

When I move that waypoint just slightly up it dissapears: image

This is the code that Im executing:

    public static List<Vector3> RoadFromPath(List<Vector3> path, float offsetDistance)
    {

        Path64 clipperPath = new Path64();
        List<Vector3> simplifiedPath = SimplifyPath(path, 10f);
        foreach (var point in simplifiedPath)
        {
            clipperPath.Add(new Point64(point.x, point.z));
        }

        ClipperOffset clipperOffset = new ClipperOffset();
        clipperOffset.AddPath(clipperPath, JoinType.Round, EndType.Round);
        Paths64 solution = new Paths64();
        clipperOffset.Execute(offsetDistance, solution);

        List<Vector3> bufferedPath = new List<Vector3>();
        if (solution.Count > 0) // Assume only one path in the solution
        {
            foreach (var point in solution[0])
            {
                bufferedPath.Add(new Vector3((float)point.X, 0, point.Y));
            }
        }

        return bufferedPath;
    }
ThatBrianDude commented 5 days ago

After further inspection it seems that the unnecessary point is not equal to but VERY close to one of the input path points.

To make this more clear here is a gif of me moving the input point a bit and the buggy point appearing/dissapearing: root

ThatBrianDude commented 5 days ago

Further observation: Switching to Clipper1 completely removes this issue. Il stay at Clipper1 for now until theres a fix for Clipper2.

Thanks for all the effort!