Skip to content

Commit a3b0720

Browse files
committed
fix: CS0660, CS0661
1 parent d78c021 commit a3b0720

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/Box2D.NET/B2BodyId.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi(ikpil@naver.com)
33
// SPDX-License-Identifier: MIT
44

5+
using System;
56
using System.Runtime.CompilerServices;
67
using static Box2D.NET.B2Ids;
78

89
namespace Box2D.NET
910
{
1011
/// Body id references a body instance. This should be treated as an opaque handle.
11-
public readonly struct B2BodyId
12+
public readonly struct B2BodyId : IEquatable<B2BodyId>
1213
{
1314
public readonly int index1;
1415
public readonly ushort world0;
@@ -50,5 +51,27 @@ public B2BodyId(int index1, ushort world0, ushort generation)
5051
{
5152
return !(a == b);
5253
}
54+
55+
public bool Equals(B2BodyId other)
56+
{
57+
return this == other;
58+
}
59+
60+
public override bool Equals(object obj)
61+
{
62+
if (obj is B2BodyId other)
63+
{
64+
return Equals(other);
65+
}
66+
67+
return false;
68+
}
69+
70+
// GetHashCode 메서드 구현
71+
public override int GetHashCode()
72+
{
73+
ulong ua = b2StoreBodyId(this);
74+
return ua.GetHashCode();
75+
}
5376
}
5477
}

src/Box2D.NET/B2Vec2.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi(ikpil@naver.com)
33
// SPDX-License-Identifier: MIT
44

5+
using System;
56
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78

@@ -10,7 +11,7 @@ namespace Box2D.NET
1011
/// 2D vector
1112
/// This can be used to represent a point or free vector
1213
[StructLayout(LayoutKind.Sequential)]
13-
public struct B2Vec2
14+
public struct B2Vec2 : IEquatable<B2Vec2>
1415
{
1516
/// coordinates
1617
public float X, Y;
@@ -76,5 +77,25 @@ public B2Vec2(float x, float y)
7677
{
7778
return !(a == b);
7879
}
80+
81+
public bool Equals(B2Vec2 other)
82+
{
83+
return this == other;
84+
}
85+
86+
public override bool Equals(object obj)
87+
{
88+
if (obj is B2Vec2 other)
89+
{
90+
return Equals(other);
91+
}
92+
93+
return false;
94+
}
95+
96+
public override int GetHashCode()
97+
{
98+
return (X, Y).GetHashCode();
99+
}
79100
}
80101
}

src/Box2D.NET/B2Worlds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ internal static void b2DrawShape(B2DebugDraw draw, B2Shape shape, B2Transform xf
873873

874874
case B2ShapeType.b2_polygonShape:
875875
{
876-
ref readonly B2Polygon poly = ref shape.us.polygon;
876+
ref B2Polygon poly = ref shape.us.polygon;
877877
draw.DrawSolidPolygonFcn(xf, poly.vertices.AsSpan(), poly.count, poly.radius, color, draw.context);
878878
}
879879
break;

0 commit comments

Comments
 (0)