GeometriCS/structs/Line2.cs

135 lines
4.4 KiB
C#
Raw Normal View History

namespace GeometriCS
{
/// <summary>
/// A line through a two-dimensional vector space.
/// </summary>
/// <remarks>
/// Line follows the equation Ax + By + C = 0
/// </remarks>
public class Line2d
{
/// <summary>
/// A coefficient of the line.
/// </summary>
/// <remarks>
/// Line follows the equation Ax + By + C = 0
/// </remarks>
public double Coeff_A { get; set; }
/// <summary>
/// B coefficient of the line.
/// </summary>
/// <remarks>
/// Line follows the equation Ax + By + C = 0
/// </remarks>
public double Coeff_B { get; set; }
/// <summary>
/// C coefficient of the line.
/// </summary>
/// <remarks>
/// Line follows the equation Ax + By + C = 0
/// </remarks>
public double Coeff_C { get; set; }
/// <summary>
/// Construct a line from a point on the line and a direction vector.
/// </summary>
/// <param name="pointOnLine">Point that lies on the line.</param>
/// <param name="direction">Direction the line takes from the point.</param>
/// <returns>Line2d passing throught the given point with the given direction.</returns>
public static Line2d FromPointAndDirection(Vector2d pointOnLine, Vector2d direction)
{
throw new NotImplementedException();
}
/// <summary>
/// Construct a line passing through two given points.
/// </summary>
/// <param name="firstPoint">First point that lies on the line.</param>
/// <param name="secondPoint">Other point that lies on the line.</param>
/// <returns>Line passing through the two points.</returns>
public static Line2d FromTwoPoints(Vector2d firstPoint, Vector2d secondPoint)
{
(double a, double b, double c) = Utils.Line2CoefficientsFromTwoPoints(firstPoint, secondPoint);
return new Line2d(a, b, c);
}
/// <summary>
/// Construct the line from its coefficients.
/// </summary>
/// <param name="coeff_A"></param>
/// <param name="coeff_B"></param>
/// <param name="coeff_C"></param>
public Line2d(double coeff_A, double coeff_B, double coeff_C)
{
Coeff_A = coeff_A;
Coeff_B = coeff_B;
Coeff_C = coeff_C;
}
/// <summary>
/// String representation of the line.
/// </summary>
/// <returns></returns>
public override string ToString()
{
throw new NotImplementedException();
}
/// <summary>
/// Do the two objects represent the same line?
/// </summary>
/// <param name="obj">Object to compare.</param>
/// <remarks>
/// <returns><c>true</c> if the lines have the same coefficients. Otherwise <c>false</c></returns>
public override bool Equals(object? obj)
{
if (obj is Line2d asLn)
{
return this == asLn;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return HashCode.Combine(Coeff_A, Coeff_B, Coeff_C);
}
/// <summary>
/// Deep copy the line.
/// </summary>
/// <returns>Deep copy of the line.</returns>
public object Clone()
{
return new Line2d(Coeff_A, Coeff_B, Coeff_C);
}
/// <summary>
/// Are the lines equal?
/// </summary>
/// <param name="a">First line.</param>
/// <param name="b">Second line.</param>
/// <returns><c>true</c> if the lines have the same start and end points. Otherwise <c>false</c></returns>
public static bool operator ==(Line2d a, Line2d b)
{
return Utils.DoubleEquals(a.Coeff_A, b.Coeff_A) && Utils.DoubleEquals(a.Coeff_B, b.Coeff_B) && Utils.DoubleEquals(a.Coeff_C, b.Coeff_C);
}
/// <summary>
/// Are the lines different?
/// </summary>
/// <param name="a">First line.</param>
/// <param name="b">Second line.</param>
/// <returns><c>true</c> If the lines have the same coefficients. Otherwise <c>false</c>.</returns>
public static bool operator !=(Line2d a, Line2d b)
{
return !(a == b);
}
}
}