Decided on architecture
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.
This commit is contained in:
parent
38932e64ac
commit
ad0599f481
14 changed files with 848 additions and 75 deletions
57
intersections/IntersectionLine2ToLine2.cs
Normal file
57
intersections/IntersectionLine2ToLine2.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection between two two-dimensional lines.
|
||||||
|
/// </summary>
|
||||||
|
public class IntersectionLine2ToLine2d
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Possible statuses the intersection can be.
|
||||||
|
/// </summary>
|
||||||
|
public enum Statuses
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection is valid.
|
||||||
|
/// </summary>
|
||||||
|
SUCCESS,
|
||||||
|
/// <summary>
|
||||||
|
/// The two lines are parallel.
|
||||||
|
/// </summary>
|
||||||
|
PARALLEL,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// First of the intersecting lines.
|
||||||
|
/// </summary>
|
||||||
|
public Line2d Line1 { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The second intersecting line.
|
||||||
|
/// </summary>
|
||||||
|
public Line2d Line2 { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status of the intersection.
|
||||||
|
/// </summary>
|
||||||
|
public Statuses Status { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The point of the intersection between the two lines.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2d? Result { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for Line2d to Line2d intersection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="line1">First of the intersecting lines.</param>
|
||||||
|
/// <param name="line1">Second of the intersecting lines.</param>
|
||||||
|
public IntersectionLine2ToLine2d(Line2d line1, Line2d line2)
|
||||||
|
{
|
||||||
|
Line1 = line1;
|
||||||
|
Line2 = line2;
|
||||||
|
|
||||||
|
// Process the intersection
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
intersections/IntersectionLine2ToLineSegment2.cs
Normal file
61
intersections/IntersectionLine2ToLineSegment2.cs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection between a line and a line segment
|
||||||
|
/// </summary>
|
||||||
|
public class IntersectionLine2ToLineSegment2d
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Possible statuses the intersection can be.
|
||||||
|
/// </summary>
|
||||||
|
public enum Statuses
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection is valid.
|
||||||
|
/// </summary>
|
||||||
|
SUCCESS,
|
||||||
|
/// <summary>
|
||||||
|
/// The two lines are parallel.
|
||||||
|
/// </summary>
|
||||||
|
PARALLEL,
|
||||||
|
/// <summary>
|
||||||
|
/// The intersection would happen if the intersectors were unbounded, but not inside the bounds.
|
||||||
|
/// </summary>
|
||||||
|
OUTOFBOUNDS,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The intersecting line.
|
||||||
|
/// </summary>
|
||||||
|
public Line2d Line { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The intersecting line segment.
|
||||||
|
/// </summary>
|
||||||
|
public LineSegment2d LineSegment { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status of the intersection.
|
||||||
|
/// </summary>
|
||||||
|
public Statuses Status { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The point of the intersection between the line and line segment.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2d? Result { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for Line2d to LinearSegment2d intersection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="line">The intersecting line.</param>
|
||||||
|
/// <param name="lineSegment">The intersecting lineSegment.</param>
|
||||||
|
public IntersectionLine2ToLineSegment2d(Line2d line, LineSegment2d lineSegment)
|
||||||
|
{
|
||||||
|
Line = line;
|
||||||
|
LineSegment = lineSegment;
|
||||||
|
|
||||||
|
// Process the intersection
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
intersections/IntersectionPlaneToLine3.cs
Normal file
57
intersections/IntersectionPlaneToLine3.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection between a plane and a line3, double precision.
|
||||||
|
/// </summary>
|
||||||
|
public class IntersectionPlaneToLine3d
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Possible statuses the intersection can be.
|
||||||
|
/// </summary>
|
||||||
|
public enum Statuses
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection is valid.
|
||||||
|
/// </summary>
|
||||||
|
SUCCESS,
|
||||||
|
/// <summary>
|
||||||
|
/// The line is on a plane coplanar to the intersection plane.
|
||||||
|
/// </summary>
|
||||||
|
COPLANAR,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The intersecting plane.
|
||||||
|
/// </summary>
|
||||||
|
public Planed Plane { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The intersecting line.
|
||||||
|
/// </summary>
|
||||||
|
public Line3d Line { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status of the intersection.
|
||||||
|
/// </summary>
|
||||||
|
public Statuses Status { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Point on the intersection of the plane and the line.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3d? Result { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for Planed to Line3d intersection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane">The intersecting plane.</param>
|
||||||
|
/// <param name="line">The intersecting line.</param>
|
||||||
|
public IntersectionPlaneToLine3d(Planed plane, Line3d line)
|
||||||
|
{
|
||||||
|
Plane = plane;
|
||||||
|
Line = line;
|
||||||
|
|
||||||
|
// Process the intersection
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
intersections/IntersectionPlaneToPlane.cs
Normal file
57
intersections/IntersectionPlaneToPlane.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection between two planes, double precision.
|
||||||
|
/// </summary>
|
||||||
|
public struct IntersectionPlaneToPlaned
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Possible statuses the intersection can be.
|
||||||
|
/// </summary>
|
||||||
|
public enum Statuses
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Intersection is valid.
|
||||||
|
/// </summary>
|
||||||
|
SUCCESS,
|
||||||
|
/// <summary>
|
||||||
|
/// The two intersecting planes are coplanar.
|
||||||
|
/// </summary>
|
||||||
|
COPLANAR,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// First of the intersecting planes.
|
||||||
|
/// </summary>
|
||||||
|
public Planed Plane1 { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The second intersecting plane.
|
||||||
|
/// </summary>
|
||||||
|
public Planed Plane2 { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status of the intersection.
|
||||||
|
/// </summary>
|
||||||
|
public Statuses Status { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resulting intersection line between the two planes.
|
||||||
|
/// </summary>
|
||||||
|
public Line3d? Result { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for Planed to Planed intersection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plane1">First of the intersecting planes.</param>
|
||||||
|
/// <param name="plane2">Second of the intersecting planes.</param>
|
||||||
|
public IntersectionPlaneToPlaned(Planed plane1, Planed plane2)
|
||||||
|
{
|
||||||
|
Plane1 = plane1;
|
||||||
|
Plane2 = plane2;
|
||||||
|
|
||||||
|
// Process the intersection.
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
135
structs/Line2.cs
Normal file
135
structs/Line2.cs
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
namespace GeometriCS.structs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A line through a two-dimensional vector space.
|
|
||||||
/// </summary>
|
|
||||||
public class Line2d
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A point that lies on the line.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2d PointOnLine { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Direction vector, along which all the points on the line lie.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2d Direction { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor for the line.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pointOnLine">Point that lies on the line.</param>
|
|
||||||
/// <param name="direction">Direction vector on the line.</param>
|
|
||||||
public Line2d(Vector2d pointOnLine, Vector2d direction)
|
|
||||||
{
|
|
||||||
PointOnLine = pointOnLine;
|
|
||||||
Direction = direction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
103
structs/Line3.cs
Normal file
103
structs/Line3.cs
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A line through the R cubed space with double precision.
|
||||||
|
/// </summary>
|
||||||
|
public class Line3d
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A point that lies on the line.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3d PointOnLine
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Direction vector, along which all the points on the line lie.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3d Direction
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for the line.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pointOnLine">Point that lies on the line.</param>
|
||||||
|
/// <param name="direction">Direction vector on the line.</param>
|
||||||
|
public Line3d(Vector3d pointOnLine, Vector3d direction)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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 any two different points on one line will also be on the other line. <c>false</c></returns>
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is Line3d asLn)
|
||||||
|
{
|
||||||
|
return this == asLn;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deep copy the line.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Deep copy of the line.</returns>
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are the lines equal?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First line.</param>
|
||||||
|
/// <param name="b">Second line.</param>
|
||||||
|
/// <returns><c>true</c> if any two different points on one line will also be on the other line. <c>false</c></returns>
|
||||||
|
public static bool operator ==(Line3d a, Line3d b)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are the lines different?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First line.</param>
|
||||||
|
/// <param name="b">Second line.</param>
|
||||||
|
/// <returns><c>true</c> If there exists a point p from all the points occupying line a and does not lie on line b. Otherwise <c>false</c>.</returns>
|
||||||
|
public static bool operator !=(Line3d a, Line3d b)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +0,0 @@
|
||||||
namespace GeometriCS.structs
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A line through the R cubed space with double precision.
|
|
||||||
/// </summary>
|
|
||||||
public class Line3d
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A point that lies on the line.
|
|
||||||
/// </summary>
|
|
||||||
public Vector3d PointOnLine { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Direction vector, along which all the points on the line lie.
|
|
||||||
/// </summary>
|
|
||||||
public Vector3d Direction { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Constructor for the line.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pointOnLine">Point that lies on the line.</param>
|
|
||||||
/// <param name="direction">Direction vector on the line.</param>
|
|
||||||
public Line3d(Vector3d pointOnLine, Vector3d direction)
|
|
||||||
{
|
|
||||||
PointOnLine = pointOnLine;
|
|
||||||
Direction = direction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
100
structs/LineSegment2.cs
Normal file
100
structs/LineSegment2.cs
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A segment of a two-dimensional line with double precision.
|
||||||
|
/// </summary>
|
||||||
|
public class LineSegment2d
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Start point of the line.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2d StartPoint { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// End point of the line.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2d EndPoint { get; set;}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A constructor for a 2d line segment.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startPoint">Point at which the line starts.</param>
|
||||||
|
/// <param name="endPoint">Point at which the line ends.</param>
|
||||||
|
public LineSegment2d(Vector2d startPoint, Vector2d endPoint)
|
||||||
|
{
|
||||||
|
StartPoint = (Vector2d) startPoint.Clone();
|
||||||
|
EndPoint = (Vector2d) 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 LineSegment2d 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 LineSegment2d(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 ==(LineSegment2d a, LineSegment2d 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 !=(LineSegment2d a, LineSegment2d b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
100
structs/LineSegment3.cs
Normal file
100
structs/LineSegment3.cs
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
153
structs/Plane.cs
Normal file
153
structs/Plane.cs
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
namespace GeometriCS
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Euclidean plane with double precision.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public class Planed
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A coefficient of the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public double Coeff_A { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// B coefficient of the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public double Coeff_B { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// C coefficient of the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public double Coeff_C { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// D coefficient of the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public double Coeff_D { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Normal vector to the plane.
|
||||||
|
/// </summary>
|
||||||
|
public Vector3d Normal => new Vector3d(Coeff_A, Coeff_B, Coeff_C);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Distance of the plane from origin along the normal vector. (signed!)
|
||||||
|
/// </summary>
|
||||||
|
public double Distance => -Coeff_D;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the plane from its normal and distance from origin.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="normal">Normal vector of the plane.</param>
|
||||||
|
/// <param name="distance">Distance from origin along normal.</param>
|
||||||
|
public Planed(Vector3d normal, double distance)
|
||||||
|
{
|
||||||
|
Coeff_A = normal.X;
|
||||||
|
Coeff_B = normal.Y;
|
||||||
|
Coeff_C = normal.Z;
|
||||||
|
Coeff_D = -distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Construct the plane from its normal and distance from origin.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="coeff_a">A coefficient of the plane.</param>
|
||||||
|
/// <param name="coeff_b">B coefficient of the plane.</param>
|
||||||
|
/// <param name="coeff_c">C coefficient of the plane.</param>
|
||||||
|
/// <param name="coeff_d">D coefficient of the plane.</param>
|
||||||
|
/// <remarks>
|
||||||
|
/// Plane follows the equation Ax + By + Cz - D = 0
|
||||||
|
/// </remarks>
|
||||||
|
public Planed(double coeff_a, double coeff_b, double coeff_c, double coeff_d)
|
||||||
|
{
|
||||||
|
Coeff_A = coeff_a;
|
||||||
|
Coeff_B = coeff_b;
|
||||||
|
Coeff_C = coeff_c;
|
||||||
|
Coeff_D = coeff_d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// String representation of the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>(normal vector, distance from origin)</returns>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"({Normal}, {Distance})";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Do the two objects represent the same plane?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Object to compare.</param>
|
||||||
|
/// <remarks>
|
||||||
|
/// If the planes have inverse normals and also inverse distances, they are considered not equal despite looking the same.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns><c>true</c> If the planes have the same coefficients. <c>false</c></returns>
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (obj is Planed asPlane)
|
||||||
|
{
|
||||||
|
return this == asPlane;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return HashCode.Combine(Coeff_A, Coeff_B, Coeff_C, Coeff_D);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deep copy the plane.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Deep copy of the plane.</returns>
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new Planed(Coeff_A, Coeff_B, Coeff_C, Coeff_D);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are the planes equal?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First plane.</param>
|
||||||
|
/// <param name="b">Second plane.</param>
|
||||||
|
/// <remarks>
|
||||||
|
/// If the planes have inverse normals and also inverse distances, they are considered not equal despite looking the same.
|
||||||
|
/// </remarks>
|
||||||
|
/// <returns><c>true</c> If the planes have the same coefficients. <c>false</c></returns>
|
||||||
|
public static bool operator ==(Planed a, Planed b)
|
||||||
|
{
|
||||||
|
return a.Coeff_A == b.Coeff_A && a.Coeff_B == b.Coeff_B &&
|
||||||
|
a.Coeff_C == b.Coeff_C && a.Coeff_D == b.Coeff_D;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are the planes different?
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="a">First plane.</param>
|
||||||
|
/// <param name="b">Second plane.</param>
|
||||||
|
/// <returns><c>true</c> If either the normals or the distance differs, otherwise <c>false</c>.</returns>
|
||||||
|
public static bool operator !=(Planed a, Planed b)
|
||||||
|
{
|
||||||
|
return !(a == b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,9 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
namespace GeometriCS
|
||||||
|
|
||||||
namespace GeometriCS.structs
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Two-dimensional vector with double precision.
|
/// Two-dimensional vector with double precision.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct Vector2d
|
public class Vector2d : ICloneable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Vector with 0 length.
|
/// Vector with 0 length.
|
||||||
|
@ -151,7 +149,7 @@ namespace GeometriCS.structs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Object to compare.</param>
|
/// <param name="obj">Object to compare.</param>
|
||||||
/// <returns><c>true</c> if the vectors are equal. Otherwise <c>false</c></returns>
|
/// <returns><c>true</c> if the vectors are equal. Otherwise <c>false</c></returns>
|
||||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
if (obj is Vector2d asVect)
|
if (obj is Vector2d asVect)
|
||||||
{
|
{
|
||||||
|
@ -168,6 +166,15 @@ namespace GeometriCS.structs
|
||||||
return HashCode.Combine(X, Y);
|
return HashCode.Combine(X, Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deep copy the vector.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Deep copy of the vector.</returns>
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new Vector2d(X, Y);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Negation of the vector.
|
/// Negation of the vector.
|
||||||
/// </summary>
|
/// </summary>
|
|
@ -1,11 +1,9 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
namespace GeometriCS
|
||||||
|
|
||||||
namespace GeometriCS.structs
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Three-dimensional vector with double precision.
|
/// Three-dimensional vector with double precision.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct Vector3d
|
public class Vector3d : ICloneable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Vector with 0 length.
|
/// Vector with 0 length.
|
||||||
|
@ -164,7 +162,7 @@ namespace GeometriCS.structs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Object to compare.</param>
|
/// <param name="obj">Object to compare.</param>
|
||||||
/// <returns><c>true</c> if the vectors are equal. Otherwise <c>false</c></returns>
|
/// <returns><c>true</c> if the vectors are equal. Otherwise <c>false</c></returns>
|
||||||
public override bool Equals([NotNullWhen(true)] object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
if (obj is Vector3d asVect)
|
if (obj is Vector3d asVect)
|
||||||
{
|
{
|
||||||
|
@ -181,6 +179,15 @@ namespace GeometriCS.structs
|
||||||
return HashCode.Combine(X, Y, Z);
|
return HashCode.Combine(X, Y, Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deep copy the vector.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Deep copy of the vector.</returns>
|
||||||
|
public object Clone()
|
||||||
|
{
|
||||||
|
return new Vector3d(X, Y, Z);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Negation of the vector.
|
/// Negation of the vector.
|
||||||
/// </summary>
|
/// </summary>
|
|
@ -1,10 +1,4 @@
|
||||||
using System;
|
namespace GeometriCS
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace GeometriCS
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Common utilities throughout the library.
|
/// Common utilities throughout the library.
|
||||||
|
|
Loading…
Reference in a new issue