Map Analysis Mode: fixed a problem where lines with fractional vertex positions could erroneously be reported as overlapping

This commit is contained in:
biwa 2023-03-03 09:53:08 +01:00
parent 1766b71cb0
commit bb7857d2bb
2 changed files with 7 additions and 13 deletions

View file

@ -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;
}

View file

@ -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)