public void Contains_Outside() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.IsFalse(c.Contains(new MVector2(32f, 32f))); Assert.IsFalse(c.Contains(new MVector2(-32f, -32f))); Assert.IsFalse(c.Contains(new MVector2(32f, -32f))); Assert.IsFalse(c.Contains(new MVector2(-32f, 32f))); }
public void Contains_Inside() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.IsTrue(c.Contains(MVector2.Zero)); Assert.IsTrue(c.Contains(new MVector2(0, 32f))); Assert.IsTrue(c.Contains(new MVector2(0, -32f))); Assert.IsTrue(c.Contains(new MVector2(32f, 0))); Assert.IsTrue(c.Contains(new MVector2(-32f, 0))); }
public void CellsFromCircle_Correct() { MCircle circle = new MCircle(new MVector2(16f, 16f), 17f); List<MPoint2> expected = new List<MPoint2>() { new MPoint2(0,0), new MPoint2(0,-1), new MPoint2(-1,0), new MPoint2(1,0), new MPoint2(0,1) }; var result = grid.CellsFromCircle(circle); CollectionAssert.AreEquivalent(expected, result); }
public void SeparationVector_Rectangle_BottomLeft_CorrectDirection() { MCircle c = new MCircle(new MVector2(-2, 2), 2f); MRectangle r = new MRectangle(-1, -1, 2, 2); MVector2 sepVector = c.SeparationVector(r); Assert.IsTrue(sepVector.X < 0); Assert.IsTrue(sepVector.Y > 0); }
/// <summary> /// Returns the shortest vector to translate the <see cref="MCircle"/> with in order to separate from the provided <see cref="MCircle"/>. /// </summary> /// <param name="circle">The circle to separate from.</param> /// <returns></returns> public MVector2 SeparationVector(MCircle circle) { MVector2 deltaVector = (circle.Origin - this.Origin); float minDistance = circle.Radius + this.Radius; float toMove = deltaVector.Length() - minDistance; if (toMove < 0) { return deltaVector.Normalized * toMove; } else { return MVector2.Zero; } }
public void Intersects_Top() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.IsTrue(c.Intersects(new MRectangle(-64f, -20f, 128f, 128f))); }
public void Intersects_OutsideCorner_False() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); Assert.IsFalse(c.Intersects(new MRectangle(-32f, -32f, 64f, 64f))); }
public void Translate_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); MVector2 translation = new MVector2(-32, -32); Assert.AreEqual(new MCircle(c.Origin + translation, c.Radius), c.Translate(translation)); }
public void SeparationVector_Rectangle_TopRight_CorrectDirection() { MCircle c = new MCircle(new MVector2(2, -2), 2f); MRectangle r = new MRectangle(-1, -1, 2, 2); MVector2 sepVector = c.SeparationVector(r); Assert.IsTrue(sepVector.X > 0); Assert.IsTrue(sepVector.Y < 0); }
public void SeparationVector_Rectangle_Outside_ZeroVector() { MCircle c = new MCircle(new MVector2(100, -100), 2f); MRectangle r = new MRectangle(1, -32, 1, 64); MVector2 sepVector = c.SeparationVector(r); Assert.AreEqual(MVector2.Zero, sepVector); }
public void Separate_MVector2_Separated() { MCircle c1 = new MCircle(new MVector2(-64, -64), 30f); MVector2 v = new MVector2(-50, -50); MCircle separated = c1.Separate(v); Assert.IsTrue(separated.SeparationVector(v) == MVector2.Zero); }
public void Separate_Circle_Separated() { MCircle c1 = new MCircle(new MVector2(-64, -64), 30f); MCircle c2 = new MCircle(new MVector2(-54, -74), 20f); MCircle separated = c1.Separate(c2); Assert.IsTrue(separated.SeparationVector(c2) == MVector2.Zero); }
public void Scale_NegativeScaling_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); float factor = -3; Assert.AreEqual(new MCircle(c.Origin, c.Radius * -factor), c.Scale(factor)); }
public void Area() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.AreEqual(32f * 32f * (float)Math.PI, c.Area); }
public void Resize_NegativeRadius_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); float radius = -30; Assert.AreEqual(new MCircle(c.Origin, -radius), c.Resize(radius)); }
public void SeparationVector_Rectangle_Outside_Corner_ZeroVector() { MCircle c = new MCircle(new MVector2(-128, 128), 32f); MRectangle r = new MRectangle(-64, -64, 128, 128); MVector2 sepVector = c.SeparationVector(r); Assert.AreEqual(MVector2.Zero, sepVector); }
public void Separate_Rectangle_Separated() { MCircle c1 = new MCircle(new MVector2(-64, -64), 30f); MRectangle r = new MRectangle(-128, 0, 128, 70); MCircle separated = c1.Separate(r); Assert.IsTrue(separated.SeparationVector(r) == MVector2.Zero); }
public void SeparationVector_Rectangle_Right_Correct() { MCircle c = new MCircle(new MVector2(3, 0), 2f); MRectangle r = new MRectangle(1, -32, 1, 64); MVector2 sepVector = c.SeparationVector(r); MVector2 expected = new MVector2(1, 0); Assert.AreEqual(expected, sepVector); }
public void SeparationVector_Circle_Correct() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MCircle c2 = new MCircle(new MVector2(0, 2), 1f); MVector2 v = c1.SeparationVector(c2); MVector2 expected = new MVector2(0, 2); Assert.AreEqual(expected, v); }
public void SeparationVector_Rectangle_Up_Correct() { MCircle c = new MCircle(new MVector2(0, 0), 2f); MRectangle r = new MRectangle(-32, 1, 64, 1); MVector2 sepVector = c.SeparationVector(r); MVector2 expected = new MVector2(0, -1); Assert.AreEqual(expected, sepVector); }
public void SeparationVector_Circle_Outside_ZeroVector() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MCircle c2 = new MCircle(new MVector2(-300, 2), 1f); MVector2 v = c1.SeparationVector(c2); Assert.AreEqual(MVector2.Zero, v); }
public void Circumference() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.AreEqual(2 * 32f * (float)Math.PI, c.Circumference); }
public void SeparationVector_MVector2_Correct() { MCircle c1 = new MCircle(new MVector2(0, 3), 2f); MVector2 v = new MVector2(0, 4); MVector2 separated = c1.SeparationVector(v); MVector2 expected = new MVector2(0, -1); Assert.AreEqual(expected, separated); }
public void Intersects_RectangleInside() { MCircle c = new MCircle(MVector2.Zero, 32f); Assert.IsTrue(c.Intersects(new MRectangle(-1f, -1f, 2f, 2f))); }
public void SeparationVector_MVector2_Outside_ZeroVector() { MCircle c1 = new MCircle(new MVector2(0, 300), 2f); MVector2 v = new MVector2(0, 4); MVector2 separated = c1.SeparationVector(v); Assert.AreEqual(MVector2.Zero, separated); }
public void MoveTo_Correct() { MCircle c = new MCircle(new MVector2(-64, -64), 30f); MVector2 position = new MVector2(-32, -32); Assert.AreEqual(new MCircle(position, c.Radius), c.MoveTo(position)); }
/// <summary> /// Separates the <see cref="MCircle"/> from the specified <see cref="MCircle"/>, translating it with the shortest distance that makes them not intersect. /// </summary> /// <param name="circle">The circle to separate from.</param> /// <returns></returns> public MCircle Separate(MCircle circle) => this.Translate(this.SeparationVector(circle));