2014-02-07 09:10:55 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
|
|
|
|
[ErrorChecker("Check overlapping vertices", true, 500)]
|
|
|
|
|
public class CheckOverlappingVertices : ErrorChecker
|
|
|
|
|
{
|
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
|
|
private const int PROGRESS_STEP = 100;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor / Destructor
|
|
|
|
|
|
|
|
|
|
// Constructor
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public CheckOverlappingVertices()
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
// Total progress is done when all lines are checked
|
2014-05-27 09:22:44 +00:00
|
|
|
|
SetTotalProgress(General.Map.Map.Vertices.Count / PROGRESS_STEP);
|
2014-02-07 09:10:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
|
|
// This runs the check
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override void Run()
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
BlockMap<BlockEntry> blockmap = BuilderPlug.Me.ErrorCheckForm.BlockMap;
|
|
|
|
|
Dictionary<Vertex, List<Vertex>> doneverts = new Dictionary<Vertex, List<Vertex>>();
|
|
|
|
|
int progress = 0;
|
|
|
|
|
int stepprogress = 0;
|
|
|
|
|
|
|
|
|
|
// Go for all the verts
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Vertex v in General.Map.Map.Vertices)
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
BlockEntry block = blockmap.GetBlockAt(v.Position);
|
|
|
|
|
|
|
|
|
|
// Go for all the linedefs that our vertex could overlap
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Linedef l in block.Lines)
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
if(v == l.Start || v == l.End) continue;
|
2020-05-22 20:30:32 +00:00
|
|
|
|
if(Math.Round(l.Line.GetDistanceToLine(v.Position, true), 3) == 0)
|
2014-02-07 09:10:55 +00:00
|
|
|
|
SubmitResult(new ResultVertexOverlappingLine(v, l));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Go for all the verts that our vertex could overlap
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Vertex bv in block.Vertices)
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
if(bv == v || (doneverts.ContainsKey(v) && doneverts[v].Contains(bv)) || (doneverts.ContainsKey(bv) && doneverts[bv].Contains(v))) continue;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(bv.Position == v.Position) SubmitResult(new ResultVertexOverlappingVertex(v, bv));
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(!doneverts.ContainsKey(v)) doneverts.Add(v, new List<Vertex>());
|
2014-02-07 09:10:55 +00:00
|
|
|
|
doneverts[v].Add(bv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle thread interruption
|
|
|
|
|
try { Thread.Sleep(0); }
|
|
|
|
|
catch(ThreadInterruptedException) { return; }
|
|
|
|
|
|
|
|
|
|
// We are making progress!
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if((++progress / PROGRESS_STEP) > stepprogress)
|
|
|
|
|
{
|
2014-02-07 09:10:55 +00:00
|
|
|
|
stepprogress = (progress / PROGRESS_STEP);
|
|
|
|
|
AddProgress(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|