private void AttemptToPlaceSegment(ConnectedScreenSegment segment, Point attemptedLocation) { // the attempts at placement will go in a diagonal like this diagram: // // 1 2 4 7 // 3 5 8 // 6 9 // 10 segment.Location = attemptedLocation; if (_segments.Where(s => s.Placed).Any(s => s.CollidesWidth(segment))) { if (attemptedLocation.X == 0) { AttemptToPlaceSegment(segment, new Point(attemptedLocation.Y + 1, 0)); } else { AttemptToPlaceSegment(segment, new Point(attemptedLocation.X - 1, attemptedLocation.Y + 1)); } } else { segment.Placed = true; } }
public bool CollidesWidth(ConnectedScreenSegment otherSegment) { var myRect = new Rectangle(Location.X, Location.Y, Width, Height); var otherRect = new Rectangle(otherSegment.Location.X, otherSegment.Location.Y, otherSegment.Width, otherSegment.Height); if (Rectangle.Intersect(myRect, otherRect) == Rectangle.Empty) { return(false); } return(_screens.Any(s => otherSegment._screens.Any(o => Rectangle.Intersect(s.GetLocation(this.Location), o.GetLocation(otherSegment.Location)) != Rectangle.Empty))); }
public bool CollidesWidth(ConnectedScreenSegment otherSegment) { var myRect = new Rectangle(Location.X, Location.Y, Width, Height); var otherRect = new Rectangle(otherSegment.Location.X, otherSegment.Location.Y, otherSegment.Width, otherSegment.Height); if (Rectangle.Intersect(myRect, otherRect) == Rectangle.Empty) { return false; } return _screens.Any(s => otherSegment._screens.Any(o => Rectangle.Intersect(s.GetLocation(this.Location), o.GetLocation(otherSegment.Location)) != Rectangle.Empty)); }
private void BuildSegments() { _remainingScreenNames.Clear(); _segments.Clear(); foreach (var screen in _stage.Screens) { _remainingScreenNames.Add(screen.Name); } while (_remainingScreenNames.Any()) { var segment = new ConnectedScreenSegment(); var nextScreen = _stage.Screens.Single(s => s.Name == _remainingScreenNames.First()); segment.GrowLayout(nextScreen, _stage.Screens); _remainingScreenNames.RemoveWhere(s => segment.ScreenNames.Contains(s)); _segments.Add(segment); } }