public static void UnitTest() { xAABB2 aabb1 = new xAABB2(); XUtils.Assert(aabb1.mIsValid == false); xAABB2 aabb2 = new xAABB2(Vector2.Zero); xAABB2 aabb3 = new xAABB2(Vector2.Zero, 1f); xAABB2 aabb4 = new xAABB2(Vector2.Zero, Vector2.Zero); XUtils.Assert(aabb2.IsValid() && aabb3.IsValid() && aabb4.IsValid()); aabb2.Reset(); XUtils.Assert(!aabb2.IsValid()); Vector2 oneTwo = new Vector2(1f, 2f); Vector2 negTwoFour = -2f * oneTwo; Vector2 TwentyTen = new Vector2(20f, 10f); const float kTol = 0.001f; aabb2.Set(oneTwo); XUtils.AssertVal(aabb2.mMin, oneTwo, kTol); XUtils.AssertVal(aabb2.mMax, oneTwo, kTol); XUtils.Assert(aabb2.IsValid()); //aabb2.Set( oneTwo, negTwoFour ); inside out, asserts, good aabb2.Set(negTwoFour, oneTwo); XUtils.Assert(aabb2.Contains(Vector2.Zero)); XUtils.Assert(!aabb2.Contains(TwentyTen)); XUtils.Assert(aabb2.Contains(negTwoFour)); XUtils.Assert(aabb2.Contains(oneTwo)); XUtils.Assert(!aabb2.Contains(-TwentyTen)); //aabb2.Set( oneTwo, -3f ); asserts on negative radius, good Vector2 fiveFive = new Vector2(5f, 5f); Vector2 sixSeven = oneTwo + fiveFive; Vector2 negFourThree = new Vector2(-4f, -3f); Vector2 epsilon = new Vector2(kTol, kTol); aabb2.Set(oneTwo, 5f); XUtils.Assert(aabb2.Contains(oneTwo)); XUtils.Assert(aabb2.Contains(fiveFive)); XUtils.Assert(aabb2.Contains(negFourThree)); XUtils.Assert(!aabb2.Contains(TwentyTen)); XUtils.Assert(!aabb2.Contains(-TwentyTen)); XUtils.Assert(aabb2.Contains(Vector2.Zero)); XUtils.Assert(aabb2.Contains(negFourThree + epsilon)); XUtils.Assert(!aabb2.Contains(negFourThree - epsilon)); XUtils.Assert(aabb2.Contains(sixSeven - epsilon)); XUtils.Assert(!aabb2.Contains(sixSeven + epsilon)); aabb2.Set(Vector2.Zero); XUtils.Assert(!aabb2.IsNonDegenerate()); aabb2.Add(Vector2.UnitX); XUtils.Assert(!aabb2.IsNonDegenerate()); XUtils.Assert(aabb2.Contains(new Vector2(0.5f, 0f))); aabb2.Add(oneTwo); XUtils.Assert(aabb2.IsNonDegenerate()); XUtils.Assert(aabb2.Contains(new Vector2(0.5f, 1f))); aabb2.Reset(); aabb2.Add(Vector2.Zero); XUtils.Assert(aabb2.IsValid()); aabb2.Reset(); aabb2.Add(-fiveFive); aabb2.Add(TwentyTen); XUtils.AssertVal(aabb2.GetMin(), -fiveFive, kTol); XUtils.AssertVal(aabb2.GetMax(), TwentyTen, kTol); XUtils.AssertVal(aabb2.GetCenter(), new Vector2(7.5f, 2.5f), kTol); XUtils.AssertVal(aabb2.GetRadius(), new Vector2(12.5f, 7.5f), kTol); XUtils.AssertVal(aabb2.GetSize(), new Vector2(25f, 15f), kTol); XUtils.AssertVal(aabb2.GetArea(), 375f, kTol); aabb2.Reset(); aabb2.Add(Vector2.Zero); aabb2.Add(oneTwo); aabb2.ScaleWorld(4f); XUtils.AssertVal(aabb2.GetArea(), 32f, kTol); aabb2.Translate(fiveFive); Vector2 center2 = new Vector2(7f, 9f); XUtils.AssertVal(aabb2.GetArea(), 32f, kTol); XUtils.AssertVal(aabb2.GetCenter(), center2, kTol); XUtils.Assert(!aabb2.Contains(oneTwo)); XUtils.Assert(aabb2.Contains(new Vector2(6f, 8f))); //aabb2.ScaleWorld( -1f ); asserts negative scalar, good //aabb2.ScaleLocal( -50f ); asserts negative scalar, good aabb2.ScaleLocal(0.25f); XUtils.AssertVal(aabb2.GetCenter(), center2, kTol); XUtils.AssertVal(aabb2.GetArea(), 2f, kTol); XUtils.Assert(!aabb2.Contains(new Vector2(6f, 8f))); XUtils.Assert(aabb2.Contains(center2)); aabb2.Reset(); aabb2.Add(Vector2.Zero); aabb2.Add(oneTwo); aabb2.Resize(new Vector2(0.1f, -0.3f)); XUtils.AssertVal(aabb2.GetArea(), 1.68f, kTol); XUtils.Assert(!aabb2.Contains(Vector2.Zero)); XUtils.Assert(aabb2.Contains(new Vector2(-0.05f, 1.4f))); }
public static void unitTest() { //XUtils.Assert( false, "hello" ); xCoord a = new xCoord(); XUtils.Assert(a.x == 0); XUtils.Assert(a.y == 0); xCoord b = a; XUtils.Assert(b.x == 0); XUtils.Assert(b.y == 0); xCoord c = new xCoord(-10, 20.0f); XUtils.Assert(c.x == -10); XUtils.Assert(c.y == 20); xCoord d = 5 * c; xCoord e = new xCoord(-50, 100); XUtils.Assert(d == e); XUtils.Assert(d != b); XUtils.Assert(d.Equals(e)); XUtils.Assert(!d.Equals(a)); #pragma warning disable CS1718 XUtils.Assert(d == d); #pragma warning restore CS1718 xCoord f = new xCoord(2, 6); xCoord g = new xCoord(-11, 33); xCoord h = f + g; xCoord i = f - g; xCoord j = f - f; xCoord k = g - g - g; XUtils.Assert(h == new xCoord(-9, 39)); XUtils.Assert(i == new xCoord(13, -27)); XUtils.Assert(j == new xCoord()); XUtils.Assert(k == -g); xCoord l = new xCoord(2, -5); xCoord m = 4 * l; xCoord n = -3.5f * l; xCoord o = l * 4; XUtils.Assert(m == new xCoord(8, -20)); XUtils.Assert(n == new xCoord(-7, 17)); XUtils.Assert(o == m); xCoord p = new xCoord(11.4, -55.6); xCoord q = new xCoord(11.6, -55.4); XUtils.Assert(p == new xCoord(11, -55)); XUtils.Assert(p == new xCoord(11, -55)); XUtils.AssertVal(a.getLength(), 0, 0.0001); XUtils.AssertVal(f.getLength(), System.Math.Sqrt(40), 0.0001); XUtils.AssertVal(g.getLength(), System.Math.Sqrt(33 * 33 + 11 * 11), 0.001); xCoord r = g.clamp(new xCoord(0, 0), new xCoord(100, 100)); xCoord s = g.clamp(new xCoord(-30, -10), new xCoord(0, -1)); xCoord t = g.clamp(new xCoord(-1000, -1000), new xCoord(1000, 1000)); xCoord u = g.clamp(new xCoord(), new xCoord()); XUtils.Assert(r == new xCoord(0, 33)); XUtils.Assert(s == new xCoord(-11, -1)); XUtils.Assert(t == g); XUtils.Assert(u == new xCoord(0, 0)); }