Moved to BowyerWatson Algorithm
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -12,14 +13,14 @@ public static class Geometries
|
||||
public double X { get; } = x;
|
||||
public double Y { get; } = y;
|
||||
public double R { get; } = r;
|
||||
|
||||
|
||||
public Color Color { get; set; } = color ?? new Color(255, 255, 255, 255);
|
||||
|
||||
|
||||
public double Left => X - R;
|
||||
public double Top => Y - R;
|
||||
public double Size => 2 * R;
|
||||
}
|
||||
|
||||
|
||||
public sealed class PointComparer : IComparer<Point>
|
||||
{
|
||||
public static readonly PointComparer Instance = new();
|
||||
@@ -46,20 +47,62 @@ public static class Geometries
|
||||
public double X2 { get; } = x2;
|
||||
public double Y1 { get; } = y1;
|
||||
public double Y2 { get; } = y2;
|
||||
|
||||
|
||||
public Avalonia.Point Start => new(X1, Y1);
|
||||
public Avalonia.Point End => new(X2, Y2);
|
||||
|
||||
private static bool Almost(double a, double b, double eps = 1e-9) => Math.Abs(a - b) <= eps;
|
||||
|
||||
public bool EqualsUndirected(Edge other, double eps = 1e-9)
|
||||
{
|
||||
bool same = Almost(X1, other.X1, eps) && Almost(Y1, other.Y1, eps) &&
|
||||
Almost(X2, other.X2, eps) && Almost(Y2, other.Y2, eps);
|
||||
|
||||
bool swapped = Almost(X1, other.X2, eps) && Almost(Y1, other.Y2, eps) &&
|
||||
Almost(X2, other.X1, eps) && Almost(Y2, other.Y1, eps);
|
||||
|
||||
return same || swapped;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Circle(double x, double y, double r)
|
||||
public sealed class Circle
|
||||
{
|
||||
public double X { get; } = x;
|
||||
public double Y { get; } = y;
|
||||
public double R { get; } = r;
|
||||
|
||||
public double X { get; }
|
||||
public double Y { get; }
|
||||
public double R { get; }
|
||||
|
||||
public double Left => X - R;
|
||||
public double Top => Y - R;
|
||||
public double Diameter => 2 * R;
|
||||
|
||||
public Circle(double x, double y, double r)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
R = r;
|
||||
}
|
||||
|
||||
public Circle(Point p1, Point p2, Point p3)
|
||||
{
|
||||
double x1 = p1.X, y1 = p1.Y;
|
||||
double x2 = p2.X, y2 = p2.Y;
|
||||
double x3 = p3.X, y3 = p3.Y;
|
||||
|
||||
var d = 2.0 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
|
||||
|
||||
if (Math.Abs(d) < 1e-12) throw new ArgumentException("Points are collinear; circumcircle undefined.");
|
||||
|
||||
var x1p = x1 * x1 + y1 * y1;
|
||||
var x2p = x2 * x2 + y2 * y2;
|
||||
var x3p = x3 * x3 + y3 * y3;
|
||||
|
||||
var ux = (x1p * (y2 - y3) + x2p * (y3 - y1) + x3p * (y1 - y2)) / d;
|
||||
var uy = (x1p * (x3 - x2) + x2p * (x1 - x3) + x3p * (x2 - x1)) / d;
|
||||
|
||||
X = ux;
|
||||
Y = uy;
|
||||
R = Math.Sqrt((ux - x1) * (ux - x1) + (uy - y1) * (uy - y1));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Triangle(Point p1, Point p2, Point p3)
|
||||
@@ -67,7 +110,7 @@ public static class Geometries
|
||||
public Avalonia.Point X { get; } = new(p1.X, p1.Y);
|
||||
public Avalonia.Point Y { get; } = new(p2.X, p2.Y);
|
||||
public Avalonia.Point Z { get; } = new(p3.X, p3.Y);
|
||||
|
||||
public IReadOnlyList<Avalonia.Point> Vertices => [ X, Y, Z ];
|
||||
|
||||
public IReadOnlyList<Avalonia.Point> Vertices => [X, Y, Z];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user