Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skeleton with Holes #13

Open
bvessels opened this issue Feb 16, 2023 · 0 comments
Open

Skeleton with Holes #13

bvessels opened this issue Feb 16, 2023 · 0 comments

Comments

@bvessels
Copy link

bvessels commented Feb 16, 2023

Edited for clarity:
I have a polygon (array of Vector2s) and an array of polygons that represent interior holes. After I create the PolygonWithHoles2 instance using the outermost polygon, I then use the AddHole method for each of the holes. I would expect an interior skeleton generated using the PolygonWithHoles2 instance to respect the previously added holes. However, the resulting skeleton remains the same as though no holes had been added at all. I've attached images demonstrating this (Input polygons/holes depicted in red, generated lines depicted in pink). How do you create a skeleton with interior holes? Below is my code:

`
////Get the instance to the offset algorithm.
var instance = PolygonOffset2.Instance;

        var polygon = new Polygon2<EIK>(args.Lines.First().Points.Select(p => new Point2d(p.X, p.Y)).ToArray());
        if (polygon.IsClockWise) {
            args.Lines.First().Points.Reverse();
            polygon = new Polygon2<EIK>(args.Lines.First().Points.Select(p => new Point2d(p.X, p.Y)).ToArray());
        }

        var polygonWithHoles = new PolygonWithHoles2<EIK>(polygon);
        foreach (var hole in args.Lines.Skip(1)) {
            var polygonHole = new Polygon2<EIK>(hole.Points.Select(p => new Point2d(p.X, p.Y)).ToArray());

            if (polygonHole.IsCounterClockWise) {
                hole.Points.Reverse();
                polygonHole = new Polygon2<EIK>(hole.Points.Select(p => new Point2d(p.X, p.Y)).ToArray());
            }
            polygonWithHoles.AddHole(polygonHole);
        }

        //The skeleton is return as a array of segments.
        var skeleton = new List<Segment2d>();
        instance.CheckInput = true;
        instance.CreateInteriorSkeleton(polygonWithHoles, false, skeleton);

        foreach (var segment in skeleton) {
            Utils.AddToBmp(bmp, new Vector2[] { 
                new Vector2((float)segment.A.x, (float)segment.A.y), 
                new Vector2((float)segment.B.x, (float)segment.B.y) 
            }, Color.HotPink);

WEIRD_Ring
Square_Ring
Polyline

        }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant