< Summary

Information
Class: Gravitas.Colliders.ExactMassProperties
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassProperties.cs
Line coverage
100%
Covered lines: 413
Uncovered lines: 0
Coverable lines: 413
Total lines: 626
Line coverage: 100%
Branch coverage
100%
Covered branches: 48
Total branches: 48
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
CreateWeight(...)100%11100%
CreateWeight(...)100%11100%
CreateWeight(...)100%11100%
CreateWeight(...)100%11100%
CreateAreaWeight(...)100%22100%
CreateTriangleAreaWeight(...)100%11100%
TryGetMeasure(...)100%11100%
TryAdd(...)100%44100%
TryGetProportionalShare(...)100%66100%
CreatePoint(...)100%11100%
CreatePoint(...)100%11100%
CreatePoint(...)100%11100%
CreatePoint(...)100%11100%
TryGetPoint(...)100%22100%
TryGetPoint(...)100%22100%
TryGetWeightedAverage(...)100%66100%
TryGetWeightedAverage(...)100%66100%
TryAddParallelAxisTensor(...)100%88100%
TryAddParallelAxisMoment(...)100%66100%
CreateWeightCore(...)100%11100%
TryGetParallelAxisValue(...)100%11100%
Product(...)100%11100%
PowerOfOne(...)100%22100%
EnsureNonNegative(...)100%22100%
ValidateWeightedInputs(...)100%22100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/MassProperties/ExactMassProperties.cs

