Extract Coordinate, IntegerRange and Coordinate3d to new AdventOfCode.HelperClasses project and refactor solution for modularity and type consistency
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
namespace AdventOfCode.HelperClasses;
|
||||
|
||||
public record Coordinate(long X, long Y)
|
||||
{
|
||||
public double GetEuclidianDistance(Coordinate other) =>
|
||||
Math.Sqrt((X - other.X) * (X - other.X) + (Y - other.Y) * (Y - other.Y));
|
||||
|
||||
public static double GetEuclidianDistance(Coordinate a, Coordinate b) =>
|
||||
Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
|
||||
|
||||
public static Coordinate operator +(Coordinate left, Coordinate right) =>
|
||||
new(left.X + right.X, left.Y + right.Y);
|
||||
}
|
||||
|
||||
public record Coordinate3d(long X, long Y, long Z)
|
||||
{
|
||||
public double GetEuclidianDistance(Coordinate3d other) =>
|
||||
Math.Sqrt((X - other.X) * (X - other.X) + (Y - other.Y) * (Y - other.Y) + (Z - other.Z) * (Z - other.Z));
|
||||
|
||||
public static double GetEuclidianDistance(Coordinate3d a, Coordinate3d b) =>
|
||||
Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z));
|
||||
|
||||
public static Coordinate3d operator +(Coordinate3d left, Coordinate3d right) =>
|
||||
new(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
|
||||
}
|
||||
Reference in New Issue
Block a user