Esempio n. 1
0
        public static Polygon Shape1minus2(List <Vec2> shape1, List <Vec2> shape2)
        {
            Polygon p1 = new Polygon(shape1);
            Polygon p2 = new Polygon(shape2);

            return(GpcWrapper.Clip(GpcWrapper.GpcOperation.Difference, p1, p2));
        }
Esempio n. 2
0
        public static List <Vec2i> IntersectShapes(List <Vec2i> shape1, List <Vec2i> shape2)
        {
            Polygon p1 = new Polygon(shape1);
            Polygon p2 = new Polygon(shape2);

            Polygon p = GpcWrapper.Clip(GpcWrapper.GpcOperation.Intersection, p1, p2);

            if (p == null || p.NumContours != 1)
            {
                return(new List <Vec2i>());
            }
            return(Vec2i.FromVec2dList(p[0]));
        }
        public static TriStrip PolygonToTristrip(Polygon polygon)
        {
            gpc_tristrip gpc_strip = new gpc_tristrip();
            gpc_polygon  gpc_pol   = GpcWrapper.PolygonTo_gpc_polygon(polygon);

            gpc_polygon_to_tristrip(ref gpc_pol, ref gpc_strip);
            TriStrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_pol);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
        public static TriStrip ClipToTristrip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_tristrip gpc_strip           = new gpc_tristrip();
            gpc_polygon  gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon  gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_tristrip_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_strip);
            TriStrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
        public static Polygon Clip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_polygon gpc_polygon         = new gpc_polygon();
            gpc_polygon gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_polygon_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_polygon);
            Polygon polygon = GpcWrapper.gpc_polygon_ToPolygon(gpc_polygon);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_polygon(ref gpc_polygon);

            return(polygon);
        }
Esempio n. 6
0
        public static Geometry.Shape BoxesToShape(List <Box2> boxes)
        {
            if (boxes.Count == 0)
            {
                return(null);
            }
            Polygon p = null;

            foreach (Box2 b in boxes)
            {
                if (b.Dimensions.X > 0.0001 && b.Dimensions.Y > 0.0001)
                {
                    Polygon pb = new Polygon(b.Corners());
                    if (p == null)
                    {
                        p = pb;
                    }
                    else
                    {
                        try
                        {
                            Polygon newPoly = GpcWrapper.Clip(GpcWrapper.GpcOperation.Union, p, pb);
                            p = newPoly;
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                }
            }
            List <List <Vec2> > vlists = PolygonToVectorLists(p);

            if (vlists.Count == 0)
            {
                return(null);
            }
            return(new Geometry.Shape(vlists[0]));
        }