Example #1
0
 /// <summary>
 /// Determines if the current BoundingRectangle contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the BoundingRectangle contains the circle.</returns>
 public override bool Contains(BoundingCircle circle)
 {
     return(this.Contains(new Vector2d(circle.Position.X - circle.Radius, circle.Position.Y)) &&
            this.Contains(new Vector2d(circle.Position.X, circle.Position.Y - circle.Radius)) &&
            this.Contains(new Vector2d(circle.Position.X + circle.Radius, circle.Position.Y)) &&
            this.Contains(new Vector2d(circle.Position.X, circle.Position.Y + circle.Radius)));
 }
        public void IsCollidingWithRectangleWorks()
        {
            var rect = new BoundingRectangle(Vector2d.Zero, new Size2d(10, 6))
            {
                Position = new Vector2d(5, 3)
            };

            var circle = new BoundingCircle(Vector2d.Zero, 3)
            {
                Position = new Vector2d(14, 3)
            };
            
            Assert.False(circle.Intersects(rect));
            circle.Position.X--;
            Assert.True(circle.Intersects(rect));
            rect.Rotation = Math.PI * .5;
            rect.Position.X = 3;
            rect.Position.Y = 5;

            circle.Position.X = 8;
            circle.Position.Y = 12;

            Assert.True(circle.Intersects(rect));

            circle = new BoundingCircle(Vector2d.Zero, 50)
            {
                Position = new Vector2d(156, 165)
            };
            rect = new BoundingRectangle(Vector2d.Zero, new Size2d(200, 100))
            {
                Position = new Vector2d(300, 200)
            };

            Assert.True(circle.Intersects(rect));

            circle.Position.X = 300;
            circle.Position.Y = 350;

            Assert.False(circle.Intersects(rect));
        }
        public void IsCollidingWithOtherCircleWorks()
        {
            var circle1 = new BoundingCircle(Vector2d.Zero, 10)
            {
                Position = new Vector2d(10, 5)
            };

            var circle2 = new BoundingCircle(Vector2d.Zero, 6)
            {
                Position = new Vector2d(17, 5)
            };

            Assert.True(circle1.Intersects(circle2));

            circle2.Position.X = -5;

            Assert.True(circle1.Intersects(circle2));

            circle2.Position.X = -6;

            Assert.False(circle1.Intersects(circle2));
        }
        public void CircumferenceWorks()
        {
            var obj = new BoundingCircle(Vector2d.Zero, 10);

            Assert.Equal(Math.Round(obj.Circumference()), 63);
        }
        public void AreaWorks()
        {
            var obj = new BoundingCircle(Vector2d.Zero, 10);

            Assert.Equal(Math.Round(obj.Area()), 314);
        }
Example #6
0
 /// <summary>
 /// Determines if the current BoundingRectangle is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="obj">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the BoundingRectangle intersects the BoundingCircle.</returns>
 public override bool Intersects(BoundingCircle obj)
 {
     return(obj.Intersects((BoundingRectangle)this));
 }
 /// <summary>
 /// Determines if the current BoundingCircle is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the BoundingCircle intersects the circle.</returns>
 public override bool Intersects(BoundingCircle circle)
 {
     return(Position.Distance(circle.Position).Length() < Radius + circle.Radius);
 }
 /// <summary>
 /// Determines if the current BoundingCircle is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the BoundingCircle intersects the circle.</returns>
 public override bool Intersects(BoundingCircle circle)
 {
     return Position.Distance(circle.Position).Length() < Radius + circle.Radius;
 }
 /// <summary>
 /// Determines if the current BoundingRectangle contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the BoundingRectangle contains the circle.</returns>
 public override bool Contains(BoundingCircle circle)
 {
     return this.Contains(new Vector2d(circle.Position.X - circle.Radius, circle.Position.Y)) &&
         this.Contains(new Vector2d(circle.Position.X, circle.Position.Y - circle.Radius)) &&
         this.Contains(new Vector2d(circle.Position.X + circle.Radius, circle.Position.Y)) &&
         this.Contains(new Vector2d(circle.Position.X, circle.Position.Y + circle.Radius));
 }
 /// <summary>
 /// Determines if the current BoundingRectangle is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="obj">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the BoundingRectangle intersects the BoundingCircle.</returns>
 public override bool Intersects(BoundingCircle obj)
 {
     return obj.Intersects((BoundingRectangle)this);
 }
Example #11
0
 /// <summary>
 /// Determines if the current bounded object is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the bounds intersects the BoundingCircle.</returns>
 public abstract bool Intersects(BoundingCircle circle);
Example #12
0
 /// <summary>
 /// Determines if the current bounded object completely contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the bounds contains the circle.</returns>
 public abstract bool Contains(BoundingCircle circle);
Example #13
0
 /// <summary>
 /// Determines if the current bounded object is intersecting the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">BoundingCircle to check intersection with.</param>
 /// <returns>Whether the bounds intersects the BoundingCircle.</returns>
 public abstract bool Intersects(BoundingCircle circle);
Example #14
0
 /// <summary>
 /// Determines if the current bounded object completely contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the bounds contains the circle.</returns>
 public abstract bool Contains(BoundingCircle circle);
 /// <summary>
 /// Determines if the current BoundingCircle contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the BoundingCircle contains the circle.</returns>
 public override bool Contains(BoundingCircle circle)
 {
     return(circle.Position.Distance(this.Position).Length() + circle.Radius <= this.Radius);
 }
        public void ContainsPointWorks()
        {
            var circle = new BoundingCircle(Vector2d.Zero, 10)
            {
                Position = new Vector2d(10, 5)
            };

            Assert.False(circle.Contains(Vector2d.Zero));
            Assert.True(circle.Contains(new Vector2d(3, 3)));
        }
 /// <summary>
 /// Determines if the current BoundingCircle contains the provided BoundingCircle.
 /// </summary>
 /// <param name="circle">A circle to check containment on.</param>
 /// <returns>Whether the BoundingCircle contains the circle.</returns>
 public override bool Contains(BoundingCircle circle)
 {
     return circle.Position.Distance(this.Position).Length() + circle.Radius <= this.Radius;
 }