protected override void Initialize() { base.Initialize(); _pointButton = new Button(12, 12, "Point", _font, () => SwitchShape(DemoShape.Point), _spriteBatch); _rectButton = new Button(12, 42, "Rectangle", _font, () => SwitchShape(DemoShape.Rectangle), _spriteBatch); _aaSegmentButton = new Button(12, 72, "AA Segment", _font, () => SwitchShape(DemoShape.AASegment), _spriteBatch); _segmentButton = new Button(12, 102, "Segment", _font, () => SwitchShape(DemoShape.Segment), _spriteBatch); _circleButton = new Button(12, 132, "Circle", _font, () => SwitchShape(DemoShape.Circle), _spriteBatch); _fanButton = new Button(12, 162, "Fan", _font, () => SwitchShape(DemoShape.Fan), _spriteBatch); _radiusUpButton = new Button(250, 12, "Radius Up", _font, RadiusUp, _spriteBatch); _radiusDownButton = new Button(250, 42, "Radius Down", _font, RadiusDown, _spriteBatch); _nextDirectionButton = new Button(500, 12, "Direction change", _font, DirectionChange, _spriteBatch); _shapeButtons = new[] { _pointButton, _rectButton, _aaSegmentButton, _segmentButton, _circleButton, _fanButton, }; _shapes = new Dictionary <DemoShape, IGridShape> { [DemoShape.Point] = new GridPoint(Center), [DemoShape.Rectangle] = new GridRectangle( GridBoundingBox.FromMinMax( Center.X - _radius, Center.Y - _radius, Center.X + _radius, Center.Y + _radius)), [DemoShape.AASegment] = new GridAASegment(Center, Center.Translation(0, _radius)), [DemoShape.Segment] = new GridSegment(Center, Center.Translation(10, 10)), [DemoShape.Circle] = new GridCircle(Center, _radius), [DemoShape.Fan] = new GridFan(Center, _radius, _direction8), }; SwitchShape(DemoShape.Point); }
public void TestMax() { var bounds = GridBoundingBox.FromSize(1, 2, 3, 4); Assert.Equal(4, bounds.MaxXExcl); Assert.Equal(6, bounds.MaxYExcl); }
public void TestEquality() { var box1 = GridBoundingBox.FromMinMaxExcl(0, 0, 1, 3); var box2 = GridBoundingBox.FromMinMax(0, 0, 0, 2); var box3 = GridBoundingBox.FromMinMax(0, 0, 1, 3); Assert.Equal(box1, box2); Assert.True(box1 == box2); Assert.NotEqual(box1, box3); Assert.True(box1 != box3); }
public void TestPack() { var b1 = GridBoundingBox.FromMinMax(1, 1, 3, 3); var b2 = GridBoundingBox.FromMinMax(3, 3, 5, 5); var b3 = GridBoundingBox.FromMinMax(1, 5, 3, 7); var b4 = GridBoundingBox.FromMinMax(1, 10, 3, 12); var boxes = new[] { b1, b2, b3, b4 }; GridBoundingBoxes.Pack(boxes); Assert.Empty(GridBoundingBoxes.FindOverlappingBoxes(boxes)); }
public void TestFindCenterOfMass() { var b1 = GridBoundingBox.FromMinMax(1, 1, 3, 3); var b2 = GridBoundingBox.FromMinMax(3, 3, 5, 5); var b3 = GridBoundingBox.FromMinMax(1, 5, 3, 7); var b4 = GridBoundingBox.FromMinMax(1, 10, 3, 12); var boxes = new[] { b1, b2, b3, b4 }; var center = GridBoundingBoxes.FindCenterOfMass(boxes); Assert.Equal(2, center.X); Assert.Equal(5, center.Y); }
public void TestFindOverlappingBoxes() { var b1 = GridBoundingBox.FromMinMax(1, 1, 3, 3); var b2 = GridBoundingBox.FromMinMax(3, 3, 5, 5); var b3 = GridBoundingBox.FromMinMax(1, 5, 3, 7); var b4 = GridBoundingBox.FromMinMax(1, 10, 3, 12); var boxes = new[] { b1, b2, b3, b4 }; var overlappingGroups = GridBoundingBoxes.FindOverlappingBoxes(boxes); Assert.Equal(2, overlappingGroups.Count); Assert.Equal(2, overlappingGroups[0].Count); Assert.Equal(2, overlappingGroups[1].Count); }
public void TestPlaceBeside() { var box1 = GridBoundingBox.FromMinMaxExcl(0, 0, 1, 3); var box2 = GridBoundingBox.FromMinMaxExcl(10, 5, 20, 15); var onTop = box1.PlaceBeside(box2, Grid4Direction.Top); var onRight = box1.PlaceBeside(box2, Grid4Direction.Right); var under = box1.PlaceBeside(box2, Grid4Direction.Bottom); var onLeft = box1.PlaceBeside(box2, Grid4Direction.Left); Assert.Equal(14, onTop.MinX); Assert.Equal(5, onTop.MaxYExcl); Assert.Equal(14, under.MinX); Assert.Equal(15, under.MinY); Assert.Equal(20, onRight.MinX); Assert.Equal(10, onLeft.MaxXExcl); }
public static IEnumerable <GridCoordinatePair> GetFloodFillCoordinates( GridCoordinatePair start, GridCoordinatePair[] walls, GridBoundingBox bounds) { var fill = new List <GridCoordinatePair>(); if (walls == null) { return(fill); } if (!bounds.Contains(start) || ArrayContains(start, walls)) { return(fill); } var queue = new Queue <GridCoordinatePair>(); queue.Enqueue(start); while (queue.Count > 0) { var c = queue.Dequeue(); if (fill.Contains(c) || ArrayContains(c, walls) || !bounds.Contains(c)) { continue; } fill.Add(c); queue.Enqueue(c.Translation(0, -1)); queue.Enqueue(c.Translation(0, 1)); queue.Enqueue(c.Translation(-1, 0)); queue.Enqueue(c.Translation(1, 0)); } return(fill); }
public void TestSizeAssertions(int width, int height) { Assert.Throws <ArgumentException>(() => GridBoundingBox.FromSize(0, 0, width, height)); }
public GridRectangle(GridBoundingBox boundingBox) { _boundingBox = boundingBox; }
public GridRectangle(int minX, int minY, int width, int height) { _boundingBox = GridBoundingBox.FromSize(minX, minY, width, height); }
public SquareGridMap(int width, int height) { Bounds = GridBoundingBox.FromSize(0, 0, width, height); }
public bool Overlaps(GridBoundingBox boundingBox) { return(_positions.Any(boundingBox.Contains)); }