Delaunay Triangulation - currently with DelaunatorSharp - VoronoiDiagram work in progress
This commit is contained in:
@@ -1,19 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Avalonia.Media;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace DelauneyTriangulation.Models;
|
||||
|
||||
public static class Geometries
|
||||
{
|
||||
public sealed class Point(double x, double y, double z = 3)
|
||||
public sealed class Point(double x, double y, double r = 3, Color? color = null)
|
||||
{
|
||||
public double X { get; } = x;
|
||||
public double Y { get; } = y;
|
||||
public double R { get; } = z;
|
||||
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 Top => Y - R;
|
||||
public double Size => 2 * R;
|
||||
}
|
||||
|
||||
public sealed class PointComparer : IComparer<Point>
|
||||
{
|
||||
public static readonly PointComparer Instance = new();
|
||||
|
||||
public int Compare(Point? a, Point? b)
|
||||
{
|
||||
if (ReferenceEquals(a, b)) return 0;
|
||||
if (a is null) return -1;
|
||||
if (b is null) return 1;
|
||||
|
||||
int c = a.X.CompareTo(b.X);
|
||||
if (c != 0) return c;
|
||||
|
||||
c = a.Y.CompareTo(b.Y);
|
||||
if (c != 0) return c;
|
||||
|
||||
return a.R.CompareTo(b.R);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Edge(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
@@ -23,7 +48,7 @@ public static class Geometries
|
||||
public double Y2 { get; } = y2;
|
||||
|
||||
public Avalonia.Point Start => new(X1, Y1);
|
||||
public Avalonia.Point End => new(X2, Y2);
|
||||
public Avalonia.Point End => new(X2, Y2);
|
||||
}
|
||||
|
||||
public sealed class Circle(double x, double y, double r)
|
||||
@@ -33,7 +58,16 @@ public static class Geometries
|
||||
public double R { get; } = r;
|
||||
|
||||
public double Left => X - R;
|
||||
public double Top => Y - R;
|
||||
public double Top => Y - R;
|
||||
public double Diameter => 2 * R;
|
||||
}
|
||||
|
||||
public sealed class Triangle(Point p1, Point p2, Point p3)
|
||||
{
|
||||
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 ];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user