Exemple #1
0
        public void CompletelySeparateRectanglesDontIntersect()
        {
            var a = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 1, 1));
            var b = TransformedRectangle.FromRectangle(new RectangleF(2, 0, 1, 1));

            Assert.False(a.Intersects(b));
        }
Exemple #2
0
        public void IdenticalRectanglesIntersect()
        {
            var a = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 10, 10));
            var b = a;

            Assert.True(a.Intersects(b));
        }
Exemple #3
0
        public void RotatedRectanglesIntersect()
        {
            var a = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 10, 10), 3.2f);
            var b = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 10, 10), 1.2f);

            Assert.True(a.Intersects(b));
        }
Exemple #4
0
        public void LargerRectangleContainsSmallerOne()
        {
            var a = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 10, 10));
            var b = TransformedRectangle.FromRectangle(new RectangleF(-5, -5, 15, 15));

            Assert.True(a.Intersects(b));
        }
Exemple #5
0
 public BoxCollider(RectangleF rect, float height = 1.0f) : base(rect, height)
 {
     _AABox                  = new AxisAlignedBoundingBox(Vector3.Zero, new Vector3(rect.Width, rect.Height, height));
     _worldBox               = new BoundingBox(rect, height);
     WorldAABox              = new AxisAlignedBoundingBox(new Vector3(rect.X, rect.Y, 0), new Vector3(rect.X + rect.Width, rect.Y + rect.Height, height));
     BoundingArea            = TransformedRectangle.FromRectangle(rect);
     AxisAlignedBoundingArea = rect;
 }
Exemple #6
0
        public override void Update(Transform transform)
        {
            WorldBounds = BoundingSphere.Transform(SphereBounds, transform.Matrix);
            var width = SphereBounds.Radius * 2.0f;

            AxisAlignedBoundingArea = new RectangleF(transform.Translation.Vector2XY() - new Vector2(SphereBounds.Radius, SphereBounds.Radius), width, width);
            BoundingArea            = TransformedRectangle.FromRectangle(AxisAlignedBoundingArea);
        }
Exemple #7
0
        protected SphereCollider(RectangleF rect)
            : base(new Transform(Matrix4x4.Identity), 0)
        {
            var radius = new Vector2(rect.Width, rect.Height).Length() / 2.0f;

            SphereBounds = new BoundingSphere(Vector3.Zero, radius);

            var center = new Vector3(rect.X + rect.Width / 2.0f, rect.Y + rect.Height / 2.0f, 0);

            WorldBounds             = new BoundingSphere(center, radius);
            AxisAlignedBoundingArea = rect;
            BoundingArea            = TransformedRectangle.FromRectangle(rect);
        }
Exemple #8
0
        public sealed override void Update(Transform transform)
        {
            base.Update(transform);
            _worldBox  = new BoundingBox(_AABox, transform.Matrix);
            WorldAABox = new AxisAlignedBoundingBox(_worldBox);

            var width  = WorldAABox.Max.X - WorldAABox.Min.X;
            var height = WorldAABox.Max.Y - WorldAABox.Min.Y;

            AxisAlignedBoundingArea = new RectangleF(WorldAABox.Min.X, WorldAABox.Min.Y, width, height);

            width  = _AABox.Max.X - _AABox.Min.X;
            height = _AABox.Max.Y - _AABox.Min.Y;
            var rect = new RectangleF(_AABox.Min.X + Transform.Translation.X, _AABox.Min.Y + Transform.Translation.Y, width, height);

            BoundingArea = TransformedRectangle.FromRectangle(rect, Transform.Yaw);
        }
Exemple #9
0
        public void IntersectsCircle(float x, float y, float radius, bool expected)
        {
            var rect = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 5, 5), 0.75f);

            Assert.Equal(expected, rect.Intersects(new Vector2(x, y), radius));
        }
        public void Contains(float x, float y, bool expected)
        {
            var sut = TransformedRectangle.FromRectangle(new RectangleF(0, 0, 4, 4), 0.75f);

            Assert.Equal(expected, sut.Contains(new Vector2(x, y)));
        }
        public void IntersectsCircle_AA_Translated(float x, float y, float width, float height, float cx, float cy, float radius, bool expected)
        {
            var rect = TransformedRectangle.FromRectangle(new RectangleF(x, y, width, height), 0);

            Assert.Equal(expected, rect.Intersects(new Vector2(cx, cy), radius));
        }