101 lines
3.6 KiB
C#
101 lines
3.6 KiB
C#
|
namespace GeometriCS
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// A segment of a line going through the R cubed space.
|
|||
|
/// </summary>
|
|||
|
public class LineSegment3d
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Point at which the line segment starts.
|
|||
|
/// </summary>
|
|||
|
public Vector3d StartPoint { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Point at which the line segment ends.
|
|||
|
/// </summary>
|
|||
|
public Vector3d EndPoint { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// A constructor for a segment of a line going throught the R cubed space.
|
|||
|
/// </summary>
|
|||
|
/// <param name="startPoint">Start point of the line.</param>
|
|||
|
/// <param name="endPoint">End point of the line.</param>
|
|||
|
public LineSegment3d(Vector3d startPoint, Vector3d endPoint)
|
|||
|
{
|
|||
|
StartPoint = (Vector3d) startPoint.Clone();
|
|||
|
EndPoint = (Vector3d) endPoint.Clone();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// String representation of the line segment.
|
|||
|
/// </summary>
|
|||
|
/// <returns>(stPt) -- (endPt)</returns>
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return $"({StartPoint} -- {EndPoint})";
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Do the two objects represent the same line segment?
|
|||
|
/// </summary>
|
|||
|
/// <param name="obj">Object to compare.</param>
|
|||
|
/// <remarks>
|
|||
|
/// 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.
|
|||
|
/// </remarks>
|
|||
|
/// <returns><c>true</c> if the lines have the same start and end points. Otherwise <c>false</c></returns>
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Deep copy the line.
|
|||
|
/// </summary>
|
|||
|
/// <returns>Deep copy of the line.</returns>
|
|||
|
public object Clone()
|
|||
|
{
|
|||
|
return new LineSegment3d(StartPoint, EndPoint);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Are the line segments equal?
|
|||
|
/// </summary>
|
|||
|
/// <param name="a">First line segment.</param>
|
|||
|
/// <param name="b">Second line segment.</param>
|
|||
|
/// <remarks>
|
|||
|
/// 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.
|
|||
|
/// </remarks>
|
|||
|
/// <returns><c>true</c> if the lines have the same start and end points. Otherwise <c>false</c></returns>
|
|||
|
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);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Are the line segments different?
|
|||
|
/// </summary>
|
|||
|
/// <param name="a">First line segment.</param>
|
|||
|
/// <param name="b">Second line segment.</param>
|
|||
|
/// <returns><c>true</c> If the line segments start or end points are different from the other ones. <c>false</c> If both are same, refer to <seealso cref="operator =="/> for details.</returns>
|
|||
|
public static bool operator !=(LineSegment3d a, LineSegment3d b)
|
|||
|
{
|
|||
|
return !(a == b);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|