Example #1
0
        void ProvinceSubstractProvinceEnclaves(int provinceIndex, Region region, Poly2Tri.Polygon poly)
        {
            List <Region> negativeRegions = new List <Region> ();

            for (int oc = 0; oc < _countries.Length; oc++)
            {
                Country ocCountry = _countries [oc];
                if (ocCountry.hidden || ocCountry.provinces == null)
                {
                    continue;
                }
                if (!ocCountry.regionsRect2D.Overlaps(region.latlonRect2D))
                {
                    continue;
                }
                for (int op = 0; op < ocCountry.provinces.Length; op++)
                {
                    Province opProvince = ocCountry.provinces [op];
                    if (opProvince == provinces [provinceIndex] || opProvince.hidden)
                    {
                        continue;
                    }
                    if (opProvince.regions == null)
                    {
                        continue;
                    }
                    if (opProvince.regionsRect2D.Overlaps(region.latlonRect2D, true))
                    {
                        Region oProvRegion = opProvince.regions [opProvince.mainRegionIndex];
                        if (region.Contains(oProvRegion))                               // just check main region of province for speed purposes
                        {
                            negativeRegions.Add(oProvRegion);
                        }
                    }
                }
            }
            // Collapse negative regions in big holes
            // Collapse negative regions in big holes
            for (int nr = 0; nr < negativeRegions.Count - 1; nr++)
            {
                for (int nr2 = nr + 1; nr2 < negativeRegions.Count; nr2++)
                {
                    if (negativeRegions [nr].Intersects(negativeRegions [nr2]))
                    {
                        Clipper clipper = new Clipper();
                        clipper.AddPath(negativeRegions [nr], PolyType.ptSubject);
                        clipper.AddPath(negativeRegions [nr2], PolyType.ptClip);
                        clipper.Execute(ClipType.ctUnion, negativeRegions [nr]);
                        negativeRegions.RemoveAt(nr2);
                        nr = -1;
                        break;
                    }
                }
            }

            // Substract holes
            for (int r = 0; r < negativeRegions.Count; r++)
            {
                Poly2Tri.Polygon polyHole = new Poly2Tri.Polygon(negativeRegions [r].latlon);
                poly.AddHole(polyHole);
            }
        }