public bool Touching(ContainerXXX other) // Diagonal corners don't count as touching { if (this.Right(Depth.World) == other.Left(Depth.World) || this.Left(Depth.World) == other.Right(Depth.World)) { if (this.Top(Depth.World) <= other.Bottom(Depth.World) || this.Bottom(Depth.World) >= other.Top(Depth.World)) { return(false); } return(true); } if (this.Top(Depth.World) == other.Bottom(Depth.World) || this.Bottom(Depth.World) == other.Top(Depth.World)) { if (this.Right(Depth.World) <= other.Left(Depth.World) || this.Left(Depth.World) >= other.Right(Depth.World)) { return(false); } return(true); } return(false); }
/// <summary> /// Join two containers. /// </summary> /// <param name="other"></param> /// <returns></returns> public ContainerXXX Join(ContainerXXX other) { if (this.depth != other.depth) { Debug.LogError("Joining two Containers of different depth! " + this.depth + " and " + other.depth); } return(new ContainerXXX(this.owner, Mathf.Min(this.Left(depth - 1), other.Left(depth - 1)), Mathf.Max(this.Right(depth - 1), other.Right(depth - 1)), Mathf.Max(this.Top(depth - 1), other.Top(depth - 1)), Mathf.Min(this.Bottom(depth - 1), other.Bottom(depth - 1)))); }
/// <summary> /// Returns true if two containers overlap. /// </summary> /// <param name="mine"></param> /// <param name="other"></param> /// <returns></returns> public bool Overlaps(ContainerXXX other) { return(!(this.Right(Depth.World) <= other.Left(Depth.World) || other.Right(Depth.World) <= this.Left(Depth.World) || this.Top(Depth.World) <= other.Bottom(Depth.World) || other.Top(Depth.World) <= this.Bottom(Depth.World))); }
private static ContainerSplitPacket QuadSplit(this ContainerXXX mine, Point dimension, Corner corner) { ContainerSplitPacket to_return = new ContainerSplitPacket(); ContainerXXX b1 = new ContainerXXX(); // [ b1 b2 ] ContainerXXX b2 = new ContainerXXX(); // [ b1 b2 ] ContainerXXX b3 = new ContainerXXX(); ContainerXXX b4 = new ContainerXXX(); switch (corner) { case Corner.TopLeft: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b2 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); to_return.result = b1; break; case Corner.TopRight: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b2 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Top(Depth.Building) - dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building) - dimension.y, mine.Bottom(Depth.Building)); to_return.result = b2; break; case Corner.BottomLeft: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b2 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Left(Depth.Building) + dimension.x, mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Left(Depth.Building) + dimension.x, mine.Right(Depth.Building), mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); to_return.result = b3; break; case Corner.BottomRight: b1 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b2 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Top(Depth.Building), mine.Bottom(Depth.Building) + dimension.y); b3 = new ContainerXXX(mine.owner, mine.Left(Depth.Building), mine.Right(Depth.Building) - dimension.x, mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); b4 = new ContainerXXX(mine.owner, mine.Right(Depth.Building) - dimension.x, mine.Right(Depth.Building), mine.Bottom(Depth.Building) + dimension.y, mine.Bottom(Depth.Building)); to_return.result = b4; break; } if (dimension.x < dimension.y) // means it's taller than it is wide, so we do a vertical split { switch (corner) { case Corner.TopLeft: to_return.container1 = b3; to_return.container2 = b2.Join(b4); break; case Corner.TopRight: to_return.container1 = b4; to_return.container2 = b1.Join(b3); break; case Corner.BottomLeft: to_return.container1 = b1; to_return.container2 = b2.Join(b4); break; case Corner.BottomRight: to_return.container1 = b2; to_return.container2 = b1.Join(b3); break; } } else // if its wider than it is tall, we do a horizontal split { switch (corner) { case Corner.TopLeft: to_return.container1 = b2; to_return.container2 = b3.Join(b4); break; case Corner.TopRight: to_return.container1 = b1; to_return.container2 = b3.Join(b4); break; case Corner.BottomLeft: to_return.container1 = b4; to_return.container2 = b1.Join(b2); break; case Corner.BottomRight: to_return.container1 = b3; to_return.container2 = b1.Join(b2); break; } } return(to_return); }