< Summary

Information
Class: FixedMathSharp.FixedCurveKey
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Curves/FixedCurveKey.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 141
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
FromDouble(...)100%11100%
FromDouble(...)100%11100%
Equals(...)100%66100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Curves/FixedCurveKey.cs

#LineLine coverage
 1//=======================================================================
 2// FixedCurveKey.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
 8using MemoryPack;
 9using System;
 10using System.Text.Json.Serialization;
 11
 12namespace FixedMathSharp;
 13
 14/// <summary>
 15/// Represents a keyframe in a <see cref="FixedCurve"/>, defining a value at a specific time.
 16/// </summary>
 17[Serializable]
 18[MemoryPackable]
 19public partial struct FixedCurveKey : IEquatable<FixedCurveKey>
 20{
 21    #region Fields
 22
 23    /// <summary>The time at which this keyframe occurs.</summary>
 24    [JsonInclude]
 25    [MemoryPackOrder(0)]
 26    public Fixed64 Time;
 27
 28    /// <summary>The value of the curve at this keyframe.</summary>
 29    [JsonInclude]
 30    [MemoryPackOrder(1)]
 31    public Fixed64 Value;
 32
 33    /// <summary>The incoming tangent for cubic interpolation.</summary>
 34    [JsonInclude]
 35    [MemoryPackOrder(2)]
 36    public Fixed64 InTangent;
 37
 38    /// <summary>The outgoing tangent for cubic interpolation.</summary>
 39    [JsonInclude]
 40    [MemoryPackOrder(3)]
 41    public Fixed64 OutTangent;
 42
 43    #endregion
 44
 45    #region Constructors
 46
 47    /// <summary>
 48    /// Creates a keyframe with a specified time and value.
 49    /// </summary>
 50    public FixedCurveKey(Fixed64 time, Fixed64 value)
 651        : this(time, value, Fixed64.Zero, Fixed64.Zero) { }
 52
 53    /// <summary>
 54    /// Creates a keyframe with a specified time and value, using integer parameters for convenience.
 55    /// </summary>
 56    public FixedCurveKey(int time, int value)
 7457        : this(new(time), new(value), Fixed64.Zero, Fixed64.Zero) { }
 58
 59    /// <summary>
 60    /// Creates a keyframe with optional tangents for cubic interpolation.
 61    /// </summary>
 62    [JsonConstructor]
 63    public FixedCurveKey(Fixed64 time, Fixed64 value, Fixed64 inTangent, Fixed64 outTangent)
 64    {
 4965        Time = time;
 4966        Value = value;
 4967        InTangent = inTangent;
 4968        OutTangent = outTangent;
 4969    }
 70
 71    /// <summary>
 72    /// Creates a keyframe with optional tangents for cubic interpolation, using integer parameters for convenience.
 73    /// </summary>
 74    public FixedCurveKey(int time, int value, int inTangent, int outTangent)
 475        : this(new Fixed64(time), new Fixed64(value), new Fixed64(inTangent), new Fixed64(outTangent)) { }
 76
 77    /// <summary>
 78    /// Creates a keyframe with a specified time and value.
 79    /// </summary>
 80    /// <remarks>
 81    /// Values are converted through <see cref="Fixed64.FromDouble(double)"/>, so non-finite values
 82    /// throw <see cref="ArgumentOutOfRangeException"/> and finite values outside the Q32.32 range
 83    /// throw <see cref="OverflowException"/>.
 84    /// </remarks>
 85    public static FixedCurveKey FromDouble(double time, double value) =>
 286        new(Fixed64.FromDouble(time), Fixed64.FromDouble(value));
 87
 88    /// <summary>
 89    /// Creates a keyframe with optional tangents for cubic interpolation.
 90    /// </summary>
 91    /// <remarks>
 92    /// Values are converted through <see cref="Fixed64.FromDouble(double)"/>, so non-finite values
 93    /// throw <see cref="ArgumentOutOfRangeException"/> and finite values outside the Q32.32 range
 94    /// throw <see cref="OverflowException"/>.
 95    /// </remarks>
 96    public static FixedCurveKey FromDouble(double time, double value, double inTangent, double outTangent) =>
 397        new(Fixed64.FromDouble(time),
 398            Fixed64.FromDouble(value),
 399            Fixed64.FromDouble(inTangent),
 3100            Fixed64.FromDouble(outTangent));
 101
 102    #endregion
 103
 104    #region Equality
 105
 106    /// <inheritdoc/>
 107    public bool Equals(FixedCurveKey other) =>
 19108        Time == other.Time &&
 19109        Value == other.Value &&
 19110        InTangent == other.InTangent &&
 19111        OutTangent == other.OutTangent;
 112
 113    /// <inheritdoc/>
 2114    public override bool Equals(object? obj) => obj is FixedCurveKey other && Equals(other);
 115
 116    /// <inheritdoc/>
 117    public override int GetHashCode()
 118    {
 119        unchecked
 120        {
 7121            int hash = 17;
 7122            hash = (hash * 31) + Time.GetHashCode();
 7123            hash = (hash * 31) + Value.GetHashCode();
 7124            hash = (hash * 31) + InTangent.GetHashCode();
 7125            hash = (hash * 31) + OutTangent.GetHashCode();
 7126            return hash;
 127        }
 128    }
 129
 130    /// <summary>
 131    /// Determines whether two FixedCurveKey instances are equal.
 132    /// </summary>
 18133    public static bool operator ==(FixedCurveKey left, FixedCurveKey right) => left.Equals(right);
 134
 135    /// <summary>
 136    /// Determines whether two FixedCurveKey instances are not equal.
 137    /// </summary>
 17138    public static bool operator !=(FixedCurveKey left, FixedCurveKey right) => !(left == right);
 139
 140    #endregion
 141}