Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }