| | | 1 | | //======================================================================= |
| | | 2 | | // Physics2DSupportQuery.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 | | using Gravitas.Colliders; |
| | | 10 | | using Gravitas.Support; |
| | | 11 | | |
| | | 12 | | namespace Gravitas.Queries; |
| | | 13 | | |
| | | 14 | | /// <summary>Describes a downward circle probe for physical support of a registered 2D collider.</summary> |
| | | 15 | | public readonly struct Physics2DSupportQuery |
| | | 16 | | { |
| | | 17 | | /// <summary>Creates a support probe and normalizes its nonzero upward direction.</summary> |
| | | 18 | | public Physics2DSupportQuery(LSCollider2D source, Vector2d center, Fixed64 radius, |
| | | 19 | | Vector2d up, Fixed64 distance, Fixed64 minimumNormalDot, PhysicsLayerMask layers) |
| | | 20 | | { |
| | 46 | 21 | | ChronicleGuard.ThrowIfNull(source, nameof(source)); |
| | 45 | 22 | | ChronicleGuard.ThrowIfArgument(radius <= Fixed64.Zero, nameof(radius), "Support radius must be positive."); |
| | 43 | 23 | | ColliderGeometryPolicy.ValidateReach(radius, nameof(radius)); |
| | 42 | 24 | | ChronicleGuard.ThrowIfArgument(distance <= Fixed64.Zero, nameof(distance), "Support distance must be positive.") |
| | 40 | 25 | | ChronicleGuard.ThrowIfArgument(up == Vector2d.Zero, nameof(up), "Support up must be nonzero."); |
| | 39 | 26 | | ChronicleGuard.ThrowIfArgument(minimumNormalDot <= Fixed64.Zero || minimumNormalDot > Fixed64.One, |
| | 39 | 27 | | nameof(minimumNormalDot), "Support normal threshold must be in (0, 1]."); |
| | 37 | 28 | | Source = source; |
| | 37 | 29 | | Center = center; |
| | 37 | 30 | | Radius = radius; |
| | 37 | 31 | | Up = up.Normalized; |
| | 37 | 32 | | Distance = distance; |
| | 37 | 33 | | MinimumNormalDot = minimumNormalDot; |
| | 37 | 34 | | Layers = layers; |
| | 37 | 35 | | } |
| | | 36 | | |
| | | 37 | | /// <summary>Gets the registered collider whose physical collision policy applies.</summary> |
| | | 38 | | public LSCollider2D Source { get; } |
| | | 39 | | /// <summary>Gets the initial probe center in native physics coordinates.</summary> |
| | | 40 | | public Vector2d Center { get; } |
| | | 41 | | /// <summary>Gets the positive probe radius.</summary> |
| | | 42 | | public Fixed64 Radius { get; } |
| | | 43 | | /// <summary>Gets the nonzero direction opposite to the sweep.</summary> |
| | | 44 | | public Vector2d Up { get; } |
| | | 45 | | /// <summary>Gets the positive maximum travel distance.</summary> |
| | | 46 | | public Fixed64 Distance { get; } |
| | | 47 | | /// <summary>Gets the inclusive normal/up threshold in (0, 1].</summary> |
| | | 48 | | public Fixed64 MinimumNormalDot { get; } |
| | | 49 | | /// <summary>Gets the included support layers, in addition to physical collision filters.</summary> |
| | | 50 | | public PhysicsLayerMask Layers { get; } |
| | | 51 | | } |
| | | 52 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 53 | | // See LICENSE file in the project root for full license information. |