| | | 1 | | //======================================================================= |
| | | 2 | | // PolygonMassProperties2D.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 | | |
| | | 8 | | using System; |
| | | 9 | | |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using FixedMathSharp.Geometry; |
| | | 12 | | |
| | | 13 | | namespace Gravitas.Colliders; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Owns exact mass-property interpretation for convex polygon area. |
| | | 17 | | /// </summary> |
| | | 18 | | internal static class PolygonMassProperties2D |
| | | 19 | | { |
| | | 20 | | internal static bool TryGetWeightAndCentroid( |
| | | 21 | | ReadOnlySpan<Vector2d> vertices, |
| | | 22 | | out ExactMassWeight weight, |
| | | 23 | | out Vector2d centroid) |
| | | 24 | | { |
| | 5553 | 25 | | bool result = |
| | 5553 | 26 | | WideConvex2dRelations.TryGetSignedDoubleAreaAndCentroid( |
| | 5553 | 27 | | vertices, |
| | 5553 | 28 | | out Signed320 signedDoubleArea, |
| | 5553 | 29 | | out centroid); |
| | 5553 | 30 | | weight = result |
| | 5553 | 31 | | ? ExactMassProperties.CreateAreaWeight(signedDoubleArea) |
| | 5553 | 32 | | : ExactMassWeight.Zero; |
| | 5553 | 33 | | return result; |
| | | 34 | | } |
| | | 35 | | } |