Пример #1
0
        /// <summary>
        /// Returns if a and b overlap.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        public static bool Overlap(BoxSelection a, BoxSelection b)
        {
            // assert that the projections of all axes overlap
            if (a.Left < b.Right)
            {
                return(false);
            }
            if (b.Left < a.Right)
            {
                return(false);
            }
            if (a.Bottom < b.Top)
            {
                return(false);
            }
            if (b.Bottom < a.Top)
            {
                return(false);
            }
            if (a.Forward < b.Backward)
            {
                return(false);
            }
            if (b.Forward < a.Backward)
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
 public bool Equals(BoxSelection other)
 {
     return(_left == other._left &&
            _right == other._right &&
            _bottom == other._bottom &&
            _top == other._top &&
            _forward == other._forward &&
            _backward == other._backward);
 }
Пример #3
0
        public static IEnumerable <BoxSelection> Deintersect(BoxSelection minuend, BoxSelection subtrahend)
        {
            var inclusive = Intersect(minuend, subtrahend);

            // if subtrahend doesn't share space with this
            if (inclusive == null)
            {
                yield return(minuend);

                yield break;
            }
        }
Пример #4
0
        /// <summary>
        /// Returns a BoxSelection where two other BoxSelections overlap.
        /// </summary>
        /// <param name="a">The first BoxSelection</param>
        /// <param name="b">The second BoxSelection</param>
        public static BoxSelection?Intersect(BoxSelection a, BoxSelection b)
        {
            if (!Overlap(a, b))
            {
                return(null);
            }

            var lesser = new BlockPosition(
                Math.Max(a.Left, b.Left),
                Math.Max(a.Bottom, b.Bottom),
                Math.Max(a.Forward, b.Forward));
            var greater = new BlockPosition(
                Math.Min(a.Right, b.Right),
                Math.Min(a.Top, b.Top),
                Math.Min(a.Backward, b.Backward));

            return(new BoxSelection(lesser, greater));
        }
Пример #5
0
        public ChunkPartition([NotNull] IChunk chunk, BoxSelection boundaries)
        {
            Chunk = chunk;

            var size          = chunk.Size();
            var position      = chunk.Position();
            var lesserCorner  = new BlockPosition(position, new LocalBlockPosition(0, 0, 0), size);
            var greaterCorner = new BlockPosition(position, new LocalBlockPosition(size.X, size.Y, size.Z), size);

            // translate boundaries into chunk-local
            // if minimum or maximum are out of bounds, cap them
            XMin = (boundaries.Left - lesserCorner.X).Clamp(0, size.X);
            YMin = (boundaries.Bottom - lesserCorner.Y).Clamp(0, size.Y);
            ZMin = (boundaries.Forward - lesserCorner.Z).Clamp(0, size.Z);

            XMax = (boundaries.Right - lesserCorner.X + 1).Clamp(0, size.X);
            YMax = (boundaries.Top - lesserCorner.Y + 1).Clamp(0, size.Y);
            ZMax = (boundaries.Backward - lesserCorner.Z + 1).Clamp(0, size.Z);
        }
Пример #6
0
 static IEnumerable <IChunkPartition> PartitionChunks(IEnumerable <IChunk> chunks, BoxSelection boundaries)
 {
     return(chunks.Select(chunk => new ChunkPartition(chunk, boundaries)));
 }
Пример #7
0
 /// <summary>
 /// Creates a new BoxSelection with the specified selection, dimensions and world.
 /// </summary>
 public BlockSelection([NotNull] BoxSelection selection, int dimension, [NotNull] World world)
 {
     Selection = selection;
     Dimension = dimension;
     World     = world;
 }