Skip to content

Commit 2783e3f

Browse files
committed
added test b2BroadPhase_EnlargeProxy, b2BroadPhase_MoveProxy
1 parent 998a937 commit 2783e3f

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

test/Box2D.NET.Test/B2BoardPhasesTests.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using static Box2D.NET.B2BoardPhases;
44
using static Box2D.NET.B2Tables;
55
using static Box2D.NET.B2Atomics;
6+
using static Box2D.NET.B2Constants;
67

78
namespace Box2D.NET.Test;
89

@@ -213,6 +214,99 @@ public void Test_B2BoardPhases_b2BroadPhase_DestroyProxy()
213214
#if DEBUG
214215
// Case 3: Destroy a non-existent proxy
215216
Assert.Throws<InvalidOperationException>(() => b2BroadPhase_DestroyProxy(bp, proxyKeyB), "Destroying a non-existent proxy should throw an exception");
217+
#endif
218+
}
219+
220+
[Test]
221+
public void Test_B2BoardPhases_b2BroadPhase_MoveProxy()
222+
{
223+
B2BroadPhase bp = null;
224+
b2CreateBroadPhase(ref bp);
225+
226+
var aabb1 = new B2AABB
227+
{
228+
lowerBound = new B2Vec2(0, 0),
229+
upperBound = new B2Vec2(1, 1)
230+
};
231+
232+
var aabb2 = new B2AABB
233+
{
234+
lowerBound = new B2Vec2(10, 10),
235+
upperBound = new B2Vec2(11, 11)
236+
};
237+
238+
ulong categoryBits = 0x0001;
239+
int shapeIndex = 1;
240+
241+
int proxyKey = b2BroadPhase_CreateProxy(bp, B2BodyType.b2_dynamicBody, aabb1, categoryBits, shapeIndex, false);
242+
B2BodyType proxyType = B2_PROXY_TYPE(proxyKey);
243+
int proxyId = B2_PROXY_ID(proxyKey);
244+
245+
{
246+
// move valid proxy
247+
b2BroadPhase_MoveProxy(bp, proxyKey, aabb2);
248+
Assert.That(bp.trees[(int)proxyType].nodes[proxyId].aabb, Is.EqualTo(aabb2));
249+
250+
Assert.That(bp.moveSet.count, Is.EqualTo(1));
251+
Assert.That(bp.moveArray.count, Is.EqualTo(1));
252+
Assert.That(bp.moveArray.data, Does.Contain(proxyKey));
253+
}
254+
255+
#if DEBUG
256+
{
257+
// move invalid (nonexistent) proxy
258+
int invalidProxyKey = B2_PROXY_KEY(9999, B2BodyType.b2_dynamicBody);
259+
Assert.Throws<InvalidOperationException>(() => b2BroadPhase_MoveProxy(bp, invalidProxyKey, aabb2));
260+
}
261+
#endif
262+
}
263+
264+
[Test]
265+
public void Test_B2BroadPhases_b2BroadPhase_EnlargeProxy()
266+
{
267+
B2BroadPhase bp = null;
268+
b2CreateBroadPhase(ref bp);
269+
270+
B2AABB aabb1 = new B2AABB
271+
{
272+
lowerBound = new B2Vec2(0, 0),
273+
upperBound = new B2Vec2(1, 1)
274+
};
275+
276+
B2AABB aabb2 = new B2AABB
277+
{
278+
lowerBound = new B2Vec2(-1, -1),
279+
upperBound = new B2Vec2(2, 2)
280+
};
281+
282+
// Create proxy
283+
int proxyKey = b2BroadPhase_CreateProxy(bp, B2BodyType.b2_dynamicBody, aabb1, 0x0001, 123, false);
284+
285+
{
286+
// enlarge valid proxy
287+
b2BroadPhase_EnlargeProxy(bp, proxyKey, aabb2);
288+
289+
var node = bp.trees[(int)B2_PROXY_TYPE(proxyKey)].nodes[B2_PROXY_ID(proxyKey)];
290+
291+
Assert.That(node.aabb.lowerBound.X, Is.EqualTo(aabb2.lowerBound.X), "LowerBound.X should match enlarged AABB");
292+
Assert.That(node.aabb.lowerBound.Y, Is.EqualTo(aabb2.lowerBound.Y), "LowerBound.Y should match enlarged AABB");
293+
Assert.That(node.aabb.upperBound.X, Is.EqualTo(aabb2.upperBound.X), "UpperBound.X should match enlarged AABB");
294+
Assert.That(node.aabb.upperBound.Y, Is.EqualTo(aabb2.upperBound.Y), "UpperBound.Y should match enlarged AABB");
295+
296+
Assert.That(bp.moveSet.count, Is.EqualTo(1), "moveSet should contain one key after enlarge");
297+
Assert.That(bp.moveArray.count, Is.EqualTo(1), "moveArray should contain one key after enlarge");
298+
Assert.That(bp.moveArray.data, Does.Contain(proxyKey), "moveArray should contain the enlarged proxyKey");
299+
}
300+
301+
#if DEBUG
302+
{
303+
// enlarge invalid proxy (null index)
304+
Assert.That(() => b2BroadPhase_EnlargeProxy(bp, B2_NULL_INDEX, aabb2), Throws.Exception, "Enlarging with null proxyKey should throw");
305+
306+
// enlarge static body
307+
int staticProxyKey = b2BroadPhase_CreateProxy(bp, B2BodyType.b2_staticBody, aabb1, 0x0001, 124, true);
308+
Assert.That(() => b2BroadPhase_EnlargeProxy(bp, staticProxyKey, aabb2), Throws.Exception, "Enlarging staticBody proxyKey should throw");
309+
}
216310
#endif
217311
}
218312
}

0 commit comments

Comments
 (0)