diff --git a/Assets/Scripts/Common/MapSite.cs b/Assets/Scripts/Common/MapSite.cs index 6105d66..19ec58f 100644 --- a/Assets/Scripts/Common/MapSite.cs +++ b/Assets/Scripts/Common/MapSite.cs @@ -19,8 +19,8 @@ namespace Assets.Common public Point Center { get; set; } public bool IsOuter { get; set; } = false; public IEnumerable Boundary { get; set; } -// public IEnumerable<(int, int)> Edges => Boundary.Append(Boundary.First()).Zip(Boundary.RotateRight(), (a, b) => (a, b)); - public IEnumerable<(int, int)> Edges { get; set; } + public IEnumerable<(int, int)> Edges => Boundary.RotateRight().Zip(Boundary, (a, b) => (a, b)); +// public IEnumerable<(int, int)> Edges { get; set; } [field: NonSerialized] public Map Map { get; internal set; } diff --git a/Assets/Scripts/Common/PointUtils.cs b/Assets/Scripts/Common/PointUtils.cs index 162b055..bf66492 100644 --- a/Assets/Scripts/Common/PointUtils.cs +++ b/Assets/Scripts/Common/PointUtils.cs @@ -26,7 +26,12 @@ namespace Assets.Common a = a - center; b = b - center; - return Math.Acos((a.x*b.x+a.y*b.y)/(a.Length * b.Length)); + var dot = a.x * b.x + a.y * b.y; + var det = a.x * b.y - a.y * b.x; + + var angle = Math.Atan2(det, dot); + + return angle > 0 ? angle : 2*Math.PI + angle; } public static bool IsClockwise(Point center, Point a, Point b) diff --git a/Assets/Scripts/GridGenerator/VoronoiGridGenerator.cs b/Assets/Scripts/GridGenerator/VoronoiGridGenerator.cs index 179165c..7d7cce4 100644 --- a/Assets/Scripts/GridGenerator/VoronoiGridGenerator.cs +++ b/Assets/Scripts/GridGenerator/VoronoiGridGenerator.cs @@ -31,7 +31,7 @@ namespace Assets.GridGenerator result.Boundaries = (Graph)generator.Voronoi.Clone(); result.Sites = generator.Delaunay.Morph(s => { - var site = new MapSite(s.Point, ClockwiseVertices(generator.Voronoi, s.Vertices)) { Edges = s.Edges }; + var site = new MapSite(s.Point, ClockwiseVertices(generator.Voronoi, s.Vertices)); site.Metadata.SetProperty(VoronoiSiteProperty, s); @@ -64,7 +64,7 @@ namespace Assets.GridGenerator var enumerated = vertices as int[] ?? vertices.ToArray(); var center = PointUtils.Mean(enumerated.Select(n => graph[n])); - var reference = center + new Point(0, 1); + var reference = center + new Point(0, -100); return enumerated .Select(n => (Vertex: n, Point: graph[n])) diff --git a/Assets/Scripts/Utils/DebugUtils.cs b/Assets/Scripts/Utils/DebugUtils.cs index ba6d7c7..473efba 100644 --- a/Assets/Scripts/Utils/DebugUtils.cs +++ b/Assets/Scripts/Utils/DebugUtils.cs @@ -12,12 +12,12 @@ namespace Assets.Utils public static void DisplayGraphVertices(Graph graph, PointExtractor extractor, bool displayLabels = true) { var vertices = graph.Vertices.Select(p => extractor(p).ToVector3()); - var offset = Vector3.right; + var offset = Vector3.right + Vector3.up; foreach (var (v, i) in vertices.Select((x, i) => (x, i))) { Gizmos.DrawSphere(v, 1); - if (displayLabels) Handles.Label(v + offset, $"{i} at {v.x:F2}, {v.y:f2}"); + if (displayLabels) Handles.Label(v + offset, $"{i} at {v.x:F2}, {v.z:f2}"); } }