仓库指标
- 星标
- (13,886 个星标)
- PR 合并指标
- (平均合并 25天 3小时) (30 天内合并 22 个 PR)
描述
I've recently started adding several 2D bounding volumes and geometric primitives to MonoGame.Extended, based on the material in Real-Time Collision Detection (Christer Ericson). MonoGame currently includes the following 3D-oriented primitives:
BoundingBox: AABB usingVector3BoundingSphere: Sphere usingVector3Ray: Ray with origin/direction usingVector3Plane: Plane using `Vector3
The new 2D-oriented types I’m implementing are:
BoundingRectangle(or possiblyBoundingBox2D)OrientedBoundingRectangleBoundingCircleBoundingCapsuleBoundingPolygonBoundingKDopLine2DLineSegment2DRay2D
Before continuing in MonoGame.Extended, I wanted to ask whether these would be considered for inclusion in MonoGame itself. From a functionality standpoint, they parallel the existing 3D primitives and could provide a natural 2D equivalent set within the core library.
If these types are something MonoGame would accept in a PR, I want to ensure their APIs match existing patterns where appropriate.
The current 3D primitives use a “dual API” pattern for intersection methods. For example:
// Ray.cs example
public float? Intersects(BoundingBox box)
{
// implementation
}
public void Intersects(ref BoundingBox box, out float? result)
{
result = Intersects(box);
}
After discussing this in the MonoGame Discord, it appears this dual API originated in XNA for performance reasons on 32-bit processors and older JIT behavior (struct copies and inlining rules). On modern .NET runtimes and x64 architectures, this pattern is generally unnecessary.
However, MonoGame still targets consoles requiring C# language version 5, so any new APIs must remain compatible with that constraint.
So my questions is, if this is a PR that sounds good for MonoGame instead of just putting in MonoGame.Extended, should the new types retain the legacy XNA style dual Intersects APIs to remain consistent with existing MonoGame types, or should they use a more modern and idiomatic .NET API (e.g., single method returning bool with an out parameter)?