示例#1
0
        public void Set(VirtualGrid3Region <T> regionToSet)
        {
            List <VirtualGrid3Region <T> > newRegions = new List <VirtualGrid3Region <T> >();

            foreach (VirtualGrid3Region <T> existingRegion in regions)
            {
                if (regionToSet.Contains(existingRegion))
                {
                    continue;
                }

                if (existingRegion.Intersects(regionToSet, out VirtualGrid3Region <T> intersection))
                {
                    newRegions.AddRange(existingRegion.Without(intersection));
                }
                else
                {
                    newRegions.Add(existingRegion);
                }
            }

            newRegions.Add(regionToSet);

            this.regions = newRegions;
        }
        internal bool Intersects(VirtualGrid3Region <T> other, out VirtualGrid3Region <T> intersection)
        {
            Point3 lowerBounds = Point3.Max(this.LowerBounds, other.LowerBounds);
            Point3 upperBounds = Point3.Min(this.UpperBounds, other.UpperBounds);

            if (upperBounds.AllGreaterThanOrEqual(lowerBounds))
            {
                intersection = new VirtualGrid3Region <T>(lowerBounds, upperBounds);
                return(true);
            }

            intersection = null;
            return(false);
        }
        internal IEnumerable <VirtualGrid3Region <T> > Without(VirtualGrid3Region <T> subregion)
        {
            Point3[] ranges = new Point3[6];

            ranges[0] = this.LowerBounds;
            ranges[1] = subregion.LowerBounds - 1;
            ranges[2] = subregion.LowerBounds;
            ranges[3] = subregion.UpperBounds;
            ranges[4] = subregion.UpperBounds + 1;
            ranges[5] = this.UpperBounds;

            for (int z = 0; z < 5; z += 2)
            {
                if (ranges[z].Z > ranges[z + 1].Z)
                {
                    continue;
                }

                for (int y = 0; y < 5; y += 2)
                {
                    if (ranges[y].Y > ranges[y + 1].Y)
                    {
                        continue;
                    }

                    for (int x = 0; x < 5; x += 2)
                    {
                        if (ranges[x].X > ranges[x + 1].X)
                        {
                            continue;
                        }

                        if (x != 2 || y != 2 || z != 2)
                        {
                            Point3 lowerBounds = new Point3(ranges[x].X, ranges[y].Y, ranges[z].Z);
                            Point3 upperBounds = new Point3(ranges[x + 1].X, ranges[y + 1].Y, ranges[z + 1].Z);

                            yield return(new VirtualGrid3Region <T>(lowerBounds, upperBounds, Value));
                        }
                    }
                }
            }
        }
 internal bool Contains(VirtualGrid3Region <T> other)
 {
     return(this.LowerBounds.AllLessThanOrEqual(other.LowerBounds) && this.UpperBounds.AllGreaterThanOrEqual(other.UpperBounds));
 }