public ViewRectangle GetIntersection(ViewRectangle rectangleA, ViewRectangle rectangleB) { Rectangle firstRectangle = rectangleA.ConvertToRectangle(); Rectangle secondRectangle = rectangleB.ConvertToRectangle(); return(new ViewRectangle(firstRectangle.GetIntersection(secondRectangle))); }
public bool TestContain(ViewRectangle rectangleA, ViewRectangle rectangleB) { Rectangle firstRectangle = rectangleA.ConvertToRectangle(); Rectangle secondRectangle = rectangleB.ConvertToRectangle(); return(firstRectangle.Contains(secondRectangle)); }
public int ViewPointToItemIndex(Point viewPt) { if (!ViewRectangle.Contains(viewPt)) { return(-1); } Size itemSize = ItemSize; int index = viewPt.X / itemSize.Width; return(index); }
public ViewRectangle GetContained(ViewRectangle rectangleA, ViewRectangle rectangleB) { Rectangle firstRectangle = rectangleA.ConvertToRectangle(); Rectangle secondRectangle = rectangleB.ConvertToRectangle(); if (firstRectangle.Contains(secondRectangle)) { return(rectangleB); } return(new ViewRectangle(null)); }
private void AddRectangle(double startX, double startY, double width, double height) { ViewRectangle viewRectangle = new ViewRectangle(startX, startY, width, height); DataContext.Rectangles.Add(viewRectangle); _notFirstRectangle = true; Rectangle rect = new Rectangle { Width = width, Height = width, Stroke = Brushes.Black }; RectCanvas.Children.Add(rect); Canvas.SetLeft(rect, startX); Canvas.SetTop(rect, startY); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); MouseDownButton = e.Button; if (e.Button == MouseButtons.Left) { TempViewRectangle = ViewRectangle; Capture = true; MouseDownPoint = new Point(e.X, e.Y); if (!ViewRectangle.Contains(e.X, e.Y)) { int x = Math.Min(FullRectangle.X + FullRectangle.Width - ViewRectangle.Width, Math.Max(FullRectangle.X, (e.X - ViewRectangle.Width / 2))); int y = Math.Min(FullRectangle.Y + FullRectangle.Height - ViewRectangle.Height, Math.Max(FullRectangle.Y, (e.Y - ViewRectangle.Height / 2))); SetViewRectangle(new Rectangle(x, y, ViewRectangle.Width, ViewRectangle.Height)); } MouseDownViewRectangle = ViewRectangle; } }
private void CheckContainment_Click(object sender, RoutedEventArgs e) { List <ViewRectangle> containedAreas = new List <ViewRectangle>(); // Go through all of the rectangles on the page, compare them to each other for intersection for (int i = 0; i < DataContext.Rectangles.Count; i++) { for (int j = 0; j < DataContext.Rectangles.Count; j++) { if (i != j) { ViewRectangle area = DataContext.GetContained(DataContext.Rectangles[i], DataContext.Rectangles[j]); if (area.Equals(null)) { continue; } containedAreas.Add(area); } } } ColorIntersectingRectangles(containedAreas); }