Skip to content

Commit 020b125

Browse files
committed
added AABBTest
1 parent 1786802 commit 020b125

4 files changed

Lines changed: 102 additions & 34 deletions

File tree

src/Box2D.NET/B2Vec2.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public struct B2Vec2
1616

1717
public B2Vec2(float x, float y)
1818
{
19-
this.X = x;
20-
this.Y = y;
19+
X = x;
20+
Y = y;
2121
}
2222

2323
/*
@@ -27,27 +27,6 @@ public B2Vec2(float x, float y)
2727
* See math_functions.h for details.
2828
*/
2929

30-
// /// Unary add one vector to another
31-
// public static void operator+=( B2Vec2& a, B2Vec2 b )
32-
// {
33-
// a.x += b.x;
34-
// a.y += b.y;
35-
// }
36-
//
37-
// /// Unary subtract one vector from another
38-
// public static void operator-=( B2Vec2& a, B2Vec2 b )
39-
// {
40-
// a.x -= b.x;
41-
// a.y -= b.y;
42-
// }
43-
//
44-
// /// Unary multiply a vector by a scalar
45-
// public static void operator*=( B2Vec2& a, float b )
46-
// {
47-
// a.x *= b;
48-
// a.y *= b;
49-
// }
50-
5130
/// Unary negate a vector
5231
public static B2Vec2 operator-( B2Vec2 a )
5332
{

test/Box2D.NET.Test/B2AABBTests.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using NUnit.Framework;
2+
using static Box2D.NET.B2AABBs;
3+
4+
namespace Box2D.NET.Test;
5+
6+
public class B2AABBTests
7+
{
8+
[Test]
9+
public void Test_b2Perimeter()
10+
{
11+
// zero
12+
{
13+
B2AABB aabb = new B2AABB();
14+
aabb.lowerBound = new B2Vec2(1.0f, 1.0f);
15+
aabb.upperBound = new B2Vec2(1.0f, 1.0f);
16+
17+
float result = b2Perimeter(aabb);
18+
Assert.That(result, Is.EqualTo(0.0f));
19+
}
20+
21+
{
22+
B2AABB aabb = new B2AABB();
23+
aabb.lowerBound = new B2Vec2(0.0f, 0.0f);
24+
aabb.upperBound = new B2Vec2(3.0f, 4.0f);
25+
26+
float result = b2Perimeter(aabb);
27+
28+
Assert.That(result, Is.EqualTo(14.0f));
29+
}
30+
31+
{
32+
B2AABB aabb = new B2AABB();
33+
aabb.lowerBound = new B2Vec2(-2.0f, -2.0f);
34+
aabb.upperBound = new B2Vec2(2.0f, 3.0f);
35+
36+
float result = b2Perimeter(aabb);
37+
Assert.That(result, Is.EqualTo(18.0f));
38+
}
39+
40+
{
41+
B2AABB aabb = new B2AABB();
42+
aabb.lowerBound = new B2Vec2(0.0f, 0.0f);
43+
aabb.upperBound = new B2Vec2(float.MaxValue, float.MaxValue);
44+
45+
float result = b2Perimeter(aabb);
46+
47+
Assert.That(result, Is.EqualTo(float.PositiveInfinity));
48+
}
49+
50+
{
51+
B2AABB aabb = new B2AABB();
52+
aabb.lowerBound = new B2Vec2(0.0f, 0.0f);
53+
aabb.upperBound = new B2Vec2(float.MinValue, float.MinValue);
54+
55+
float result = b2Perimeter(aabb);
56+
57+
Assert.That(result, Is.EqualTo(4 * float.MinValue));
58+
}
59+
}
60+
61+
[Test]
62+
public void Test_b2EnlargeAABB()
63+
{
64+
// enlarge
65+
{
66+
var a = new B2AABB();
67+
a.lowerBound = new B2Vec2(0, 0);
68+
a.upperBound = new B2Vec2(1, 1);
69+
70+
var b = new B2AABB();
71+
b.lowerBound = new B2Vec2(-1, -1);
72+
b.upperBound = new B2Vec2(2, 2);
73+
74+
var result = b2EnlargeAABB(ref a, b);
75+
76+
Assert.That(result);
77+
Assert.That(a.lowerBound, Is.EqualTo(new B2Vec2(-1, -1)));
78+
Assert.That(a.upperBound, Is.EqualTo(new B2Vec2(2, 2)));
79+
}
80+
81+
// no enlarge
82+
{
83+
var a = new B2AABB();
84+
a.lowerBound = new B2Vec2(0, 0);
85+
a.upperBound = new B2Vec2(5, 5);
86+
87+
var b = new B2AABB();
88+
b.lowerBound = new B2Vec2(3, 2);
89+
b.upperBound = new B2Vec2(4, 5);
90+
91+
var result = b2EnlargeAABB(ref a, b);
92+
93+
Assert.That(!result);
94+
Assert.That(a.lowerBound, Is.EqualTo(new B2Vec2(0, 0)));
95+
Assert.That(a.upperBound, Is.EqualTo(new B2Vec2(5, 5)));
96+
}
97+
}
98+
}

test/Box2D.NET.Test/B2BitSetTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// SPDX-License-Identifier: MIT
44

55
using NUnit.Framework;
6+
using static Box2D.NET.B2BitSets;
67

78
namespace Box2D.NET.Test;
89

9-
using static NET.B2BitSets;
10-
1110
public class B2BitSetTest
1211
{
1312
private const int COUNT = 169;
@@ -41,4 +40,4 @@ public void BitSetTest()
4140

4241
b2DestroyBitSet(ref bitSet);
4342
}
44-
}
43+
}

test/Box2D.NET.Test/B2DeterminismTest.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,8 @@
1010
using System.Threading.Tasks;
1111
using Box2D.NET.Shared;
1212
using NUnit.Framework;
13-
using static Box2D.NET.B2Geometries;
14-
using static Box2D.NET.B2MathFunction;
1513
using static Box2D.NET.B2Types;
1614
using static Box2D.NET.B2Worlds;
17-
using static Box2D.NET.B2Bodies;
18-
using static Box2D.NET.B2Shapes;
19-
using static Box2D.NET.B2Ids;
20-
using static Box2D.NET.B2Constants;
21-
using static Box2D.NET.B2Joints;
22-
using static Box2D.NET.B2Timers;
2315
using static Box2D.NET.B2Cores;
2416
using static Box2D.NET.Shared.Determinism;
2517

0 commit comments

Comments
 (0)