| | | 1 | | using MemoryPack; |
| | | 2 | | using System; |
| | | 3 | | using System.Text.Json.Serialization; |
| | | 4 | | |
| | | 5 | | namespace FixedMathSharp; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents a keyframe in a <see cref="FixedCurve"/>, defining a value at a specific time. |
| | | 9 | | /// </summary> |
| | | 10 | | [Serializable] |
| | | 11 | | [MemoryPackable] |
| | | 12 | | public partial struct FixedCurveKey : IEquatable<FixedCurveKey> |
| | | 13 | | { |
| | | 14 | | #region Fields |
| | | 15 | | |
| | | 16 | | /// <summary>The time at which this keyframe occurs.</summary> |
| | | 17 | | [JsonInclude] |
| | | 18 | | [MemoryPackOrder(0)] |
| | | 19 | | public Fixed64 Time; |
| | | 20 | | |
| | | 21 | | /// <summary>The value of the curve at this keyframe.</summary> |
| | | 22 | | [JsonInclude] |
| | | 23 | | [MemoryPackOrder(1)] |
| | | 24 | | public Fixed64 Value; |
| | | 25 | | |
| | | 26 | | /// <summary>The incoming tangent for cubic interpolation.</summary> |
| | | 27 | | [JsonInclude] |
| | | 28 | | [MemoryPackOrder(2)] |
| | | 29 | | public Fixed64 InTangent; |
| | | 30 | | |
| | | 31 | | /// <summary>The outgoing tangent for cubic interpolation.</summary> |
| | | 32 | | [JsonInclude] |
| | | 33 | | [MemoryPackOrder(3)] |
| | | 34 | | public Fixed64 OutTangent; |
| | | 35 | | |
| | | 36 | | #endregion |
| | | 37 | | |
| | | 38 | | #region Constructors |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Creates a keyframe with a specified time and value. |
| | | 42 | | /// </summary> |
| | | 43 | | public FixedCurveKey(double time, double value) |
| | 102 | 44 | | : this(new Fixed64(time), new Fixed64(value)) { } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Creates a keyframe with optional tangents for cubic interpolation. |
| | | 48 | | /// </summary> |
| | | 49 | | public FixedCurveKey(double time, double value, double inTangent, double outTangent) |
| | 9 | 50 | | : this(new Fixed64(time), new Fixed64(value), new Fixed64(inTangent), new Fixed64(outTangent)) { } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Creates a keyframe with a specified time and value. |
| | | 54 | | /// </summary> |
| | | 55 | | public FixedCurveKey(Fixed64 time, Fixed64 value) |
| | 108 | 56 | | : this(time, value, Fixed64.Zero, Fixed64.Zero) { } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Creates a keyframe with optional tangents for cubic interpolation. |
| | | 60 | | /// </summary> |
| | | 61 | | [JsonConstructor] |
| | | 62 | | public FixedCurveKey(Fixed64 time, Fixed64 value, Fixed64 inTangent, Fixed64 outTangent) |
| | 43 | 63 | | { |
| | 43 | 64 | | Time = time; |
| | 43 | 65 | | Value = value; |
| | 43 | 66 | | InTangent = inTangent; |
| | 43 | 67 | | OutTangent = outTangent; |
| | 43 | 68 | | } |
| | | 69 | | |
| | | 70 | | #endregion |
| | | 71 | | |
| | | 72 | | #region Equality |
| | | 73 | | |
| | | 74 | | public bool Equals(FixedCurveKey other) |
| | 17 | 75 | | { |
| | 17 | 76 | | return Time == other.Time && |
| | 17 | 77 | | Value == other.Value && |
| | 17 | 78 | | InTangent == other.InTangent && |
| | 17 | 79 | | OutTangent == other.OutTangent; |
| | 17 | 80 | | } |
| | | 81 | | |
| | 2 | 82 | | public override bool Equals(object? obj) => obj is FixedCurveKey other && Equals(other); |
| | | 83 | | |
| | | 84 | | public override int GetHashCode() |
| | 6 | 85 | | { |
| | 6 | 86 | | return HashCode.Combine(Time, Value, InTangent, OutTangent); |
| | 6 | 87 | | } |
| | | 88 | | |
| | 2 | 89 | | public static bool operator ==(FixedCurveKey left, FixedCurveKey right) => left.Equals(right); |
| | | 90 | | |
| | 1 | 91 | | public static bool operator !=(FixedCurveKey left, FixedCurveKey right) => !(left == right); |
| | | 92 | | |
| | | 93 | | #endregion |
| | | 94 | | } |