diff --git a/Assets/Map/LocationGenerator.cs b/Assets/Map/LocationGenerator.cs index 312a7b6..c327ff8 100644 --- a/Assets/Map/LocationGenerator.cs +++ b/Assets/Map/LocationGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using Random = System.Random; @@ -13,6 +14,7 @@ namespace Assets.Map public bool Done => _queue.Count == 0; public Graph Result => _graph; + private Dictionary> _blacklist = new Dictionary>(); public LocationGenerator(Graph graph, Random random = null) { @@ -57,10 +59,33 @@ namespace Assets.Map private void SetLocation(int vertex, Location location) { _graph.Vertices[vertex].Location = location; + location.Sites.Add(_graph.Vertices[vertex]); + + FixBoundaryPoints(vertex, location); + FixBoundaryEdges(vertex, location); foreach (var neighbour in _graph.Neighbours(vertex)) if (_graph.Vertices[neighbour].Location == null) _queue.Add((neighbour, location)); } + + private void FixBoundaryPoints(int vertex, Location location) + { + var a = location.BoundaryPoints; + var b = _graph.Vertices[vertex].Site.Vertices; + + if (!_blacklist.ContainsKey(location)) _blacklist[location] = new List(); + _blacklist[location].AddRange(a.Intersect(b)); + + location.BoundaryPoints = a.Union(b).Except(_blacklist[location]).ToList(); + } + + private void FixBoundaryEdges(int vertex, Location location) + { + var a = location.BoundaryEdges; + var b = _graph.Vertices[vertex].Site.Edges; + + location.BoundaryEdges = a.Union(b).Except(a.Intersect(b)).ToList(); + } } } \ No newline at end of file diff --git a/Assets/Map/LocationSite.cs b/Assets/Map/LocationSite.cs index 3891c43..551fa62 100644 --- a/Assets/Map/LocationSite.cs +++ b/Assets/Map/LocationSite.cs @@ -7,8 +7,10 @@ namespace Assets.Map { public class Location { - public List Sites; - public List BoundaryPoints; + public List Sites = new List(); + public List BoundaryPoints = new List(); + public List<(int, int)> BoundaryEdges = new List<(int, int)>(); + public LocationType Type; } diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 349e453..994522b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -248,30 +248,34 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 06dfaa94f8713f12fbe207b61b694c90, type: 3} m_Name: m_EditorClassIdentifier: - sections: - - name: - color: {r: 1, g: 0, b: 0, a: 1} + types: - name: color: {r: 0.18382645, g: 1, b: 0, a: 1} - name: color: {r: 1, g: 0, b: 0.74144936, a: 1} - name: color: {r: 0, g: 0.06698942, b: 1, a: 1} - - name: + - name: fucks color: {r: 0, g: 1, b: 0.94361734, a: 1} - seed: 120 - size: {x: 200, y: 200} + - name: + color: {r: 1, g: 0.008301804, b: 0, a: 1} + - name: + color: {r: 0.96469927, g: 1, b: 0, a: 1} + seed: 1090655872 + size: {x: 300, y: 300} debug: enabled: 1 displayPoints: 0 displayBeachLine: 0 - displayParabolas: 0 + displayParabolas: 1 displayVertices: 0 displayNeighbours: 0 - displayLabels: 0 + displayLabels: 1 displayHalfEdges: 0 displayEdges: 0 - displayLocations: 1 + displayLocations: 0 + displayLocationEdges: 1 + displayLocationPoints: 1 radius: 5 --- !u!33 &528199734 MeshFilter: diff --git a/Assets/Scripts/GraphGenerator.cs b/Assets/Scripts/GraphGenerator.cs index 1920a43..1bf45ea 100644 --- a/Assets/Scripts/GraphGenerator.cs +++ b/Assets/Scripts/GraphGenerator.cs @@ -24,6 +24,8 @@ namespace Assets public bool displayHalfEdges = false; public bool displayEdges = true; public bool displayLocations = true; + public bool displayLocationEdges = true; + public bool displayLocationPoints = true; } [Serializable] @@ -204,7 +206,9 @@ namespace Assets } } - if (debug.displayLocations && LocationGenerator != null) + if (LocationGenerator == null) return; + + if (debug.displayLocations) { foreach (var location in LocationGenerator.Result.Vertices.Where(l => l.Location != null && l.Location != _locations[0])) { @@ -212,6 +216,30 @@ namespace Assets Gizmos.DrawSphere(location.Site.Point.ToVector3(), 2); } } + + if (debug.displayLocationPoints) + { + foreach (var location in _locations.Skip(1)) + { + Gizmos.color = location.Type.color; + foreach (var point in location.BoundaryPoints) + { + Gizmos.DrawSphere(VoronoiGenerator.Voronoi.Vertices[point].ToVector3(), 1); + } + } + } + + if (debug.displayLocationEdges) + { + foreach (var location in _locations.Skip(1)) + { + Gizmos.color = location.Type.color; + foreach (var (a, b) in location.BoundaryEdges) + { + Gizmos.DrawLine(VoronoiGenerator.Voronoi.Vertices[a].ToVector3(), VoronoiGenerator.Voronoi.Vertices[b].ToVector3()); + } + } + } } public void Rewind(float y) diff --git a/ProjectSettings/EditorSettings.asset b/ProjectSettings/EditorSettings.asset index f70eba0..8fc58dc 100644 --- a/ProjectSettings/EditorSettings.asset +++ b/ProjectSettings/EditorSettings.asset @@ -6,7 +6,7 @@ EditorSettings: serializedVersion: 8 m_ExternalVersionControlSupport: Visible Meta Files m_SerializationMode: 2 - m_LineEndingsForNewScripts: 2 + m_LineEndingsForNewScripts: 1 m_DefaultBehaviorMode: 1 m_PrefabRegularEnvironment: {fileID: 0} m_PrefabUIEnvironment: {fileID: 0}