using System; using UnityEngine; namespace Framework.Geometry.Lines { /// 2D infinite line public struct Line2 { /// A default line public static readonly Line2 Default = new Line2(Vector2.zero, Vector2.right); /// Offset of the line from the coordinate system's center public Vector2 Offset; /// Direction along which the line runs public Vector2 Direction; /// Initializes a new line /// /// X coordinate of the line's offset from the coordinate system's center /// /// /// Y coordinate of the line's offset from the coordinate system's center /// /// /// X coordinate of the direction along which the line runs /// /// /// Y coordinate of the direction along which the line runs /// public Line2(float offsetX, float offsetY, float directionX, float directionY) { this.Offset = new Vector2(offsetX, offsetY); this.Direction = new Vector2(directionX, directionY); } /// Initializes a new line /// Offset of the line from the coordinate system's center /// Direction along which the line runs public Line2(Vector2 offset, Vector2 direction) { this.Offset = offset; this.Direction = direction; } /// /// Determines whether this instance is identical to another instance /// /// Other instance of compare against /// True if both instances are identical public override bool Equals(object otherObject) { if(!(otherObject is Line2)) { return false; } Line2 other = (Line2)otherObject; return ( (this.Offset == other.Offset) && (this.Direction == other.Direction) ); } /// Returns a hash code for the instance /// The instance's hash code public override int GetHashCode() { return this.Offset.GetHashCode() ^ this.Direction.GetHashCode(); } } } // namespace Framework.Geometry.Lines