private bool HasOutOfBoardCollision(ICollidableElement element) { #region Argument Check if (element == null) { throw new ArgumentNullException("element"); } #endregion var primitives = element.GetPrimitives(); // First, checking just base points //// ReSharper disable once LoopCanBeConvertedToQuery //// ReSharper disable once ForCanBeConvertedToForeach for (var index = 0; index < primitives.Count; index++) { var primitive = primitives[index]; if (!CollisionDetector.IsPointInPolygon(primitive.BasePoint, this.Data.BoardBorder)) { return(true); } } // Then checking intersection of element's primitives with board borders //// ReSharper disable once ForCanBeConvertedToForeach for (var index = 0; index < primitives.Count; index++) { var primitive = primitives[index]; //// ReSharper disable once LoopCanBeConvertedToQuery //// ReSharper disable once ForCanBeConvertedToForeach for (var edgeIndex = 0; edgeIndex < this.Data.BoardBorder.Edges.Count; edgeIndex++) { var edge = this.Data.BoardBorder.Edges[edgeIndex]; if (edge.HasCollision(primitive)) { return(true); } } } return(false); }
internal static bool CheckElementCollision(ICollidableElement element, ICollidable other) { #region Argument Check if (element == null) { throw new ArgumentNullException("element"); } if (other == null) { throw new ArgumentNullException("other"); } #endregion if (element.HasRoughPrimitives) { var canCollide = false; var roughPrimitives = element.GetRoughPrimitives().EnsureNotNull(); if (roughPrimitives.Count <= 0) { throw new InvalidOperationException( string.Format( "The element {{{0}}} has empty rough primitives collection.", element)); } // ReSharper disable once LoopCanBeConvertedToQuery // ReSharper disable once ForCanBeConvertedToForeach for (var index = 0; index < roughPrimitives.Count; index++) { var roughPrimitive = roughPrimitives[index]; if (roughPrimitive.HasCollision(other)) { canCollide = true; break; } } if (!canCollide) { return(false); } } var primitives = element.GetPrimitives().EnsureNotNull(); if (primitives.Count <= 0) { throw new InvalidOperationException( string.Format( "The element {{{0}}} has empty primitives collection.", element)); } // ReSharper disable once LoopCanBeConvertedToQuery // ReSharper disable once ForCanBeConvertedToForeach for (var index = 0; index < primitives.Count; index++) { var primitive = primitives[index]; if (CheckPrimitiveCollision(primitive, other)) { return(true); } } return(false); }