public static bool Equals(Rect rect1, Rect rect2) { if (rect1.IsEmpty) { return rect2.IsEmpty; } return (((rect1.X.Equals(rect2.X) && rect1.Y.Equals(rect2.Y)) && rect1.Width.Equals(rect2.Width)) && rect1.Height.Equals(rect2.Height)); }
static Rect() { s_empty = new Rect { x = float.PositiveInfinity, y = float.PositiveInfinity, width = float.NegativeInfinity, height = float.NegativeInfinity }; }
public WMOHolder(WMORoot wmo) { WMO = wmo; var min = wmo.Bounds.Min; var max = wmo.Bounds.Max; var minPoint = new Point(min.X, min.Y); var maxPoint = new Point(max.X, max.Y); Bounds = new Rect(minPoint, maxPoint); }
public M2Holder(M2 model) { Model = model; var min = model.Bounds.Min; var max = model.Bounds.Max; var minPoint = new Point(min.X, min.Y); var maxPoint = new Point(max.X, max.Y); Bounds = new Rect(minPoint, maxPoint); }
public static Rect Offset(Rect rect, float offsetX, float offsetY) { rect.Offset(offsetX, offsetY); return rect; }
public static Rect Union(Rect rect, Point point) { rect.Union(new Rect(point, point)); return rect; }
public static Rect Union(Rect rect1, Rect rect2) { rect1.Union(rect2); return rect1; }
public void Union(Rect rect) { if (IsEmpty) { this = rect; } else if (!rect.IsEmpty) { float num = Math.Min(Left, rect.Left); float num2 = Math.Min(Top, rect.Top); if ((rect.Width == float.PositiveInfinity) || (Width == float.PositiveInfinity)) { width = float.PositiveInfinity; } else { float num3 = Math.Max(Right, rect.Right); width = Math.Max(num3 - num, 0.0f); } if ((rect.Height == float.PositiveInfinity) || (Height == float.PositiveInfinity)) { height = float.PositiveInfinity; } else { float num4 = Math.Max(Bottom, rect.Bottom); height = Math.Max((num4 - num2), 0.0f); } x = num; y = num2; } }
private void CalculateBounds(IEnumerable<Vector3> vertices) { var min = new Vector3(float.MaxValue); var max = new Vector3(float.MinValue); foreach (var vertex in vertices) { min = Vector3.Min(min, vertex); max = Vector3.Max(max, vertex); } Bounds = new Rect(min.X, min.Y, (max.X - min.X), (max.Y - min.Y)); }
/// <summary> /// Checks this Map for LOS between two positions. /// </summary> /// <param name="pos1">The start position.</param> /// <param name="pos2">The end position.</param> /// <returns>True if there is a clear LOS between the points.</returns> internal bool HasLOS(Vector3 pos1, Vector3 pos2) { // The max distance check has already been performed. var tile1Id = TileIdentifier.ByPosition(MapId, pos1); if (tile1Id == null) { log.Warn("Got an invalid Tile Coord for {0}. Assuming LOS for now.", pos1); return true; } var tile2Id = TileIdentifier.ByPosition(MapId, pos2); if (tile2Id == null) { log.Warn("Got an invalid Tile Coord for {0}. ", pos1); return true; } Tile tile; if (!TryGetTile(tile1Id, out tile)) { log.Error("Unable to load the given tile: {0} to check for LOS. Assuming LOS for now.", tile1Id); return true; } // if the positions are on the same tile, things get easier if (tile1Id == tile2Id) { return tile.HasLOS(pos1, pos2); } // else the LOS line segment crosses tile boundaries (possibly more than one.) var lineRect = new Rect(new Point(pos1.X, pos1.Y), new Point(pos2.X, pos2.Y)); var tile1Rect = tile.Bounds; lineRect.Intersect(tile1Rect); // we know that pos1 was internal to tile1, so lineRect contains pos1 and the new pos2. var newPoint = lineRect.BottomRight; var newPos2 = new Vector3(newPoint.X, newPoint.Y, pos2.Z); if (!tile.HasLOS(pos1, newPos2)) return false; // clip the LOS line segment against the intervening tiles until tile2 is reached pos1 = newPos2; var dir = (pos2 - pos1); dir.Normalize(); while(true) { // advance the start position by a small amount to ensure that we're on the new tile pos1 += 1e-3f*dir; tile1Id = TileIdentifier.ByPosition(MapId, pos1); if (tile1Id == null) { log.Warn("Got an invalid Tile Coord for {0}. Assuming LOS for now.", pos1); return true; } if (!TryGetTile(tile1Id, out tile)) { log.Error("Unable to load the given tile: {0} to check for LOS. Assuming LOS for now.", tile1Id); return true; } if (tile1Id == tile2Id) { return tile.HasLOS(pos1, pos2); } lineRect = new Rect(new Point(pos1.X, pos1.Y), new Point(pos2.X, pos2.Y)); tile1Rect = tile.Bounds; lineRect.Intersect(tile1Rect); newPoint = lineRect.BottomRight; newPos2 = new Vector3(newPoint.X, newPoint.Y, pos2.Z); if (!tile.HasLOS(pos1, newPos2)) return false; pos1 = newPos2; } }
public static ClipperResponse ClipAgainst(WMORoot wmo, Rect bounds, out List<Vector3> vertices, out List<int> indices) { vertices = new List<Vector3>(); indices = new List<int>(); return ClipperResponse.AllClipped; }
public bool IntersectsWith(Rect rect) { if (IsEmpty || rect.IsEmpty) { return false; } return ((((rect.Left <= Right) && (rect.Right >= Left)) && (rect.Top <= Bottom)) && (rect.Bottom >= Top)); }
public bool Contains(Rect rect) { if (IsEmpty || rect.IsEmpty) { return false; } return ((((x <= rect.x) && (y <= rect.y)) && ((x + width) >= (rect.x + rect.width))) && ((y + height) >= (rect.y + rect.height))); }
public static void Write(this BinaryWriter writer, Rect rect) { writer.Write(rect.X); writer.Write(rect.Y); writer.Write(rect.Width); writer.Write(rect.Height); }
public static Rect Inflate(Rect rect, Size size) { rect.Inflate(size.Width, size.Height); return rect; }
public static Rect Inflate(Rect rect, float width, float height) { rect.Inflate(width, height); return rect; }
public bool Equals(Rect value) { return Equals(this, value); }
private static bool Intersect(Rect chunkRect, ref Vector3 vertex0, ref Vector3 vertex1, ref Vector3 vertex2) { if (chunkRect.Contains(vertex0.X, vertex0.Y)) return true; if (chunkRect.Contains(vertex1.X, vertex1.Y)) return true; if (chunkRect.Contains(vertex2.X, vertex2.Y)) return true; // Check if any of the Chunk's corners are contained in the triangle if (Intersection.PointInTriangle2DXY(chunkRect.TopLeft, vertex0, vertex1, vertex2)) return true; if (Intersection.PointInTriangle2DXY(chunkRect.TopRight, vertex0, vertex1, vertex2)) return true; if (Intersection.PointInTriangle2DXY(chunkRect.BottomLeft, vertex0, vertex1, vertex2)) return true; if (Intersection.PointInTriangle2DXY(chunkRect.BottomRight, vertex0, vertex1, vertex2)) return true; // Check if any of the triangle's line segments intersect the chunk's bounds if (Intersection.IntersectSegmentRectangle2DXY(chunkRect, vertex0, vertex1)) return true; if (Intersection.IntersectSegmentRectangle2DXY(chunkRect, vertex0, vertex2)) return true; if (Intersection.IntersectSegmentRectangle2DXY(chunkRect, vertex1, vertex2)) return true; return false; }
public void Intersect(Rect rect) { if (!IntersectsWith(rect)) { this = Empty; } else { float num = Math.Max(Left, rect.Left); float num2 = Math.Max(Top, rect.Top); width = Math.Max(Math.Min(Right, rect.Right) - num, 0.0f); height = Math.Max(Math.Min(Bottom, rect.Bottom) - num2, 0.0f); x = num; y = num2; } }
public static bool IntersectSegmentRectangle2DXY(Rect rect, Vector3 point1, Vector3 point2) { var rectMin = new Vector2(rect.TopLeft.X, rect.TopLeft.Y); var rectMax = new Vector2(rect.BottomRight.X, rect.BottomRight.Y); var point12d = new Vector2(point1.X, point2.X); var point22d = new Vector2(point2.X, point2.Y); return IntersectSegmentRectangle2D(rectMin, rectMax, point12d, point22d); }
public static Rect Intersect(Rect rect1, Rect rect2) { rect1.Intersect(rect2); return rect1; }