public bool AreAdjacent(IRectangle rectangle, IRectangle anotherRectangle) { //If any lines are inside another rectangle it can't be adjacent if(_decomposer.GetLines(anotherRectangle).Any(line => rectangle.Contains(line.StartingPoint) && rectangle.Contains(line.EndingPoint))) return false; if (_decomposer.GetLines(rectangle).Any(line => anotherRectangle.Contains(line.StartingPoint) && anotherRectangle.Contains(line.EndingPoint))) return false; //If rectangles intersect they are not adjacent if (_intersectionService.Solve(rectangle, anotherRectangle).HasIntersection) return false; //For two rectangles to be adjacent the must share exactly 1 one or have 1 line exist in another var matchingLines = new List<ILine>(); foreach (var line in _decomposer.GetLines(rectangle)) { foreach (var anotherLine in _decomposer.GetLines(anotherRectangle)) { if (line.Contains(anotherLine) || anotherLine.Contains(line)) { if(line.Contains(anotherLine) && !matchingLines.Contains(anotherLine)) matchingLines.Add(anotherLine); if(anotherLine.Contains(line) && !matchingLines.Contains(line)) matchingLines.Add(line); } } } return matchingLines.Count == 1; }
public List <IPoint <IUserObject> > GetPoints(IRectangle aTargetBoundary, bool aIsAcceptChildren) { List <IPoint <IUserObject> > foundPoints = new List <IPoint <IUserObject> >(); if (null == this.points || !this.boundary.IntersectsWithRectangle(aTargetBoundary)) { return(foundPoints); } foreach (IPoint <IUserObject> p in this.points) { if (aTargetBoundary.Contains(p)) { foundPoints.Add(p); } } if (aIsAcceptChildren && null != this.subTrees) { foreach (IQuadTree subTree in this.subTrees) { foundPoints.AddRange(subTree.GetPoints(aTargetBoundary, aIsAcceptChildren)); } } return(foundPoints); }
/// <summary> /// brings the first leaf which rectangle was hit and the delegate is happy with the object /// </summary> /// <param name="point"></param> /// <param name="hitTestForPointDelegate"></param> /// <returns></returns> public RectangleNode <T, P> FirstHitNode(P point, Func <P, T, HitTestBehavior> hitTestForPointDelegate) { if (rectangle.Contains(point)) { if (IsLeaf) { if (hitTestForPointDelegate != null) { return(hitTestForPointDelegate(point, UserData) == HitTestBehavior.Stop ? this : null); } return(this); } return(Left.FirstHitNode(point, hitTestForPointDelegate) ?? Right.FirstHitNode(point, hitTestForPointDelegate)); } return(null); }
/// <summary> /// Checks if the given pixel is located /// within the given rectangle. /// </summary> /// <param name="Pixel">A pixel of type T.</param> /// <param name="Rectangle">A rectangle of type T.</param> /// <returns>True if the pixel is located within the given rectangle; False otherwise.</returns> public static Boolean IsInRectangle <T>(this IPixel <T> Pixel, IRectangle <T> Rectangle) where T : IEquatable <T>, IComparable <T>, IComparable { #region Initial Checks if (Pixel == null) { throw new ArgumentNullException("The given pixel must not be null!"); } if (Rectangle == null) { throw new ArgumentNullException("The given rectangle must not be null!"); } #endregion return(Rectangle.Contains(Pixel)); }
/// <summary> /// Checks if the given pixel is located /// within the given rectangle. /// </summary> /// <param name="Rectangle">A rectanlge of type T.</param> /// <param name="Pixel">A pixel of type T.</param> /// <returns>True if the pixel is located within the given rectangle; False otherwise.</returns> public static Boolean Contains <T>(this IRectangle <T> Rectangle, IPixel <T> Pixel) where T : IEquatable <T>, IComparable <T>, IComparable { return(Rectangle.Contains(Pixel.X, Pixel.Y)); }
/// <summary> /// Remove all pixels located within the given rectangle. /// </summary> /// <param name="Rectangle">A rectangle selecting which pixels to remove.</param> public void Remove(IRectangle <T> Rectangle) { #region Initial Checks if (Rectangle == null) { throw new ArgumentNullException("The given rectangle must not be null!"); } #endregion #region Remove embedded voxel lock (this) { var _List = new List <IPixel <T> >(); foreach (var _Pixel in EmbeddedPixels) { if (Rectangle.Contains(_Pixel)) { _List.Add(_Pixel); } } foreach (var _Pixel in _List) { EmbeddedPixels.Remove(_Pixel); } } #endregion #region Check subtrees if (Subtree1 != null) { if (Subtree1.Overlaps(Rectangle)) { Subtree1.Remove(Rectangle); } } if (Subtree2 != null) { if (Subtree2.Overlaps(Rectangle)) { Subtree2.Remove(Rectangle); } } if (Subtree3 != null) { if (Subtree3.Overlaps(Rectangle)) { Subtree3.Remove(Rectangle); } } if (Subtree4 != null) { if (Subtree4.Overlaps(Rectangle)) { Subtree4.Remove(Rectangle); } } #endregion }
/// <summary> /// Return all pixels within the given rectangle. /// </summary> /// <param name="Rectangle">A rectangle selecting which pixels to return.</param> public IEnumerable <IPixel <T> > Get(IRectangle <T> Rectangle) { #region Initial Checks if (Rectangle == null) { throw new ArgumentNullException("The given Rectangle must not be null!"); } #endregion #region Check embedded pixels foreach (var _Pixel in EmbeddedPixels) { if (Rectangle.Contains(_Pixel)) { yield return(_Pixel); } } #endregion #region Check subtrees if (Subtree1 != null) { if (Subtree1.Overlaps(Rectangle)) { foreach (var _Pixel in Subtree1.Get(Rectangle)) { yield return(_Pixel); } } } if (Subtree2 != null) { if (Subtree2.Overlaps(Rectangle)) { foreach (var _Pixel in Subtree2.Get(Rectangle)) { yield return(_Pixel); } } } if (Subtree3 != null) { if (Subtree3.Overlaps(Rectangle)) { foreach (var _Pixel in Subtree3.Get(Rectangle)) { yield return(_Pixel); } } } if (Subtree4 != null) { if (Subtree4.Overlaps(Rectangle)) { foreach (var _Pixel in Subtree4.Get(Rectangle)) { yield return(_Pixel); } } } #endregion }
private void ProcessComponentInputs(IGuiElement component, IRectangle clipRect) { // does the element have mouse processing enabled? if (!component.GetMouseEnabled()) { return; } var processingData = component.GetLayoutProcessingData(); // is the mouse actually hovering over the element var containsCurrent = processingData.AbsoluteGeometry.Contains(GuiStage.MousePosition) && clipRect.Contains(GuiStage.MousePosition) && component.GetLayout().Visible ; // was it hovering over the element in the last frame var containsPrevious = processingData.MouseWasOver; // remember the current situation for the next frame processingData.MouseWasOver = containsCurrent; if (containsCurrent) { _result.GuiElementsUnderMouse.Add(component); } // check for mouse over if (containsCurrent && !containsPrevious) { _result.MouseOverEvent.Add(component); } // check for mouse out if (!containsCurrent && containsPrevious) { _result.MouseOutEvent.Add(component); } // check for clicks if (containsCurrent) { // check for left mouse down if (!_previousMouseButtonLeft && _currentMouseButtonLeft) { _result.LeftMouseDownEvent.Add(component); } // check for left mouse up / clicked if (_previousMouseButtonLeft && !_currentMouseButtonLeft) { _result.LeftMouseUpEvent.Add(component); _result.ClickedEvent.Add(component); // detect double click var now = DateTime.Now; if ((now - processingData.LastClickTimestamp).TotalMilliseconds < 500) { _result.DoubleClickedEvent.Add(component); } // remember the last click time processingData.LastClickTimestamp = DateTime.Now; } // check for right mouse down if (!_previousMouseButtonRight && _currentMouseButtonRight) { _result.RightMouseDownEvent.Add(component); } // check for right mouse up if (_previousMouseButtonRight && !_currentMouseButtonRight) { _result.RightMouseUpEvent.Add(component); } // check for middle mouse down if (!_previousMouseButtonMiddle && _currentMouseButtonMiddle) { _result.MiddleMouseDownEvent.Add(component); } // check for right mouse up if (_previousMouseButtonMiddle && !_currentMouseButtonMiddle) { _result.MiddleMouseUpEvent.Add(component); } } }