using System; namespace UnityEngine.Splines { /// /// Provides a tuple to define a couple (Spline index, Knot index) that identifies a particular knot on a spline. /// This tuple is used by to maintain links between knots. /// [Serializable] public struct SplineKnotIndex : IEquatable { /// /// Represents the default value for an invalid index. /// public static SplineKnotIndex Invalid = new SplineKnotIndex(-1, -1); /// /// The index of the spline in the . /// public int Spline; /// /// The index of the knot in the spline. /// public int Knot; /// /// Creates a new SplineKnotIndex to reference a knot. /// /// The spline index. /// The knot index. public SplineKnotIndex(int spline, int knot) { Spline = spline; Knot = knot; } /// /// Checks if two indices are equal. /// /// The first index. /// The second index. /// Returns true if the indices reference the same knot on the same spline, false otherwise. public static bool operator ==(SplineKnotIndex indexA, SplineKnotIndex indexB) { return indexA.Equals(indexB); } /// /// Checks if two indices are not equal. /// /// The first index. /// The second index. /// Returns false if the indices reference the same knot on the same spline, true otherwise. public static bool operator !=(SplineKnotIndex indexA, SplineKnotIndex indexB) { return !indexA.Equals(indexB); } /// /// Checks if two indices are equal. /// /// The index to compare against. /// Returns true if the indices reference the same knot on the same spline, false otherwise. public bool Equals(SplineKnotIndex otherIndex) { return Spline == otherIndex.Spline && Knot == otherIndex.Knot; } /// /// Checks if two indices are equal. /// /// The object to compare against. /// Returns true if the object is a SplineKnotIndex and the indices reference the same knot on the same spline, false otherwise. public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; return obj is SplineKnotIndex other && Equals(other); } /// /// Checks if an index is greater than or equal to 0. /// /// Returns true if the indices are greater than or equal to 0, false otherwise. public bool IsValid() { return Spline >= 0 && Knot >= 0; } /// /// Gets a hash code for this SplineKnotIndex. /// /// A hash code for the SplineKnotIndex. public override int GetHashCode() { unchecked { return (Spline * 397) ^ Knot; } } /// /// Gets a string representation of a SplineKnotIndex. /// /// A string representation of this SplineKnotIndex. public override string ToString() => $"{{{Spline}, {Knot}}}"; } }