Skip to content

Commit c917c91

Browse files
committed
refactor: pass B2Segment as readonly in and update callers
Change segment collision helpers to take B2Segment by 'in' instead of 'ref'. Update contacts, shape setter, and sample call sites accordingly. This better reflects readonly intent and avoids unnecessary ref usage.
1 parent b9d5286 commit c917c91

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/Box2D.NET.Samples/Samples/Collisions/Manifold.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public override void Step()
283283
B2Transform transform1 = new B2Transform(offset, b2Rot_identity);
284284
B2Transform transform2 = new B2Transform(b2Add(m_transform.p, offset), m_transform.q);
285285

286-
B2Manifold m = b2CollideSegmentAndCircle(ref segment, transform1, ref circle, transform2);
286+
B2Manifold m = b2CollideSegmentAndCircle(segment, transform1, ref circle, transform2);
287287

288288
B2Vec2 p1 = b2TransformPoint(transform1, segment.point1);
289289
B2Vec2 p2 = b2TransformPoint(transform1, segment.point2);
@@ -367,7 +367,7 @@ public override void Step()
367367
B2Transform transform1 = new B2Transform(offset, b2Rot_identity);
368368
B2Transform transform2 = new B2Transform(b2Add(m_transform.p, offset), m_transform.q);
369369

370-
B2Manifold m = b2CollideSegmentAndCapsule(ref segment, transform1, capsule, transform2);
370+
B2Manifold m = b2CollideSegmentAndCapsule(segment, transform1, capsule, transform2);
371371

372372
B2Vec2 p1 = b2TransformPoint(transform1, segment.point1);
373373
B2Vec2 p2 = b2TransformPoint(transform1, segment.point2);
@@ -473,7 +473,7 @@ public override void Step()
473473
B2Transform transform2 = new B2Transform(b2Add(m_transform.p, offset), m_transform.q);
474474
// b2Transform transform2 = {b2Add({-1.44583416f, 0.397352695f}, offset), m_transform.q};
475475

476-
B2Manifold m = b2CollideSegmentAndPolygon(ref segment, transform1, ref rox, transform2);
476+
B2Manifold m = b2CollideSegmentAndPolygon(segment, transform1, ref rox, transform2);
477477

478478
B2Vec2 p1 = b2TransformPoint(transform1, segment.point1);
479479
B2Vec2 p2 = b2TransformPoint(transform1, segment.point2);

src/Box2D.NET.Samples/Samples/Shapes/ModifyGeometry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void UpdateShape()
9191

9292
case B2ShapeType.b2_segmentShape:
9393
m_us.segment = new B2Segment(new B2Vec2(-0.5f * m_scale, 0.0f), new B2Vec2(0.75f * m_scale, 0.0f));
94-
b2Shape_SetSegment(m_shapeId, ref m_us.segment);
94+
b2Shape_SetSegment(m_shapeId, m_us.segment);
9595
break;
9696

9797
case B2ShapeType.b2_polygonShape:

