| | | 1 | | //======================================================================= |
| | | 2 | | // FixedPointAnchorTerm2d.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 | | namespace FixedMathSharp.Geometry; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Two-dimensional counterpart of <see cref="FixedPointAnchorTerm3d"/>. |
| | | 14 | | /// </summary> |
| | | 15 | | internal readonly struct FixedPointAnchorTerm2d : |
| | | 16 | | IEquatable<FixedPointAnchorTerm2d> |
| | | 17 | | { |
| | | 18 | | internal readonly long X; |
| | | 19 | | internal readonly long Y; |
| | | 20 | | |
| | | 21 | | private FixedPointAnchorTerm2d(long x, long y) |
| | | 22 | | { |
| | 645 | 23 | | X = x; |
| | 645 | 24 | | Y = y; |
| | 645 | 25 | | } |
| | | 26 | | |
| | 834 | 27 | | internal bool IsZero => X == 0L && Y == 0L; |
| | | 28 | | |
| | | 29 | | internal static FixedPointAnchorTerm2d CreateCenteredAxisSupport( |
| | | 30 | | Vector2d localAxis, |
| | | 31 | | Fixed64 signedAxisLength, |
| | | 32 | | Vector2d localRadialDirection, |
| | | 33 | | Fixed64 radius, |
| | | 34 | | Vector2d roundedAxialOffset, |
| | | 35 | | Vector2d roundedRadialOffset) => |
| | 645 | 36 | | new( |
| | 645 | 37 | | FixedPointAnchorTerm3d.GetResidual( |
| | 645 | 38 | | localAxis.X, |
| | 645 | 39 | | signedAxisLength, |
| | 645 | 40 | | localRadialDirection.X, |
| | 645 | 41 | | radius, |
| | 645 | 42 | | roundedAxialOffset.X, |
| | 645 | 43 | | roundedRadialOffset.X), |
| | 645 | 44 | | FixedPointAnchorTerm3d.GetResidual( |
| | 645 | 45 | | localAxis.Y, |
| | 645 | 46 | | signedAxisLength, |
| | 645 | 47 | | localRadialDirection.Y, |
| | 645 | 48 | | radius, |
| | 645 | 49 | | roundedAxialOffset.Y, |
| | 645 | 50 | | roundedRadialOffset.Y)); |
| | | 51 | | |
| | | 52 | | internal static FixedPointAnchorTerm2d CreateRadialSupport( |
| | | 53 | | Vector2d localRadialDirection, |
| | | 54 | | Fixed64 radius, |
| | | 55 | | Vector2d roundedRadialOffset) => |
| | 55 | 56 | | CreateCenteredAxisSupport( |
| | 55 | 57 | | Vector2d.Zero, |
| | 55 | 58 | | Fixed64.Zero, |
| | 55 | 59 | | localRadialDirection, |
| | 55 | 60 | | radius, |
| | 55 | 61 | | Vector2d.Zero, |
| | 55 | 62 | | roundedRadialOffset); |
| | | 63 | | |
| | | 64 | | public bool Equals(FixedPointAnchorTerm2d other) => |
| | 24 | 65 | | X == other.X && Y == other.Y; |
| | | 66 | | |
| | | 67 | | public override int GetHashCode() |
| | | 68 | | { |
| | | 69 | | unchecked |
| | | 70 | | { |
| | 2 | 71 | | int hash = 17; |
| | 2 | 72 | | hash = (hash * 31) + X.GetHashCode(); |
| | 2 | 73 | | hash = (hash * 31) + Y.GetHashCode(); |
| | 2 | 74 | | return hash; |
| | | 75 | | } |
| | | 76 | | } |
| | | 77 | | } |