namespace GeometriCS { /// /// A segment of a line going through the R cubed space. /// public class LineSegment3d { /// /// Point at which the line segment starts. /// public Vector3d StartPoint { get; set; } /// /// Point at which the line segment ends. /// public Vector3d EndPoint { get; set; } /// /// A constructor for a segment of a line going throught the R cubed space. /// /// Start point of the line. /// End point of the line. public LineSegment3d(Vector3d startPoint, Vector3d endPoint) { StartPoint = (Vector3d) startPoint.Clone(); EndPoint = (Vector3d) endPoint.Clone(); } /// /// String representation of the line segment. /// /// (stPt) -- (endPt) public override string ToString() { return $"({StartPoint} -- {EndPoint})"; } /// /// Do the two objects represent the same line segment? /// /// Object to compare. /// /// If this lines start point is equal to the other lines end point, /// and this lines end point is equal to the other lines start point, the lines will be considered equal. /// /// true if the lines have the same start and end points. Otherwise false public override bool Equals(object? obj) { if (obj is LineSegment3d asLnSgmnt) { return this == asLnSgmnt; } else { return false; } } public override int GetHashCode() { return HashCode.Combine(StartPoint, EndPoint); } /// /// Deep copy the line. /// /// Deep copy of the line. public object Clone() { return new LineSegment3d(StartPoint, EndPoint); } /// /// Are the line segments equal? /// /// First line segment. /// Second line segment. /// /// If this lines start point is equal to the other lines end point, /// and this lines end point is equal to the other lines start point, the lines will be considered equal. /// /// true if the lines have the same start and end points. Otherwise false public static bool operator ==(LineSegment3d a, LineSegment3d b) { return (a.StartPoint == b.StartPoint && a.EndPoint == b.EndPoint) || (a.StartPoint == b.EndPoint && a.EndPoint == b.StartPoint); } /// /// Are the line segments different? /// /// First line segment. /// Second line segment. /// true If the line segments start or end points are different from the other ones. false If both are same, refer to for details. public static bool operator !=(LineSegment3d a, LineSegment3d b) { return !(a == b); } } }