From e21b756f29ae356b069871f9046d4ece66468c0f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 24 Jul 2018 15:00:35 +0300 Subject: [PATCH] Fixed invalid left/right normal errors during level generation (I think). The voronoi cell generation logic ignored zero-length edges, but it was possible for an edge to be so short that the distance from the adjacent edge to the center of the short edge rounded down to zero in GenerateWallShapes. --- .../Source/Map/Levels/CaveGenerator.cs | 2 +- .../Source/Map/Levels/VoronoiElements.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs index 1e08742a2..7325965ff 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/CaveGenerator.cs @@ -183,7 +183,7 @@ namespace Barotrauma foreach (GraphEdge ge in graphEdges) { - if (ge.point1 == ge.point2) continue; + if (Vector2.DistanceSquared(ge.point1, ge.point2) < 0.001f) continue; for (int i = 0; i < 2; i++) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs index 22641dfb4..27ee2e4a7 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/VoronoiElements.cs @@ -211,16 +211,16 @@ namespace Voronoi2 public VoronoiCell AdjacentCell(VoronoiCell cell) { - if (cell1==cell) + if (cell1 == cell) { return cell2; } - else if (cell2==cell) + else if (cell2 == cell) { return cell1; } - return null; + return null; } /// @@ -239,6 +239,11 @@ namespace Voronoi2 return normal; } + + public override string ToString() + { + return "GraphEdge (" + point1.ToString() + ", " + point2.ToString() + ")"; + } } // للترتيب