< 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: 126
Uncovered lines: 0
Coverable lines: 126
Total lines: 288
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IntersectsSweptUprightCylinderStrict(...)100%22100%
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    /// Determines whether an upright cylinder translated between two
 21    /// bottom-center points has strict positive-volume overlap with a rotated
 22    /// vertical convex prism at any shared continuous parameter in [0, 1].
 23    /// </summary>
 24    /// <remarks>
 25    /// Planar tangency, vertical tangency, and contact that exists only where
 26    /// the planar and vertical strict intervals meet at one boundary parameter
 27    /// return <see langword="false"/>. A zero radius requires the swept axis
 28    /// point to enter the strict prism footprint. The joint parameter relation
 29    /// is evaluated with exact wide intermediates and does not publish rounded
 30    /// interval endpoints.
 31    /// </remarks>
 32    /// <param name="bottomStart">The cylinder bottom center at parameter zero.</param>
 33    /// <param name="bottomEnd">The cylinder bottom center at parameter one.</param>
 34    /// <param name="radius">The nonnegative cylinder radius.</param>
 35    /// <param name="height">The positive full cylinder height.</param>
 36    /// <param name="prismOrigin">The center of the vertical convex prism.</param>
 37    /// <param name="prismRotation">The prism footprint rotation about world Y.</param>
 38    /// <param name="prismLocalOffsets">At least three ordered convex-footprint offsets.</param>
 39    /// <param name="prismHalfThickness">The positive prism half-thickness along world Y.</param>
 40    /// <exception cref="ArgumentOutOfRangeException">
 41    /// <paramref name="radius"/> is negative, <paramref name="height"/> is not
 42    /// positive, or <paramref name="prismHalfThickness"/> is not positive.
 43    /// </exception>
 44    /// <exception cref="ArgumentException">
 45    /// Fewer than three ordered prism offsets were supplied.
 46    /// </exception>
 47    public static bool IntersectsSweptUprightCylinderStrict(
 48        Vector3d bottomStart,
 49        Vector3d bottomEnd,
 50        Fixed64 radius,
 51        Fixed64 height,
 52        Vector3d prismOrigin,
 53        Fixed64 prismRotation,
 54        ReadOnlySpan<Vector2d> prismLocalOffsets,
 55        Fixed64 prismHalfThickness)
 56    {
 16457        if (height <= Fixed64.Zero)
 158            throw new ArgumentOutOfRangeException(nameof(height));
 16359        ValidatePrism(radius, prismLocalOffsets, prismHalfThickness);
 16060        return WideConvexPrismRelations
 16061            .IntersectsSweptUprightCylinderStrict(
 16062                bottomStart,
 16063                bottomEnd,
 16064                radius,
 16065                height,
 16066                prismOrigin,
 16067                prismRotation,
 16068                prismLocalOffsets,
 16069                prismHalfThickness);
 70    }
 71
 72    /// <summary>
 73    /// Attempts to construct canonical contact anchors between a rigidly
 74    /// transformed triangle and a rotated vertical convex prism.
 75    /// </summary>
 76    public static bool TryGetTriangleContact(
 77        Vector3d triangleOrigin,
 78        FixedQuaternion triangleRotation,
 79        FixedTriangle triangle,
 80        Vector3d prismOrigin,
 81        Fixed64 prismRotation,
 82        ReadOnlySpan<Vector2d> prismLocalOffsets,
 83        Fixed64 prismHalfThickness,
 84        out FixedContactAnchors contact)
 85    {
 7686        if (!triangleRotation.IsNormalized())
 187            throw new ArgumentException(
 188                "The triangle rotation must be normalized.",
 189                nameof(triangleRotation));
 7590        ValidatePrism(
 7591            Fixed64.Zero,
 7592            prismLocalOffsets,
 7593            prismHalfThickness);
 7594        return WideOrientedBox.TryGetTrianglePrismContact(
 7595            triangleOrigin,
 7596            triangleRotation,
 7597            triangle,
 7598            prismOrigin,
 7599            prismRotation,
 75100            prismLocalOffsets,
 75101            prismHalfThickness,
 75102            out contact);
 103    }
 104
 105    /// <summary>
 106    /// Attempts to construct canonical contact anchors between a sphere and a
 107    /// rotated vertical convex prism.
 108    /// </summary>
 109    public static bool TryGetSphereContact(
 110        Vector3d sphereCenter,
 111        Fixed64 sphereRadius,
 112        Vector3d prismOrigin,
 113        Fixed64 prismRotation,
 114        ReadOnlySpan<Vector2d> prismLocalOffsets,
 115        Fixed64 prismHalfThickness,
 116        out FixedContactAnchors contact)
 117    {
 14118        ValidatePrism(
 14119            sphereRadius,
 14120            prismLocalOffsets,
 14121            prismHalfThickness);
 14122        return WideConvexPrismRelations.TryGetCenteredCapsuleContact(
 14123            sphereCenter,
 14124            FixedQuaternion.Identity,
 14125            Vector3d.Up,
 14126            Fixed64.Zero,
 14127            sphereRadius,
 14128            prismOrigin,
 14129            prismRotation,
 14130            prismLocalOffsets,
 14131            prismHalfThickness,
 14132            out contact);
 133    }
 134
 135    /// <summary>
 136    /// Attempts to construct canonical contact anchors between a centered
 137    /// capsule and a rotated vertical convex prism.
 138    /// </summary>
 139    public static bool TryGetCenteredCapsuleContact(
 140        Vector3d capsuleCenter,
 141        FixedQuaternion capsuleRotation,
 142        Vector3d localCapsuleAxisDirection,
 143        Fixed64 capsuleAxisLength,
 144        Fixed64 capsuleRadius,
 145        Vector3d prismOrigin,
 146        Fixed64 prismRotation,
 147        ReadOnlySpan<Vector2d> prismLocalOffsets,
 148        Fixed64 prismHalfThickness,
 149        out FixedContactAnchors contact)
 150    {
 24151        Validate(
 24152            capsuleRotation,
 24153            localCapsuleAxisDirection,
 24154            capsuleAxisLength,
 24155            nameof(capsuleAxisLength),
 24156            capsuleRadius,
 24157            prismLocalOffsets,
 24158            prismHalfThickness,
 24159            requirePositiveLength: false);
 20160        return WideConvexPrismRelations.TryGetCenteredCapsuleContact(
 20161            capsuleCenter,
 20162            capsuleRotation,
 20163            localCapsuleAxisDirection,
 20164            capsuleAxisLength,
 20165            capsuleRadius,
 20166            prismOrigin,
 20167            prismRotation,
 20168            prismLocalOffsets,
 20169            prismHalfThickness,
 20170            out contact);
 171    }
 172
 173    /// <summary>
 174    /// Attempts to construct canonical contact anchors between a centered
 175    /// finite cylinder and a rotated vertical convex prism.
 176    /// </summary>
 177    public static bool TryGetCenteredCylinderContact(
 178        Vector3d cylinderCenter,
 179        FixedQuaternion cylinderRotation,
 180        Vector3d localCylinderAxisDirection,
 181        Fixed64 cylinderAxisLength,
 182        Fixed64 cylinderRadius,
 183        Vector3d prismOrigin,
 184        Fixed64 prismRotation,
 185        ReadOnlySpan<Vector2d> prismLocalOffsets,
 186        Fixed64 prismHalfThickness,
 187        out FixedContactAnchors contact)
 188    {
 11189        Validate(
 11190            cylinderRotation,
 11191            localCylinderAxisDirection,
 11192            cylinderAxisLength,
 11193            nameof(cylinderAxisLength),
 11194            cylinderRadius,
 11195            prismLocalOffsets,
 11196            prismHalfThickness,
 11197            requirePositiveLength: true);
 10198        return WideConvexPrismRelations.TryGetCenteredCylinderContact(
 10199            cylinderCenter,
 10200            cylinderRotation,
 10201            localCylinderAxisDirection,
 10202            cylinderAxisLength,
 10203            cylinderRadius,
 10204            prismOrigin,
 10205            prismRotation,
 10206            prismLocalOffsets,
 10207            prismHalfThickness,
 10208            out contact);
 209    }
 210
 211    /// <summary>
 212    /// Attempts to construct canonical contact anchors between a centered
 213    /// finite cone and a rotated vertical convex prism.
 214    /// </summary>
 215    public static bool TryGetCenteredConeContact(
 216        Vector3d coneCenter,
 217        FixedQuaternion coneRotation,
 218        Vector3d localConeAxisDirection,
 219        Fixed64 coneHeight,
 220        Fixed64 coneRadius,
 221        Vector3d prismOrigin,
 222        Fixed64 prismRotation,
 223        ReadOnlySpan<Vector2d> prismLocalOffsets,
 224        Fixed64 prismHalfThickness,
 225        out FixedContactAnchors contact)
 226    {
 8227        Validate(
 8228            coneRotation,
 8229            localConeAxisDirection,
 8230            coneHeight,
 8231            nameof(coneHeight),
 8232            coneRadius,
 8233            prismLocalOffsets,
 8234            prismHalfThickness,
 8235            requirePositiveLength: true);
 7236        return WideConvexPrismRelations.TryGetCenteredConeContact(
 7237            coneCenter,
 7238            coneRotation,
 7239            localConeAxisDirection,
 7240            coneHeight,
 7241            coneRadius,
 7242            prismOrigin,
 7243            prismRotation,
 7244            prismLocalOffsets,
 7245            prismHalfThickness,
 7246            out contact);
 247    }
 248
 249    private static void Validate(
 250        FixedQuaternion rotation,
 251        Vector3d localAxisDirection,
 252        Fixed64 length,
 253        string lengthParameterName,
 254        Fixed64 radius,
 255        ReadOnlySpan<Vector2d> prismLocalOffsets,
 256        Fixed64 prismHalfThickness,
 257        bool requirePositiveLength)
 258    {
 43259        if (!rotation.IsNormalized())
 1260            throw new ArgumentException(
 1261                "Shape rotation must be normalized.",
 1262                nameof(rotation));
 42263        if (!localAxisDirection.IsNormalized())
 1264            throw new ArgumentException(
 1265                "Local shape axis direction must be normalized.",
 1266                nameof(localAxisDirection));
 41267        if (requirePositiveLength ? length <= Fixed64.Zero : length < Fixed64.Zero)
 1268            throw new ArgumentOutOfRangeException(lengthParameterName);
 40269        ValidatePrism(radius, prismLocalOffsets, prismHalfThickness);
 37270    }
 271
 272    private static void ValidatePrism(
 273        Fixed64 radius,
 274        ReadOnlySpan<Vector2d> prismLocalOffsets,
 275        Fixed64 prismHalfThickness)
 276    {
 292277        if (radius < Fixed64.Zero)
 2278            throw new ArgumentOutOfRangeException(nameof(radius));
 290279        if (prismLocalOffsets.Length < 3)
 280        {
 2281            throw new ArgumentException(
 2282                "A convex prism requires at least three ordered boundary offsets.",
 2283                nameof(prismLocalOffsets));
 284        }
 288285        if (prismHalfThickness <= Fixed64.Zero)
 2286            throw new ArgumentOutOfRangeException(nameof(prismHalfThickness));
 286287    }
 288}

Methods/Properties

IntersectsSweptUprightCylinderStrict(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,System.ReadOnlySpan`1<FixedMathSharp.Vector2d>,FixedMathSharp.Fixed64)
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)