Exemplo n.º 1
0
        protected virtual Cuboid FindDimensionsOfChild(OctreeNode <T> child)
        {
            Octant oct  = FindOctantOfChild(child);
            Cuboid dims = Parent.FindDimensionsOfChild(this);

            int size = dims.Width >> 1;

            return(new Cuboid(dims.X + oct.X * size, dims.Y + oct.Y * size, dims.Z + oct.Z * size, size));
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (obj is Cuboid)
            {
                Cuboid cuboid = (Cuboid)obj;
                return(X == cuboid.X && Y == cuboid.Y && Z == cuboid.Z &&
                       Width == cuboid.Width && Height == cuboid.Height && Depth == cuboid.Depth);
            }

            return(false);
        }
Exemplo n.º 3
0
        public Cuboid FindIntersection(Cuboid cuboid)
        {
            if (!IsIntersecting(cuboid))
            {
                throw new InvalidOperationException();
            }

            int left   = Math.Max(Left, cuboid.Left);
            int bottom = Math.Max(Bottom, cuboid.Bottom);
            int front  = Math.Max(Front, cuboid.Front);

            int right = Math.Min(Right, cuboid.Right);
            int top   = Math.Min(Top, cuboid.Top);
            int back  = Math.Min(Back, cuboid.Back);

            return(new Cuboid(left, bottom, front, right - left, top - bottom, back - front));
        }
Exemplo n.º 4
0
        internal override void SetCuboid(int size, Cuboid cuboid, T value)
        {
            if (cuboid.IsIntersecting(size))
            {
                Cuboid i = cuboid.FindIntersection(size);
                if (i.X == 0 && i.Y == 0 && i.Z == 0 &&
                    i.Width == i.Height && i.Height == i.Depth && i.Depth == size && ShouldMerge())
                {
                    Merge(value);
                }
                else if (i.Volume != 0)
                {
                    int h = size >> 1;

                    foreach (Octant oct in Octant.All)
                    {
                        Cuboid sub = new Cuboid(i.X - oct.X * h, i.Y - oct.Y * h, i.Z - oct.Z * h,
                                                i.Width, i.Height, i.Depth);
                        this[oct].SetCuboid(h, sub, value);
                    }
                }
            }
        }
Exemplo n.º 5
0
 internal virtual void SetCuboid(int size, Cuboid cuboid, T value)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public bool IsIntersecting(Cuboid cuboid)
 {
     return(cuboid.Left <= Right && cuboid.Right >= Left &&
            cuboid.Bottom <= Top && cuboid.Top >= Bottom &&
            cuboid.Front <= Back && cuboid.Back >= Front);
 }