/// <summary> /// Checks if the given line shares some /// area with this line. /// </summary> /// <param name="Line">A line of type T.</param> /// <returns>True if the line shares some area with this line; False otherwise.</returns> public Boolean Overlaps(ILine1D <T> Line) { #region Initial Checks if (Line == null) { throw new ArgumentNullException("The given line must not be null!"); } #endregion // Check if any corner of the given line // is located within this line if (Contains(Line.Left)) { return(true); } if (Contains(Line.Right)) { return(true); } return(false); }
/// <summary> /// Compares two lines for equality. /// </summary> /// <param name="ILine">A line to compare with.</param> /// <returns>True if both match; False otherwise.</returns> public Boolean Equals(ILine1D <T> ILine) { if ((Object)ILine == null) { return(false); } return(this.Left.Equals(ILine.Left) && this.Right.Equals(ILine.Right)); }
/// <summary> /// Remove all elements located within the given line. /// </summary> /// <param name="Line">A line selecting which elements to remove.</param> public void Remove(ILine1D <T> Line) { #region Initial Checks if (Line == null) { throw new ArgumentNullException("The given line must not be null!"); } #endregion #region Remove embedded data lock (this) { var _List = new List <T>(); foreach (var _Element in EmbeddedData) { if (Line.Contains(_Element)) { _List.Add(_Element); } } foreach (var _Element in _List) { EmbeddedData.Remove(_Element); } } #endregion #region Check subtrees if (Subtree1 != null) { if (Subtree1.Overlaps(Line)) { Subtree1.Remove(Line); } } if (Subtree2 != null) { if (Subtree2.Overlaps(Line)) { Subtree2.Remove(Line); } } #endregion }
/// <summary> /// Return all elements within the given line. /// </summary> /// <param name="Line">A line selecting which elements to return.</param> public IEnumerable <T> Get(ILine1D <T> Line) { #region Initial Checks if (Line == null) { throw new ArgumentNullException("The given line must not be null!"); } #endregion #region Check embedded element foreach (var _Element in EmbeddedData) { if (Line.Contains(_Element)) { yield return(_Element); } } #endregion #region Check subtrees if (Subtree1 != null) { if (Subtree1.Overlaps(Line)) { foreach (var _Element in Subtree1.Get(Line)) { yield return(_Element); } } } if (Subtree2 != null) { if (Subtree2.Overlaps(Line)) { foreach (var _Element in Subtree2.Get(Line)) { yield return(_Element); } } } #endregion }