< Summary

Information
Class: FixedMathSharp.FixedConvexPrismRelations
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Primitives/Relations/FixedConvexPrismRelations.cs
Line coverage
100%
Covered lines: 113
Uncovered lines: 0
Coverable lines: 113
Total lines: 235
Line coverage: 100%
Branch coverage
100%
Covered branches: 16
Total branches: 16
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryGetTriangleContact(...)100%22100%
TryGetSphereContact(...)100%11100%
TryGetCenteredCapsuleContact(...)100%11100%
TryGetCenteredCylinderContact(...)100%11100%
TryGetCenteredConeContact(...)100%11100%
Validate(...)100%88100%
ValidatePrism(...)100%66100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Primitives/Relations/FixedConvexPrismRelations.cs

#LineLine coverage
 1//=======================================================================
 2// FixedConvexPrismRelations.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9using FixedMathSharp.Geometry;
 10
 11namespace FixedMathSharp;
 12
 13/// <summary>
 14/// Provides exact owner-relative contacts between centered finite surfaces
 15/// and vertical convex prisms.
 16/// </summary>
 17public static class FixedConvexPrismRelations
 18{
 19    /// <summary>
 20    /// Attempts to construct canonical contact anchors between a rigidly
 21    /// transformed triangle and a rotated vertical convex prism.
 22    /// </summary>
 23    public static bool TryGetTriangleContact(
 24        Vector3d triangleOrigin,
 25        FixedQuaternion triangleRotation,
 26        FixedTriangle triangle,
 27        Vector3d prismOrigin,
 28        Fixed64 prismRotation,
 29        ReadOnlySpan<Vector2d> prismLocalOffsets,
 30        Fixed64 prismHalfThickness,
 31        out FixedContactAnchors contact)
 32    {
 7633        if (!triangleRotation.IsNormalized())
 134            throw new ArgumentException(
 135                "The triangle rotation must be normalized.",
 136                nameof(triangleRotation));
 7537        ValidatePrism(
 7538            Fixed64.Zero,
 7539            prismLocalOffsets,
 7540            prismHalfThickness);
 7541        return WideOrientedBox.TryGetTrianglePrismContact(
 7542            triangleOrigin,
 7543            triangleRotation,
 7544            triangle,
 7545            prismOrigin,
 7546            prismRotation,
 7547            prismLocalOffsets,
 7548            prismHalfThickness,
 7549            out contact);
 50    }
 51
 52    /// <summary>
 53    /// Attempts to construct canonical contact anchors between a sphere and a
 54    /// rotated vertical convex prism.
 55    /// </summary>
 56    public static bool TryGetSphereContact(
 57        Vector3d sphereCenter,
 58        Fixed64 sphereRadius,
 59        Vector3d prismOrigin,
 60        Fixed64 prismRotation,
 61        ReadOnlySpan<Vector2d> prismLocalOffsets,
 62        Fixed64 prismHalfThickness,
 63        out FixedContactAnchors contact)
 64    {
 1465        ValidatePrism(
 1466            sphereRadius,
 1467            prismLocalOffsets,
 1468            prismHalfThickness);
 1469        return WideConvexPrismRelations.TryGetCenteredCapsuleContact(
 1470            sphereCenter,
 1471            FixedQuaternion.Identity,
 1472            Vector3d.Up,
 1473            Fixed64.Zero,
 1474            sphereRadius,
 1475            prismOrigin,
 1476            prismRotation,
 1477            prismLocalOffsets,
 1478            prismHalfThickness,
 1479            out contact);
 80    }
 81
 82    /// <summary>
 83    /// Attempts to construct canonical contact anchors between a centered
 84    /// capsule and a rotated vertical convex prism.
 85    /// </summary>
 86    public static bool TryGetCenteredCapsuleContact(
 87        Vector3d capsuleCenter,
 88        FixedQuaternion capsuleRotation,
 89        Vector3d localCapsuleAxisDirection,
 90        Fixed64 capsuleAxisLength,
 91        Fixed64 capsuleRadius,
 92        Vector3d prismOrigin,
 93        Fixed64 prismRotation,
 94        ReadOnlySpan<Vector2d> prismLocalOffsets,
 95        Fixed64 prismHalfThickness,
 96        out FixedContactAnchors contact)
 97    {
 2498        Validate(
 2499            capsuleRotation,
 24100            localCapsuleAxisDirection,
 24101            capsuleAxisLength,
 24102            nameof(capsuleAxisLength),
 24103            capsuleRadius,
 24104            prismLocalOffsets,
 24105            prismHalfThickness,
 24106            requirePositiveLength: false);
 20107        return WideConvexPrismRelations.TryGetCenteredCapsuleContact(
 20108            capsuleCenter,
 20109            capsuleRotation,
 20110            localCapsuleAxisDirection,
 20111            capsuleAxisLength,
 20112            capsuleRadius,
 20113            prismOrigin,
 20114            prismRotation,
 20115            prismLocalOffsets,
 20116            prismHalfThickness,
 20117            out contact);
 118    }
 119
 120    /// <summary>
 121    /// Attempts to construct canonical contact anchors between a centered
 122    /// finite cylinder and a rotated vertical convex prism.
 123    /// </summary>
 124    public static bool TryGetCenteredCylinderContact(
 125        Vector3d cylinderCenter,
 126        FixedQuaternion cylinderRotation,
 127        Vector3d localCylinderAxisDirection,
 128        Fixed64 cylinderAxisLength,
 129        Fixed64 cylinderRadius,
 130        Vector3d prismOrigin,
 131        Fixed64 prismRotation,
 132        ReadOnlySpan<Vector2d> prismLocalOffsets,
 133        Fixed64 prismHalfThickness,
 134        out FixedContactAnchors contact)
 135    {
 11136        Validate(
 11137            cylinderRotation,
 11138            localCylinderAxisDirection,
 11139            cylinderAxisLength,
 11140            nameof(cylinderAxisLength),
 11141            cylinderRadius,
 11142            prismLocalOffsets,
 11143            prismHalfThickness,
 11144            requirePositiveLength: true);
 10145        return WideConvexPrismRelations.TryGetCenteredCylinderContact(
 10146            cylinderCenter,
 10147            cylinderRotation,
 10148            localCylinderAxisDirection,
 10149            cylinderAxisLength,
 10150            cylinderRadius,
 10151            prismOrigin,
 10152            prismRotation,
 10153            prismLocalOffsets,
 10154            prismHalfThickness,
 10155            out contact);
 156    }
 157
 158    /// <summary>
 159    /// Attempts to construct canonical contact anchors between a centered
 160    /// finite cone and a rotated vertical convex prism.
 161    /// </summary>
 162    public static bool TryGetCenteredConeContact(
 163        Vector3d coneCenter,
 164        FixedQuaternion coneRotation,
 165        Vector3d localConeAxisDirection,
 166        Fixed64 coneHeight,
 167        Fixed64 coneRadius,
 168        Vector3d prismOrigin,
 169        Fixed64 prismRotation,
 170        ReadOnlySpan<Vector2d> prismLocalOffsets,
 171        Fixed64 prismHalfThickness,
 172        out FixedContactAnchors contact)
 173    {
 8174        Validate(
 8175            coneRotation,
 8176            localConeAxisDirection,
 8177            coneHeight,
 8178            nameof(coneHeight),
 8179            coneRadius,
 8180            prismLocalOffsets,
 8181            prismHalfThickness,
 8182            requirePositiveLength: true);
 7183        return WideConvexPrismRelations.TryGetCenteredConeContact(
 7184            coneCenter,
 7185            coneRotation,
 7186            localConeAxisDirection,
 7187            coneHeight,
 7188            coneRadius,
 7189            prismOrigin,
 7190            prismRotation,
 7191            prismLocalOffsets,
 7192            prismHalfThickness,
 7193            out contact);
 194    }
 195
 196    private static void Validate(
 197        FixedQuaternion rotation,
 198        Vector3d localAxisDirection,
 199        Fixed64 length,
 200        string lengthParameterName,
 201        Fixed64 radius,
 202        ReadOnlySpan<Vector2d> prismLocalOffsets,
 203        Fixed64 prismHalfThickness,
 204        bool requirePositiveLength)
 205    {
 43206        if (!rotation.IsNormalized())
 1207            throw new ArgumentException(
 1208                "Shape rotation must be normalized.",
 1209                nameof(rotation));
 42210        if (!localAxisDirection.IsNormalized())
 1211            throw new ArgumentException(
 1212                "Local shape axis direction must be normalized.",
 1213                nameof(localAxisDirection));
 41214        if (requirePositiveLength ? length <= Fixed64.Zero : length < Fixed64.Zero)
 1215            throw new ArgumentOutOfRangeException(lengthParameterName);
 40216        ValidatePrism(radius, prismLocalOffsets, prismHalfThickness);
 37217    }
 218
 219    private static void ValidatePrism(
 220        Fixed64 radius,
 221        ReadOnlySpan<Vector2d> prismLocalOffsets,
 222        Fixed64 prismHalfThickness)
 223    {
 129224        if (radius < Fixed64.Zero)
 1225            throw new ArgumentOutOfRangeException(nameof(radius));
 128226        if (prismLocalOffsets.Length < 3)
 227        {
 1228            throw new ArgumentException(
 1229                "A convex prism requires at least three ordered boundary offsets.",
 1230                nameof(prismLocalOffsets));
 231        }
 127232        if (prismHalfThickness <= Fixed64.Zero)
 1233            throw new ArgumentOutOfRangeException(nameof(prismHalfThickness));
 126234    }
 235}

Methods/Properties

TryGetTriangleContact(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Geometry.FixedTriangle,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,FixedMathSharp.Geometry.FixedContactAnchors&)
TryGetSphereContact(FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,FixedMathSharp.Geometry.FixedContactAnchors&)
TryGetCenteredCapsuleContact(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,FixedMathSharp.Geometry.FixedContactAnchors&)
TryGetCenteredCylinderContact(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,FixedMathSharp.Geometry.FixedContactAnchors&)
TryGetCenteredConeContact(FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,FixedMathSharp.Geometry.FixedContactAnchors&)
Validate(FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.String,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64,System.Boolean)
ValidatePrism(FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64)