< Summary

Information
Class: Gravitas.Colliders.CompoundColliderPart
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Compound/CompoundColliderPart.cs
Line coverage
100%
Covered lines: 52
Uncovered lines: 0
Coverable lines: 52
Total lines: 257
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
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%22100%
get_Material()100%22100%
get_HasMaterial()100%22100%
Sphere(...)100%11100%
Sphere(...)100%11100%
Sphere(...)100%11100%
Capsule(...)100%11100%
Capsule(...)100%11100%
Capsule(...)100%11100%
Cuboid(...)100%11100%
Cuboid(...)100%11100%
Cuboid(...)100%11100%
Cylinder(...)100%11100%
Cylinder(...)100%11100%
Cylinder(...)100%11100%
Cone(...)100%11100%
Cone(...)100%11100%
Cone(...)100%11100%
ConvexMesh(...)100%11100%
ConvexMesh(...)100%11100%
ConvexMesh(...)100%11100%
get_IsDefault()100%11100%
TryGetMaterial(...)100%44100%
ResolveMaterial(...)100%22100%
ValidateScale(...)100%44100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Compound/CompoundColliderPart.cs

#LineLine coverage
 1//=======================================================================
 2// CompoundColliderPart.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2026–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using FixedMathSharp;
 9using Gravitas.Materials;
 10using System.Runtime.CompilerServices;
 11
 12namespace Gravitas.Colliders;
 13
 14/// <summary>
 15/// Declares one data-only geometry part owned by an
 16/// <see cref="LSCompoundCollider"/>.
 17/// </summary>
 18public readonly struct CompoundColliderPart
 19{
 20    /// <summary>Creates a part from an authored 3D shape.</summary>
 21    public CompoundColliderPart(ColliderShapeDefinition shape)
 322        : this(shape, Vector3d.Zero, FixedQuaternion.Identity, Vector3d.One, null)
 323    { }
 24
 25    /// <summary>Creates a part with a compound-local offset.</summary>
 26    public CompoundColliderPart(ColliderShapeDefinition shape, Vector3d localOffset)
 22027        : this(shape, localOffset, FixedQuaternion.Identity, Vector3d.One, null)
 22028    { }
 29
 30    /// <summary>Creates a part with a compound-local pose.</summary>
 31    public CompoundColliderPart(ColliderShapeDefinition shape, Vector3d localOffset, FixedQuaternion localRotation)
 232        : this(shape, localOffset, localRotation, Vector3d.One, null)
 233    { }
 34
 35    /// <summary>Creates a part with a compound-local transform and optional material override.</summary>
 36    public CompoundColliderPart(
 37        ColliderShapeDefinition shape,
 38        Vector3d localOffset,
 39        FixedQuaternion localRotation,
 40        Vector3d localScale,
 41        PhysicsMaterial? material = null)
 42    {
 30443        shape.EnsureDefined();
 30444        ValidateScale(localScale);
 45
 30246        Shape = shape;
 30247        LocalOffset = localOffset;
 30248        LocalRotation = localRotation.Normalized;
 30249        LocalScale = localScale;
 30250        _material = material ?? PhysicsMaterial.Default;
 30251        _hasMaterial = material.HasValue;
 30252    }
 53
 54    private readonly PhysicsMaterial _material;
 55    private readonly bool _hasMaterial;
 56
 57    /// <summary>
 58    /// Gets the authored data-only shape definition for this part.
 59    /// </summary>
 60    public ColliderShapeDefinition Shape { get; }
 61
 62    /// <summary>
 63    /// Gets the deterministic local center offset applied relative to the
 64    /// owning compound collider.
 65    /// </summary>
 66    public Vector3d LocalOffset { get; }
 67
 68    /// <summary>
 69    /// Gets the deterministic local rotation applied relative to the owning
 70    /// compound collider. Authored values are scale-safely normalized; a zero
 71    /// quaternion resolves to identity.
 72    /// </summary>
 73    public FixedQuaternion LocalRotation { get; }
 74
 75    /// <summary>
 76    /// Gets the deterministic local scale applied relative to the owning
 77    /// compound collider.
 78    /// </summary>
 79    public Vector3d LocalScale { get; }
 80
 81    /// <summary>
 82    /// Gets the authored material for this part, or the shape/default material
 83    /// when no part-level material was supplied.
 84    /// </summary>
 685    public PhysicsMaterial Material => TryGetMaterial(out PhysicsMaterial material)
 686        ? material
 687        : PhysicsMaterial.Default;
 88
 89    internal bool HasMaterial
 90    {
 91        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 9292        get => _hasMaterial || Shape.HasMaterial;
 93    }
 94
 95    /// <summary>Creates a sphere part.</summary>
 96    public static CompoundColliderPart Sphere(Fixed64 radius, Vector3d localOffset) =>
 12997        new(ColliderShapeDefinition.Sphere(radius), localOffset);
 98
 99    /// <summary>Creates a sphere part with a material override.</summary>
 100    public static CompoundColliderPart Sphere(
 101        Fixed64 radius,
 102        Vector3d localOffset,
 103        PhysicsMaterial material) =>
 7104        new(ColliderShapeDefinition.Sphere(radius), localOffset, FixedQuaternion.Identity, Vector3d.One, material);
 105
 106    /// <summary>Creates a transformed sphere part.</summary>
 107    public static CompoundColliderPart Sphere(
 108        Fixed64 radius,
 109        Vector3d localOffset,
 110        FixedQuaternion localRotation,
 111        Vector3d localScale) =>
 5112        new(ColliderShapeDefinition.Sphere(radius), localOffset, localRotation, localScale);
 113
 114    /// <summary>Creates a capsule part.</summary>
 115    public static CompoundColliderPart Capsule(Fixed64 radius, Fixed64 height, Vector3d localOffset) =>
 5116        new(ColliderShapeDefinition.Capsule(radius, height), localOffset);
 117
 118    /// <summary>Creates a capsule part with a material override.</summary>
 119    public static CompoundColliderPart Capsule(
 120        Fixed64 radius,
 121        Fixed64 height,
 122        Vector3d localOffset,
 123        PhysicsMaterial material) =>
 1124        new(ColliderShapeDefinition.Capsule(radius, height), localOffset, FixedQuaternion.Identity, Vector3d.One, materi
 125
 126    /// <summary>Creates a transformed capsule part.</summary>
 127    public static CompoundColliderPart Capsule(
 128        Fixed64 radius,
 129        Fixed64 height,
 130        Vector3d localOffset,
 131        FixedQuaternion localRotation,
 132        Vector3d localScale) =>
 12133        new(ColliderShapeDefinition.Capsule(radius, height), localOffset, localRotation, localScale);
 134
 135    /// <summary>Creates a cuboid part.</summary>
 136    public static CompoundColliderPart Cuboid(Vector3d size, Vector3d localOffset) =>
 18137        new(ColliderShapeDefinition.Cuboid(size), localOffset);
 138
 139    /// <summary>Creates a cuboid part with a material override.</summary>
 140    public static CompoundColliderPart Cuboid(
 141        Vector3d size,
 142        Vector3d localOffset,
 143        PhysicsMaterial material) =>
 1144        new(ColliderShapeDefinition.Cuboid(size), localOffset, FixedQuaternion.Identity, Vector3d.One, material);
 145
 146    /// <summary>Creates a transformed cuboid part.</summary>
 147    public static CompoundColliderPart Cuboid(
 148        Vector3d size,
 149        Vector3d localOffset,
 150        FixedQuaternion localRotation,
 151        Vector3d localScale) =>
 5152        new(ColliderShapeDefinition.Cuboid(size), localOffset, localRotation, localScale);
 153
 154    /// <summary>Creates a cylinder part.</summary>
 155    public static CompoundColliderPart Cylinder(Fixed64 radius, Fixed64 height, Vector3d localOffset) =>
 6156        new(ColliderShapeDefinition.Cylinder(radius, height), localOffset);
 157
 158    /// <summary>Creates a cylinder part with a material override.</summary>
 159    public static CompoundColliderPart Cylinder(
 160        Fixed64 radius,
 161        Fixed64 height,
 162        Vector3d localOffset,
 163        PhysicsMaterial material) =>
 1164        new(ColliderShapeDefinition.Cylinder(radius, height), localOffset, FixedQuaternion.Identity, Vector3d.One, mater
 165
 166    /// <summary>Creates a transformed cylinder part.</summary>
 167    public static CompoundColliderPart Cylinder(
 168        Fixed64 radius,
 169        Fixed64 height,
 170        Vector3d localOffset,
 171        FixedQuaternion localRotation,
 172        Vector3d localScale) =>
 9173        new(ColliderShapeDefinition.Cylinder(radius, height), localOffset, localRotation, localScale);
 174
 175    /// <summary>Creates a cone part.</summary>
 176    public static CompoundColliderPart Cone(Fixed64 radius, Fixed64 height, Vector3d localOffset) =>
 6177        new(ColliderShapeDefinition.Cone(radius, height), localOffset);
 178
 179    /// <summary>Creates a cone part with a material override.</summary>
 180    public static CompoundColliderPart Cone(
 181        Fixed64 radius,
 182        Fixed64 height,
 183        Vector3d localOffset,
 184        PhysicsMaterial material) =>
 1185        new(ColliderShapeDefinition.Cone(radius, height), localOffset, FixedQuaternion.Identity, Vector3d.One, material)
 186
 187    /// <summary>Creates a transformed cone part.</summary>
 188    public static CompoundColliderPart Cone(
 189        Fixed64 radius,
 190        Fixed64 height,
 191        Vector3d localOffset,
 192        FixedQuaternion localRotation,
 193        Vector3d localScale) =>
 13194        new(ColliderShapeDefinition.Cone(radius, height), localOffset, localRotation, localScale);
 195
 196    /// <summary>Creates a convex-mesh part.</summary>
 197    public static CompoundColliderPart ConvexMesh(
 198        Vector3d[] vertices,
 199        int[] triangles,
 200        Vector3d localOffset,
 201        MeshInertiaPolicy inertiaPolicy = MeshInertiaPolicy.RequireClosedVolume) =>
 9202        new(ColliderShapeDefinition.ConvexMesh(vertices, triangles, inertiaPolicy), localOffset);
 203
 204    /// <summary>Creates a convex-mesh part with a material override.</summary>
 205    public static CompoundColliderPart ConvexMesh(
 206        Vector3d[] vertices,
 207        int[] triangles,
 208        Vector3d localOffset,
 209        PhysicsMaterial material,
 210        MeshInertiaPolicy inertiaPolicy = MeshInertiaPolicy.RequireClosedVolume) =>
 1211        new(ColliderShapeDefinition.ConvexMesh(vertices, triangles, inertiaPolicy), localOffset, FixedQuaternion.Identit
 212
 213    /// <summary>Creates a transformed convex-mesh part.</summary>
 214    public static CompoundColliderPart ConvexMesh(
 215        Vector3d[] vertices,
 216        int[] triangles,
 217        Vector3d localOffset,
 218        FixedQuaternion localRotation,
 219        Vector3d localScale,
 220        MeshInertiaPolicy inertiaPolicy = MeshInertiaPolicy.RequireClosedVolume) =>
 6221        new(ColliderShapeDefinition.ConvexMesh(vertices, triangles, inertiaPolicy), localOffset, localRotation, localSca
 222
 223    internal bool IsDefault
 224    {
 225        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 288226        get => Shape.Kind == ColliderShapeDefinitionKind.Undefined;
 227    }
 228
 229    internal bool TryGetMaterial(out PhysicsMaterial material)
 230    {
 406231        if (_hasMaterial)
 232        {
 34233            material = _material;
 34234            return true;
 235        }
 236
 372237        if (Shape.HasMaterial)
 238        {
 40239            material = Shape.Material;
 40240            return true;
 241        }
 242
 332243        material = PhysicsMaterial.Default;
 332244        return false;
 245    }
 246
 247    internal PhysicsMaterial ResolveMaterial(PhysicsMaterial ownerMaterial) =>
 308248        TryGetMaterial(out PhysicsMaterial material) ? material : ownerMaterial;
 249
 250    private static void ValidateScale(Vector3d localScale)
 251    {
 304252        SwiftThrowHelper.ThrowIfArgument(
 304253            localScale.X <= Fixed64.Zero || localScale.Y <= Fixed64.Zero || localScale.Z <= Fixed64.Zero,
 304254            nameof(localScale),
 304255            "Compound collider part scale components must be greater than zero.");
 302256    }
 257}

Methods/Properties

.ctor(Gravitas.Colliders.ColliderShapeDefinition)
.ctor(Gravitas.Colliders.ColliderShapeDefinition,FixedMathSharp.Vector3d)
.ctor(Gravitas.Colliders.ColliderShapeDefinition,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
.ctor(Gravitas.Colliders.ColliderShapeDefinition,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,System.Nullable`1<Gravitas.Materials.PhysicsMaterial>)
get_Material()
get_HasMaterial()
Sphere(FixedMathSharp.Fixed64,FixedMathSharp.Vector3d)
Sphere(FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial)
Sphere(FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d)
Capsule(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d)
Capsule(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial)
Capsule(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d)
Cuboid(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Cuboid(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial)
Cuboid(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d)
Cylinder(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d)
Cylinder(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial)
Cylinder(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d)
Cone(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d)
Cone(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial)
Cone(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d)
ConvexMesh(FixedMathSharp.Vector3d[],System.Int32[],FixedMathSharp.Vector3d,Gravitas.Colliders.MeshInertiaPolicy)
ConvexMesh(FixedMathSharp.Vector3d[],System.Int32[],FixedMathSharp.Vector3d,Gravitas.Materials.PhysicsMaterial,Gravitas.Colliders.MeshInertiaPolicy)
ConvexMesh(FixedMathSharp.Vector3d[],System.Int32[],FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion,FixedMathSharp.Vector3d,Gravitas.Colliders.MeshInertiaPolicy)
get_IsDefault()
TryGetMaterial(Gravitas.Materials.PhysicsMaterial&)
ResolveMaterial(Gravitas.Materials.PhysicsMaterial)
ValidateScale(FixedMathSharp.Vector3d)