Zdeněk Borovec
ad0599f481
A sizeable commit, I know, but I wanted to try and write a few aspects before deciding to settle on a system. This one seems to be fine so far. But I would still not rely on it not changing.
135 lines
4.4 KiB
C#
135 lines
4.4 KiB
C#
using System.Runtime.CompilerServices;
|
|
|
|
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)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|