using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
namespace UnityEngine.Splines
{
///
/// Defines an interpolation ratio 't' for a Data Point.
///
public interface IDataPoint
{
///
/// The interpolation ratio. How this value is interpreted depends on the specified
/// by .
///
float Index { get; set; }
}
///
/// A pair containing an interpolation ratio and {TDataType} value.
///
/// The type of data this data point stores.
[Serializable]
public struct DataPoint : IComparable>, IComparable, IDataPoint
{
[FormerlySerializedAs("m_Time")]
[SerializeField]
float m_Index;
[SerializeField]
TDataType m_Value;
///
/// The interpolation ratio relative to a spline. How this value is interpolated depends on the
/// specified by .
///
public float Index
{
get => m_Index;
set => m_Index = value;
}
///
/// A value to store with this Data Point.
///
public TDataType Value
{
get => m_Value;
set => m_Value = value;
}
///
/// Create a new Data Point with interpolation ratio and value.
///
/// Interpolation ratio.
/// The value to store.
public DataPoint(float index, TDataType value)
{
m_Index = index;
m_Value = value;
}
///
/// Compare DataPoint values.
///
/// The DataPoint to compare against.
/// An integer less than 0 if other.Key is greater than , 0 if key values are equal, and greater
/// than 0 when other.Key is less than .
public int CompareTo(DataPoint other) => Index.CompareTo(other.Index);
///
/// Compare DataPoint values.
///
/// An interpolation ratio to compare against.
/// An integer less than 0 if other.Key is greater than , 0 if key values are equal, and greater
/// than 0 when other.Key is less than .
public int CompareTo(float other) => Index.CompareTo(other);
///
/// A summary of the DataPoint time and value.
///
/// A summary of the DataPoint key and value.
public override string ToString() => $"{Index} {Value}";
}
class DataPointComparer : IComparer where T : IDataPoint
{
public int Compare(T x, T y)
{
return x.Index.CompareTo(y.Index);
}
}
}