#LineLine coverage
 1//=======================================================================
 2// ExactMassProperties.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;
 9
 10using FixedMathSharp;
 11using FixedMathSharp.Geometry;
 12
 13namespace Gravitas.Colliders;
 14
 15/// <summary>
 16/// Owns exact bounded arithmetic for semantic mass-property values.
 17/// </summary>
 18internal static class ExactMassProperties
 19{
 120    private static readonly Signed192 One = Signed192.One;
 121    private static readonly Signed320 Point3dDenominator =
 122        WideArithmetic.MultiplySigned192(One, One);
 123    private static readonly Signed576 WeightMeasureDenominator =
 124        PowerOfOne(3);
 125    private static readonly Signed576 ParallelAxis2dDenominator =
 126        PowerOfOne(4);
 127    private static readonly Signed576 ParallelAxis3dDenominator =
 128        PowerOfOne(6);
 29
 30    internal static ExactMassWeight CreateWeight(Fixed64 measure)
 31    {
 7532        EnsureNonNegative(measure, nameof(measure));
 7433        return CreateWeightCore(
 7434            measure,
 7435            Fixed64.One,
 7436            Fixed64.One,
 7437            Fixed64.One);
 38    }
 39
 40    internal static ExactMassWeight CreateWeight(
 41        Fixed64 first,
 42        Fixed64 second)
 43    {
 144        EnsureNonNegative(first, nameof(first));
 145        EnsureNonNegative(second, nameof(second));
 146        return CreateWeightCore(
 147            first,
 148            second,
 149            Fixed64.One,
 150            Fixed64.One);
 51    }
 52
 53    internal static ExactMassWeight CreateWeight(
 54        Fixed64 first,
 55        Fixed64 second,
 56        Fixed64 third)
 57    {
 480158        EnsureNonNegative(first, nameof(first));
 480159        EnsureNonNegative(second, nameof(second));
 480160        EnsureNonNegative(third, nameof(third));
 480161        return CreateWeightCore(
 480162            first,
 480163            second,
 480164            third,
 480165            Fixed64.One);
 66    }
 67
 68    internal static ExactMassWeight CreateWeight(
 69        Fixed64 first,
 70        Fixed64 second,
 71        Fixed64 third,
 72        Fixed64 fourth)
 73    {
 255974        EnsureNonNegative(first, nameof(first));
 255975        EnsureNonNegative(second, nameof(second));
 255976        EnsureNonNegative(third, nameof(third));
 255977        EnsureNonNegative(fourth, nameof(fourth));
 255978        return CreateWeightCore(first, second, third, fourth);
 79    }
 80
 81    internal static ExactMassWeight CreateAreaWeight(
 82        Signed320 signedDoubleArea)
 83    {
 555284        Signed320 absoluteArea = signedDoubleArea.Sign < 0
 555285            ? WideArithmetic.SubtractSigned320(
 555286                default,
 555287                signedDoubleArea)
 555288            : signedDoubleArea;
 555289        Signed320 halfScale = WideArithmetic.MultiplySigned192(
 555290            Signed192.Raw(Fixed64.Half),
 555291            One);
 555292        return new ExactMassWeight(
 555293            Signed320.NarrowValue(
 555294                WideArithmetic.MultiplySigned320(
 555295                    absoluteArea,
 555296                    halfScale)));
 97    }
 98
 99    internal static ExactMassWeight CreateTriangleAreaWeight(
 100        Signed320 squaredDoubleArea)
 101    {
 161950102        Signed320 scaledRoot =
 161950103            WideArithmetic.GetFloorSquareRootScaledByFixed64(
 161950104                Signed576.ExtendValue(squaredDoubleArea));
 161950105        Signed576 numerator = WideArithmetic.MultiplySigned320(
 161950106            scaledRoot,
 161950107            Signed320.ExtendValue(
 161950108                Signed192.Raw(Fixed64.Half)));
 161950109        return new ExactMassWeight(
 161950110            Signed320.NarrowValue(numerator));
 111    }
 112
 113    internal static bool TryGetMeasure(
 114        ExactMassWeight weight,
 115        out Fixed64 measure) =>
 32116        Fixed64.TryGetSignedRawRatio(
 32117            Signed576.ExtendValue(weight.Numerator),
 32118            WeightMeasureDenominator,
 32119            out measure);
 120
 121    internal static bool TryAdd(
 122        ExactMassWeight first,
 123        ExactMassWeight second,
 124        out ExactMassWeight result)
 125    {
 3714126        Signed576 sum = WideArithmetic.AddSigned576(
 3714127            Signed576.ExtendValue(first.Numerator),
 3714128            Signed576.ExtendValue(second.Numerator));
 3714129        if (!Signed320.TryNarrowSigned(sum, out Signed320 numerator)
 3714130            || numerator.Sign < 0)
 131        {
 2132            result = default;
 2133            return false;
 134        }
 135
 3712136        result = new ExactMassWeight(numerator);
 3712137        return true;
 138    }
 139
 140    internal static bool TryGetProportionalShare(
 141        ExactMassWeight weight,
 142        Fixed64 total,
 143        ExactMassWeight totalWeight,
 144        out Fixed64 share)
 145    {
 1995146        if (total < Fixed64.Zero
 1995147            || totalWeight.Numerator.Sign <= 0
 1995148            || WideArithmetic.CompareNonNegative(
 1995149                Signed576.ExtendValue(weight.Numerator),
 1995150                Signed576.ExtendValue(totalWeight.Numerator)) > 0)
 151        {
 3152            share = default;
 3153            return false;
 154        }
 155
 1992156        Signed576 numerator = WideArithmetic.MultiplySigned320(
 1992157            weight.Numerator,
 1992158            Signed320.ExtendValue(Signed192.Raw(total)));
 1992159        return Fixed64.TryGetSignedRawRatio(
 1992160            numerator,
 1992161            Signed576.ExtendValue(totalWeight.Numerator),
 1992162            out share);
 163    }
 164
 165    internal static ExactMassPoint3D CreatePoint(Vector3d point) =>
 667166        new(
 667167            Product(Signed192.Raw(point.X), One, One),
 667168            Product(Signed192.Raw(point.Y), One, One),
 667169            Product(Signed192.Raw(point.Z), One, One));
 170
 171    internal static ExactMassPoint3D CreatePoint(
 172        Vector3d outerPoint,
 173        Vector3d outerScale,
 174        Vector3d innerOffset,
 175        Vector3d innerScale,
 176        Vector3d innerDisplacement,
 177        FixedQuaternion innerRotation)
 178    {
 66863179        WideRationalBasis3d basis = new(innerRotation);
 66863180        Signed576 denominator = Signed576.ExtendValue(
 66863181            WideArithmetic.MultiplySigned192(
 66863182                basis.Denominator,
 66863183                Signed192.One));
 66863184        Signed320 x = WideArithmetic.GetSignedRatioWith64FractionBits(
 66863185            WideRationalBasis3d.GetComposedScaledCoordinateNumerator(
 66863186                outerPoint.X,
 66863187                outerScale.X,
 66863188                basis.Xx,
 66863189                basis.Yx,
 66863190                basis.Zx,
 66863191                basis.Denominator,
 66863192                innerOffset.X,
 66863193                innerScale.X,
 66863194                innerDisplacement),
 66863195            denominator);
 66863196        Signed320 y = WideArithmetic.GetSignedRatioWith64FractionBits(
 66863197            WideRationalBasis3d.GetComposedScaledCoordinateNumerator(
 66863198                outerPoint.Y,
 66863199                outerScale.Y,
 66863200                basis.Xy,
 66863201                basis.Yy,
 66863202                basis.Zy,
 66863203                basis.Denominator,
 66863204                innerOffset.Y,
 66863205                innerScale.Y,
 66863206                innerDisplacement),
 66863207            denominator);
 66863208        Signed320 z = WideArithmetic.GetSignedRatioWith64FractionBits(
 66863209            WideRationalBasis3d.GetComposedScaledCoordinateNumerator(
 66863210                outerPoint.Z,
 66863211                outerScale.Z,
 66863212                basis.Xz,
 66863213                basis.Yz,
 66863214                basis.Zz,
 66863215                basis.Denominator,
 66863216                innerOffset.Z,
 66863217                innerScale.Z,
 66863218                innerDisplacement),
 66863219            denominator);
 66863220        return new ExactMassPoint3D(x, y, z);
 221    }
 222
 223    internal static ExactMassPoint2D CreatePoint(Vector2d point) =>
 713224        new(
 713225            WideArithmetic.MultiplySigned192(Signed192.Raw(point.X), One),
 713226            WideArithmetic.MultiplySigned192(Signed192.Raw(point.Y), One));
 227
 228    internal static ExactMassPoint2D CreatePoint(
 229        Vector2d outerPoint,
 230        Vector2d outerScale,
 231        Vector2d innerOffset,
 232        Vector2d innerScale,
 233        Vector2d innerDisplacement,
 234        Fixed64 innerRotation)
 235    {
 48169236        Fixed64 cosine = FixedMath.Cos(innerRotation);
 48169237        Fixed64 sine = FixedMath.Sin(innerRotation);
 48169238        Signed320 rotatedX = WideArithmetic.SubtractSigned320(
 48169239            WideArithmetic.MultiplySigned192(
 48169240                Signed192.Raw(innerDisplacement.X),
 48169241                Signed192.Raw(cosine)),
 48169242            WideArithmetic.MultiplySigned192(
 48169243                Signed192.Raw(innerDisplacement.Y),
 48169244                Signed192.Raw(sine)));
 48169245        Signed320 rotatedY = WideArithmetic.AddSigned320(
 48169246            WideArithmetic.MultiplySigned192(
 48169247                Signed192.Raw(innerDisplacement.X),
 48169248                Signed192.Raw(sine)),
 48169249            WideArithmetic.MultiplySigned192(
 48169250                Signed192.Raw(innerDisplacement.Y),
 48169251                Signed192.Raw(cosine)));
 48169252        return new ExactMassPoint2D(
 48169253            WideArithmetic.AddSigned320(
 48169254                WideArithmetic.AddSigned320(
 48169255                    WideArithmetic.MultiplySigned192(
 48169256                        Signed192.Raw(outerPoint.X),
 48169257                        Signed192.Raw(outerScale.X)),
 48169258                    WideArithmetic.MultiplySigned192(
 48169259                        Signed192.Raw(innerOffset.X),
 48169260                        Signed192.Raw(innerScale.X))),
 48169261                rotatedX),
 48169262            WideArithmetic.AddSigned320(
 48169263                WideArithmetic.AddSigned320(
 48169264                    WideArithmetic.MultiplySigned192(
 48169265                        Signed192.Raw(outerPoint.Y),
 48169266                        Signed192.Raw(outerScale.Y)),
 48169267                    WideArithmetic.MultiplySigned192(
 48169268                        Signed192.Raw(innerOffset.Y),
 48169269                        Signed192.Raw(innerScale.Y))),
 48169270                rotatedY));
 271    }
 272
 273    internal static bool TryGetPoint(
 274        ExactMassPoint3D point,
 275        out Vector3d result)
 276    {
 55855277        Signed576 denominator =
 55855278            Signed576.ExtendValue(Point3dDenominator);
 55855279        bool representable = Fixed64.TryGetSignedRawRatio(
 55855280                Signed576.ExtendValue(point.XNumerator),
 55855281                denominator,
 55855282                out Fixed64 x)
 55855283            & Fixed64.TryGetSignedRawRatio(
 55855284                Signed576.ExtendValue(point.YNumerator),
 55855285                denominator,
 55855286                out Fixed64 y)
 55855287            & Fixed64.TryGetSignedRawRatio(
 55855288                Signed576.ExtendValue(point.ZNumerator),
 55855289                denominator,
 55855290                out Fixed64 z);
 55855291        result = representable
 55855292            ? new Vector3d(x, y, z)
 55855293            : default;
 55855294        return representable;
 295    }
 296
 297    internal static bool TryGetPoint(
 298        ExactMassPoint2D point,
 299        out Vector2d result)
 300    {
 30001301        Signed576 denominator =
 30001302            Signed576.ExtendValue(Signed320.ExtendValue(One));
 30001303        bool representable = Fixed64.TryGetSignedRawRatio(
 30001304                Signed576.ExtendValue(point.XNumerator),
 30001305                denominator,
 30001306                out Fixed64 x)
 30001307            & Fixed64.TryGetSignedRawRatio(
 30001308                Signed576.ExtendValue(point.YNumerator),
 30001309                denominator,
 30001310                out Fixed64 y);
 30001311        result = representable
 30001312            ? new Vector2d(x, y)
 30001313            : default;
 30001314        return representable;
 315    }
 316
 317    internal static bool TryGetWeightedAverage(
 318        ReadOnlySpan<ExactMassPoint3D> points,
 319        ReadOnlySpan<ExactMassWeight> weights,
 320        out Vector3d average)
 321    {
 671322        ValidateWeightedInputs(points.Length, weights.Length);
 670323        Signed576 totalWeight = default;
 670324        Signed576 x = default;
 670325        Signed576 y = default;
 670326        Signed576 z = default;
 3628327        for (int i = 0; i < points.Length; i++)
 328        {
 1144329            Signed320 weight = weights[i].Numerator;
 1144330            totalWeight = WideArithmetic.AddSigned576(
 1144331                totalWeight,
 1144332                Signed576.ExtendValue(weight));
 1144333            x = WideArithmetic.AddSigned576(
 1144334                x,
 1144335                WideArithmetic.MultiplySigned320(
 1144336                    points[i].XNumerator,
 1144337                    weight));
 1144338            y = WideArithmetic.AddSigned576(
 1144339                y,
 1144340                WideArithmetic.MultiplySigned320(
 1144341                    points[i].YNumerator,
 1144342                    weight));
 1144343            z = WideArithmetic.AddSigned576(
 1144344                z,
 1144345                WideArithmetic.MultiplySigned320(
 1144346                    points[i].ZNumerator,
 1144347                    weight));
 348        }
 349
 670350        if (totalWeight.Sign <= 0)
 351        {
 1352            average = default;
 1353            return false;
 354        }
 355
 669356        Signed576 denominator = WideArithmetic.MultiplySigned576(
 669357            totalWeight,
 669358            One,
 669359            One);
 669360        bool representable = Fixed64.TryGetSignedRawRatio(
 669361                x,
 669362                denominator,
 669363                out Fixed64 resultX)
 669364            & Fixed64.TryGetSignedRawRatio(
 669365                y,
 669366                denominator,
 669367                out Fixed64 resultY)
 669368            & Fixed64.TryGetSignedRawRatio(
 669369                z,
 669370                denominator,
 669371                out Fixed64 resultZ);
 669372        average = representable
 669373            ? new Vector3d(resultX, resultY, resultZ)
 669374            : default;
 669375        return representable;
 376    }
 377
 378    internal static bool TryGetWeightedAverage(
 379        ReadOnlySpan<ExactMassPoint2D> points,
 380        ReadOnlySpan<ExactMassWeight> weights,
 381        out Vector2d average)
 382    {
 716383        ValidateWeightedInputs(points.Length, weights.Length);
 716384        Signed576 totalWeight = default;
 716385        Signed576 x = default;
 716386        Signed576 y = default;
 4036387        for (int i = 0; i < points.Length; i++)
 388        {
 1302389            Signed320 weight = weights[i].Numerator;
 1302390            totalWeight = WideArithmetic.AddSigned576(
 1302391                totalWeight,
 1302392                Signed576.ExtendValue(weight));
 1302393            x = WideArithmetic.AddSigned576(
 1302394                x,
 1302395                WideArithmetic.MultiplySigned320(
 1302396                    points[i].XNumerator,
 1302397                    weight));
 1302398            y = WideArithmetic.AddSigned576(
 1302399                y,
 1302400                WideArithmetic.MultiplySigned320(
 1302401                    points[i].YNumerator,
 1302402                    weight));
 403        }
 404
 716405        if (totalWeight.Sign <= 0)
 406        {
 1407            average = default;
 1408            return false;
 409        }
 410
 715411        Signed576 denominator = WideArithmetic.MultiplySigned576(
 715412            totalWeight,
 715413            One);
 715414        bool representable = Fixed64.TryGetSignedRawRatio(
 715415                x,
 715416                denominator,
 715417                out Fixed64 resultX)
 715418            & Fixed64.TryGetSignedRawRatio(
 715419                y,
 715420                denominator,
 715421                out Fixed64 resultY);
 715422        average = representable
 715423            ? new Vector2d(resultX, resultY)
 715424            : default;
 715425        return representable;
 426    }
 427
 428    internal static bool TryAddParallelAxisTensor(
 429        ExactMassPoint3D point,
 430        Fixed3x3 centerTensor,
 431        Fixed64 mass,
 432        Vector3d referencePoint,
 433        out Fixed3x3 tensor)
 434    {
 10383435        if (mass < Fixed64.Zero)
 436        {
 1437            tensor = default;
 1438            return false;
 439        }
 10382440        if (mass == Fixed64.Zero)
 441        {
 1442            tensor = centerTensor;
 1443            return true;
 444        }
 445
 10381446        Signed320 dx = WideArithmetic.SubtractSigned320(
 10381447            point.XNumerator,
 10381448            Product(Signed192.Raw(referencePoint.X), One, One));
 10381449        Signed320 dy = WideArithmetic.SubtractSigned320(
 10381450            point.YNumerator,
 10381451            Product(Signed192.Raw(referencePoint.Y), One, One));
 10381452        Signed320 dz = WideArithmetic.SubtractSigned320(
 10381453            point.ZNumerator,
 10381454            Product(Signed192.Raw(referencePoint.Z), One, One));
 10381455        Signed576 dxSquared = WideArithmetic.MultiplySigned320(dx, dx);
 10381456        Signed576 dySquared = WideArithmetic.MultiplySigned320(dy, dy);
 10381457        Signed576 dzSquared = WideArithmetic.MultiplySigned320(dz, dz);
 10381458        bool representable = TryGetParallelAxisValue(
 10381459                WideArithmetic.AddSigned576(dySquared, dzSquared),
 10381460                mass,
 10381461                ParallelAxis3dDenominator,
 10381462                out Fixed64 xx)
 10381463            & TryGetParallelAxisValue(
 10381464                WideArithmetic.AddSigned576(dxSquared, dzSquared),
 10381465                mass,
 10381466                ParallelAxis3dDenominator,
 10381467                out Fixed64 yy)
 10381468            & TryGetParallelAxisValue(
 10381469                WideArithmetic.AddSigned576(dxSquared, dySquared),
 10381470                mass,
 10381471                ParallelAxis3dDenominator,
 10381472                out Fixed64 zz)
 10381473            & TryGetParallelAxisValue(
 10381474                WideArithmetic.MultiplySigned320(dx, dy),
 10381475                mass,
 10381476                ParallelAxis3dDenominator,
 10381477                out Fixed64 xy)
 10381478            & TryGetParallelAxisValue(
 10381479                WideArithmetic.MultiplySigned320(dx, dz),
 10381480                mass,
 10381481                ParallelAxis3dDenominator,
 10381482                out Fixed64 xz)
 10381483            & TryGetParallelAxisValue(
 10381484                WideArithmetic.MultiplySigned320(dy, dz),
 10381485                mass,
 10381486                ParallelAxis3dDenominator,
 10381487                out Fixed64 yz);
 10381488        if (!representable)
 489        {
 13490            tensor = default;
 13491            return false;
 492        }
 493
 10368494        representable = Fixed64.TryAdd(centerTensor.M11, xx, out Fixed64 m11)
 10368495            & Fixed64.TrySubtract(centerTensor.M12, xy, out Fixed64 m12)
 10368496            & Fixed64.TrySubtract(centerTensor.M13, xz, out Fixed64 m13)
 10368497            & Fixed64.TrySubtract(centerTensor.M21, xy, out Fixed64 m21)
 10368498            & Fixed64.TryAdd(centerTensor.M22, yy, out Fixed64 m22)
 10368499            & Fixed64.TrySubtract(centerTensor.M23, yz, out Fixed64 m23)
 10368500            & Fixed64.TrySubtract(centerTensor.M31, xz, out Fixed64 m31)
 10368501            & Fixed64.TrySubtract(centerTensor.M32, yz, out Fixed64 m32)
 10368502            & Fixed64.TryAdd(centerTensor.M33, zz, out Fixed64 m33);
 10368503        tensor = representable
 10368504            ? new Fixed3x3(
 10368505                m11, m12, m13,
 10368506                m21, m22, m23,
 10368507                m31, m32, m33)
 10368508            : default;
 10368509        return representable;
 510    }
 511
 512    internal static bool TryAddParallelAxisMoment(
 513        ExactMassPoint2D point,
 514        Fixed64 centerMoment,
 515        Fixed64 mass,
 516        Vector2d referencePoint,
 517        out Fixed64 moment)
 518    {
 17485519        if (mass < Fixed64.Zero)
 520        {
 1521            moment = default;
 1522            return false;
 523        }
 17484524        if (mass == Fixed64.Zero)
 525        {
 1526            moment = centerMoment;
 1527            return true;
 528        }
 529
 17483530        Signed320 dx = WideArithmetic.SubtractSigned320(
 17483531            point.XNumerator,
 17483532            WideArithmetic.MultiplySigned192(
 17483533                Signed192.Raw(referencePoint.X),
 17483534                One));
 17483535        Signed320 dy = WideArithmetic.SubtractSigned320(
 17483536            point.YNumerator,
 17483537            WideArithmetic.MultiplySigned192(
 17483538                Signed192.Raw(referencePoint.Y),
 17483539                One));
 17483540        Signed576 squaredDistance = WideArithmetic.AddSigned576(
 17483541            WideArithmetic.MultiplySigned320(dx, dx),
 17483542            WideArithmetic.MultiplySigned320(dy, dy));
 17483543        if (!TryGetParallelAxisValue(
 17483544                squaredDistance,
 17483545                mass,
 17483546                ParallelAxis2dDenominator,
 17483547                out Fixed64 shift))
 548        {
 13549            moment = default;
 13550            return false;
 551        }
 552
 17470553        return Fixed64.TryAdd(centerMoment, shift, out moment);
 554    }
 555
 556    private static ExactMassWeight CreateWeightCore(
 557        Fixed64 first,
 558        Fixed64 second,
 559        Fixed64 third,
 560        Fixed64 fourth)
 561    {
 7435562        Signed576 product = WideArithmetic.MultiplySigned576(
 7435563            Signed576.ExtendValue(
 7435564                Signed320.ExtendValue(Signed192.Raw(first))),
 7435565            Signed192.Raw(second),
 7435566            Signed192.Raw(third),
 7435567            Signed192.Raw(fourth));
 7435568        return new ExactMassWeight(Signed320.NarrowValue(product));
 569    }
 570
 571    private static bool TryGetParallelAxisValue(
 572        Signed576 squaredValue,
 573        Fixed64 mass,
 574        Signed576 denominator,
 575        out Fixed64 value) =>
 79769576        Fixed64.TryGetSignedRawRatio(
 79769577            WideArithmetic.MultiplySigned576(
 79769578                squaredValue,
 79769579                Signed192.Raw(mass)),
 79769580            denominator,
 79769581            out value);
 582
 583    private static Signed320 Product(
 584        Signed192 first,
 585        Signed192 second,
 586        Signed192 third) =>
 33144587        Signed320.NarrowValue(
 33144588            WideArithmetic.MultiplySigned576(
 33144589                Signed576.ExtendValue(
 33144590                    Signed320.ExtendValue(first)),
 33144591                second,
 33144592                third));
 593
 594    private static Signed576 PowerOfOne(int exponent)
 595    {
 3596        Signed576 result = Signed576.ExtendValue(
 3597            Signed320.ExtendValue(Signed192.Signed(1)));
 32598        for (int i = 0; i < exponent; i++)
 13599            result = WideArithmetic.MultiplySigned576(result, One);
 3600        return result;
 601    }
 602
 603    private static void EnsureNonNegative(
 604        Fixed64 value,
 605        string parameterName)
 606    {
 24716607        if (value < Fixed64.Zero)
 608        {
 1609            throw new ArgumentOutOfRangeException(
 1610                parameterName,
 1611                "Mass-property weight factors cannot be negative.");
 612        }
 24715613    }
 614
 615    private static void ValidateWeightedInputs(
 616        int pointCount,
 617        int weightCount)
 618    {
 1387619        if (pointCount != weightCount)
 620        {
 1621            throw new ArgumentException(
 1622                "Mass points and weights must have the same length.",
 1623                "weights");
 624        }
 1386625    }
 626}

