using System; using System.Diagnostics; namespace Unity.CodeEditor.Rendering { /// /// Represents information about a character hit within a glyph run. /// /// /// The CharacterHit structure provides information about the index of the first /// character that got hit as well as information about leading or trailing edge. /// [DebuggerDisplay("CharacterHit({FirstCharacterIndex}, {TrailingLength})")] internal readonly struct CharacterHit : IEquatable { /// /// Initializes a new instance of the structure. /// /// Index of the first character that got hit. /// In the case of a leading edge, this value is 0. In the case of a trailing edge, /// this value is the number of code points until the next valid caret position. [DebuggerStepThrough] internal CharacterHit(int firstCharacterIndex, int trailingLength = 0) { FirstCharacterIndex = firstCharacterIndex; TrailingLength = trailingLength; } /// /// Gets the index of the first character that got hit. /// internal int FirstCharacterIndex { get; } /// /// Gets the trailing length value for the character that got hit. /// internal int TrailingLength { get; } public bool Equals(CharacterHit other) { return FirstCharacterIndex == other.FirstCharacterIndex && TrailingLength == other.TrailingLength; } public override bool Equals(object obj) { return obj is CharacterHit other && Equals(other); } public override int GetHashCode() { unchecked { return FirstCharacterIndex * 397 ^ TrailingLength; } } public static bool operator ==(CharacterHit left, CharacterHit right) { return left.Equals(right); } public static bool operator !=(CharacterHit left, CharacterHit right) { return !left.Equals(right); } } }