From bb7857d2bb660c9c882dfd896854318aa84a819e Mon Sep 17 00:00:00 2001
From: biwa <6475593+biwa@users.noreply.github.com>
Date: Fri, 3 Mar 2023 09:53:08 +0100
Subject: [PATCH] Map Analysis Mode: fixed a problem where lines with
 fractional vertex positions could erroneously be reported as overlapping

---
 Source/Core/Geometry/Line2D.cs                   |  4 ++--
 .../ErrorChecks/CheckOverlappingLines.cs         | 16 +++++-----------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/Source/Core/Geometry/Line2D.cs b/Source/Core/Geometry/Line2D.cs
index b8cb9b67b..416574667 100755
--- a/Source/Core/Geometry/Line2D.cs
+++ b/Source/Core/Geometry/Line2D.cs
@@ -151,7 +151,7 @@ namespace CodeImp.DoomBuilder.Geometry
 			double div = (y4 - y3) * (v2.x - v1.x) - (x4 - x3) * (v2.y - v1.y);
 
 			// Can this be tested?
-			if(div != 0.0f)
+			if(div != 0.0)
 			{
 				// Calculate the intersection distance from the line
 				u_line = ((x4 - x3) * (v1.y - y3) - (y4 - y3) * (v1.x - x3)) / div;
@@ -160,7 +160,7 @@ namespace CodeImp.DoomBuilder.Geometry
 				u_ray = ((v2.x - v1.x) * (v1.y - y3) - (v2.y - v1.y) * (v1.x - x3)) / div;
 
 				// Return if intersecting
-				if(bounded && (u_ray < 0.0f || u_ray > 1.0f || u_line < 0.0f || u_line > 1.0f)) return false; //mxd
+				if(bounded && (u_ray < 0.0 || u_ray > 1.0 || u_line < 0.0 || u_line > 1.0)) return false; //mxd
 				return true;
 			}
 
diff --git a/Source/Plugins/BuilderModes/ErrorChecks/CheckOverlappingLines.cs b/Source/Plugins/BuilderModes/ErrorChecks/CheckOverlappingLines.cs
index ed2abbac1..6b2a666b3 100755
--- a/Source/Plugins/BuilderModes/ErrorChecks/CheckOverlappingLines.cs
+++ b/Source/Plugins/BuilderModes/ErrorChecks/CheckOverlappingLines.cs
@@ -63,9 +63,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
 				// Check if not already done
 				if(!donelines.ContainsKey(l))
 				{
-					// Temporary line
-					Line2D tl = l.Line;
-
 					// And go for all the linedefs that could overlap
 					List<BlockEntry> blocks = blockmap.GetLineBlocks(l.Start.Position, l.End.Position);
 					Dictionary<Linedef, Linedef> doneblocklines = new Dictionary<Linedef, Linedef>(blocks.Count * 3);
@@ -78,8 +75,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
 							{
 								double lu, du;
 
-								// Temporary line
-								Line2D td;
+								// Temporary lines
+								Line2D tl = l.Line;
+								Line2D td = d.Line;
 
 								// If vertices are off-grid and far from the map's origin the calculation of the intersection can go wrong because of rounding errors.
 								// So if any vertex is off-grid we'll to the calculations with lines that are closer to the origin. This is pretty ugly :(
@@ -98,8 +96,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
 
 									// Create the two lines to check. this takes the original values, applies the offset, then rounds them to the map format's precision
 									tl = new Line2D(
-										new Vector2D(Math.Round(tl.v1.x - offset.x, General.Map.FormatInterface.VertexDecimals), Math.Round(tl.v1.y - offset.y, General.Map.FormatInterface.VertexDecimals)),
-										new Vector2D(Math.Round(tl.v2.x - offset.x, General.Map.FormatInterface.VertexDecimals), Math.Round(tl.v2.y - offset.y, General.Map.FormatInterface.VertexDecimals))
+										new Vector2D(Math.Round(l.Line.v1.x - offset.x, General.Map.FormatInterface.VertexDecimals), Math.Round(l.Line.v1.y - offset.y, General.Map.FormatInterface.VertexDecimals)),
+										new Vector2D(Math.Round(l.Line.v2.x - offset.x, General.Map.FormatInterface.VertexDecimals), Math.Round(l.Line.v2.y - offset.y, General.Map.FormatInterface.VertexDecimals))
 									);
 
 									td = new Line2D(
@@ -107,10 +105,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
 										new Vector2D(Math.Round(d.Line.v2.x - offset.x, General.Map.FormatInterface.VertexDecimals), Math.Round(d.Line.v2.y - offset.y, General.Map.FormatInterface.VertexDecimals))
 									);
 								}
-								else
-								{
-									td = d.Line;
-								}
 								
 								//mxd. This can also happen. I suppose. Some people manage to do this. I dunno how, but they do...
 								if((l.Start.Position == d.Start.Position && l.End.Position == d.End.Position)
-- 
GitLab