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)); }
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); }
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)); }
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); } } } }
internal virtual void SetCuboid(int size, Cuboid cuboid, T value) { throw new NotImplementedException(); }
public bool IsIntersecting(Cuboid cuboid) { return(cuboid.Left <= Right && cuboid.Right >= Left && cuboid.Bottom <= Top && cuboid.Top >= Bottom && cuboid.Front <= Back && cuboid.Back >= Front); }