src/Box2D.NET/B2Contacts.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ internal static B2Manifold b2PolygonManifold(B2Shape shapeA, in B2Transform xfA,
8181
internal static B2Manifold b2SegmentAndCircleManifold(B2Shape shapeA, in B2Transform xfA, B2Shape shapeB, in B2Transform xfB, ref B2SimplexCache cache)
8282
{
8383
B2_UNUSED(cache);
84-
return b2CollideSegmentAndCircle(ref shapeA.us.segment, xfA, ref shapeB.us.circle, xfB);
84+
return b2CollideSegmentAndCircle(shapeA.us.segment, xfA, ref shapeB.us.circle, xfB);
8585
}
8686

8787
internal static B2Manifold b2SegmentAndCapsuleManifold(B2Shape shapeA, in B2Transform xfA, B2Shape shapeB, in B2Transform xfB, ref B2SimplexCache cache)
8888
{
8989
B2_UNUSED(cache);
90-
return b2CollideSegmentAndCapsule(ref shapeA.us.segment, xfA, shapeB.us.capsule, xfB);
90+
return b2CollideSegmentAndCapsule(shapeA.us.segment, xfA, shapeB.us.capsule, xfB);
9191
}
9292

9393
internal static B2Manifold b2SegmentAndPolygonManifold(B2Shape shapeA, in B2Transform xfA, B2Shape shapeB, in B2Transform xfB, ref B2SimplexCache cache)
9494
{
9595
B2_UNUSED(cache);
96-
return b2CollideSegmentAndPolygon(ref shapeA.us.segment, xfA, ref shapeB.us.polygon, xfB);
96+
return b2CollideSegmentAndPolygon(shapeA.us.segment, xfA, ref shapeB.us.polygon, xfB);
9797
}
9898

9999
internal static B2Manifold b2ChainSegmentAndCircleManifold(B2Shape shapeA, in B2Transform xfA, B2Shape shapeB, in B2Transform xfB, ref B2SimplexCache cache)

src/Box2D.NET/B2Manifolds.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ public static B2Manifold b2CollideCapsules(in B2Capsule capsuleA, in B2Transform
537537
}
538538

539539
/// Compute the contact manifold between an segment and a capsule
540-
public static B2Manifold b2CollideSegmentAndCapsule(ref B2Segment segmentA, in B2Transform xfA, in B2Capsule capsuleB, in B2Transform xfB)
540+
public static B2Manifold b2CollideSegmentAndCapsule(in B2Segment segmentA, in B2Transform xfA, in B2Capsule capsuleB, in B2Transform xfB)
541541
{
542542
B2Capsule capsuleA = new B2Capsule(segmentA.point1, segmentA.point2, 0.0f);
543543
return b2CollideCapsules(capsuleA, xfA, capsuleB, xfB);
@@ -1088,14 +1088,14 @@ public static B2Manifold b2CollidePolygons(ref B2Polygon polygonA, in B2Transfor
10881088
}
10891089

10901090
/// Compute the contact manifold between an segment and a circle
1091-
public static B2Manifold b2CollideSegmentAndCircle(ref B2Segment segmentA, in B2Transform xfA, ref B2Circle circleB, in B2Transform xfB)
1091+
public static B2Manifold b2CollideSegmentAndCircle(in B2Segment segmentA, in B2Transform xfA, ref B2Circle circleB, in B2Transform xfB)
10921092
{
10931093
B2Capsule capsuleA = new B2Capsule(segmentA.point1, segmentA.point2, 0.0f);
10941094
return b2CollideCapsuleAndCircle(capsuleA, xfA, ref circleB, xfB);
10951095
}
10961096

10971097
/// Compute the contact manifold between an segment and a polygon
1098-
public static B2Manifold b2CollideSegmentAndPolygon(ref B2Segment segmentA, in B2Transform xfA, ref B2Polygon polygonB, in B2Transform xfB)
1098+
public static B2Manifold b2CollideSegmentAndPolygon(in B2Segment segmentA, in B2Transform xfA, ref B2Polygon polygonB, in B2Transform xfB)
10991099
{
11001100
B2Polygon polygonA = b2MakeCapsule(segmentA.point1, segmentA.point2, 0.0f);
11011101
return b2CollidePolygons(ref polygonA, xfA, ref polygonB, xfB);

src/Box2D.NET/B2Shapes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ public static void b2Shape_SetCapsule(in B2ShapeId shapeId, in B2Capsule capsule
15021502
b2ResetProxy(world, shape, wakeBodies, destroyProxy);
15031503
}
15041504

1505-
public static void b2Shape_SetSegment(in B2ShapeId shapeId, ref B2Segment segment)
1505+
public static void b2Shape_SetSegment(in B2ShapeId shapeId, in B2Segment segment)
15061506
{
15071507
B2World world = b2GetWorldLocked(shapeId.world0);
15081508
if (world == null)

0 commit comments

Comments
 (0)