Methods/Properties

.cctor()
CreateWeight(FixedMathSharp.Fixed64)
CreateWeight(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
CreateWeight(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
CreateWeight(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
CreateAreaWeight(FixedMathSharp.Signed320)
CreateTriangleAreaWeight(FixedMathSharp.Signed320)
TryGetMeasure(Gravitas.Colliders.ExactMassWeight,FixedMathSharp.Fixed64&)
TryAdd(Gravitas.Colliders.ExactMassWeight,Gravitas.Colliders.ExactMassWeight,Gravitas.Colliders.ExactMassWeight&)
TryGetProportionalShare(Gravitas.Colliders.ExactMassWeight,FixedMathSharp.Fixed64,Gravitas.Colliders.ExactMassWeight,FixedMathSharp.Fixed64&)
CreatePoint(FixedMathSharp.Vector3d)
CreatePoint(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
CreatePoint(FixedMathSharp.Vector2d)
CreatePoint(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d,FixedMathSharp.Vector2d,FixedMathSharp.Vector2d,FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
TryGetPoint(Gravitas.Colliders.ExactMassPoint3D,FixedMathSharp.Vector3d&)
TryGetPoint(Gravitas.Colliders.ExactMassPoint2D,FixedMathSharp.Vector2d&)
TryGetWeightedAverage(System.ReadOnlySpan`1<Gravitas.Colliders.ExactMassPoint3D>,System.ReadOnlySpan`1<Gravitas.Colliders.ExactMassWeight>,FixedMathSharp.Vector3d&)
TryGetWeightedAverage(System.ReadOnlySpan`1<Gravitas.Colliders.ExactMassPoint2D>,System.ReadOnlySpan`1<Gravitas.Colliders.ExactMassWeight>,FixedMathSharp.Vector2d&)
TryAddParallelAxisTensor(Gravitas.Colliders.ExactMassPoint3D,FixedMathSharp.Fixed3x3,FixedMathSharp.Fixed64,FixedMathSharp.Vector3d,FixedMathSharp.Fixed3x3&)
TryAddParallelAxisMoment(Gravitas.Colliders.ExactMassPoint2D,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Vector2d,FixedMathSharp.Fixed64&)
CreateWeightCore(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
TryGetParallelAxisValue(FixedMathSharp.Signed576,FixedMathSharp.Fixed64,FixedMathSharp.Signed576,FixedMathSharp.Fixed64&)
Product(FixedMathSharp.Signed192,FixedMathSharp.Signed192,FixedMathSharp.Signed192)
PowerOfOne(System.Int32)
EnsureNonNegative(FixedMathSharp.Fixed64,System.String)
ValidateWeightedInputs(System.Int32,System.Int32)