| | | 1 | | //======================================================================= |
| | | 2 | | // ContactLever2D.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 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | |
| | | 10 | | namespace Gravitas.CollisionHandling; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Carries a 2D contact lever or signals that the solver must use exact anchor arithmetic. |
| | | 14 | | /// </summary> |
| | | 15 | | internal readonly struct ContactLever2D |
| | | 16 | | { |
| | | 17 | | private ContactLever2D(Vector2d vector, bool isExact) |
| | | 18 | | { |
| | 35598 | 19 | | Vector = vector; |
| | 35598 | 20 | | IsExact = isExact; |
| | 35598 | 21 | | } |
| | | 22 | | |
| | | 23 | | internal bool IsExact { get; } |
| | | 24 | | |
| | | 25 | | internal Vector2d Vector { get; } |
| | | 26 | | |
| | | 27 | | internal static ContactLever2D Zero => |
| | 4373 | 28 | | new(Vector2d.Zero, isExact: false); |
| | | 29 | | |
| | | 30 | | internal static ContactLever2D Create( |
| | | 31 | | in ContactAnchor2D point, |
| | | 32 | | in ContactAnchor2D origin) |
| | | 33 | | { |
| | 31225 | 34 | | if (point.TryGetOffsetFrom(origin, out Vector2d vector)) |
| | 31203 | 35 | | return new ContactLever2D(vector, isExact: false); |
| | | 36 | | |
| | 22 | 37 | | return new ContactLever2D(default, isExact: true); |
| | | 38 | | } |
| | | 39 | | } |