MapSet.NearestLinedefRange using a blockmap now takes into account that the maxrange could be bigger than the blockmap block size

This commit is contained in:
biwa 2020-11-15 13:59:04 +01:00 committed by spherallic
parent 27be4b6868
commit 87c30c0bf8
2 changed files with 45 additions and 8 deletions

View file

@ -196,6 +196,32 @@ namespace CodeImp.DoomBuilder.Map
return entries;
}
// This returns a range of blocks in a rectangle. Pretty much the same like GetSquareRange(RectangleF rect),
// just without the overhead to create a RectangleF first
public virtual List<BE> GetSquareRange(float left, float top, float width, float height)
{
// Calculate block coordinates
Point lt = GetBlockCoordinates(new Vector2D(left, top));
Point rb = GetBlockCoordinates(new Vector2D(left+width, top+height));
// Crop coordinates to range
lt = CropToRange(lt);
rb = CropToRange(rb);
// Go through the range to make a list
int entriescount = ((rb.X - lt.X) + 1) * ((rb.Y - lt.Y) + 1);
List<BE> entries = new List<BE>(entriescount);
for (int x = lt.X; x <= rb.X; x++)
{
for (int y = lt.Y; y <= rb.Y; y++)
{
entries.Add(blockmap[x, y]);
}
}
return entries;
}
// This returns all blocks along the given line
public virtual List<BE> GetLineBlocks(Vector2D v1, Vector2D v2)
{

View file

@ -3364,15 +3364,26 @@ namespace CodeImp.DoomBuilder.Map
float distance = float.MaxValue;
float maxrangesq = maxrange * maxrange;
HashSet<Linedef> processed = new HashSet<Linedef>();
HashSet<BlockEntry> blocks = new HashSet<BlockEntry>
List<BlockEntry> blocks;
// If the max range is lower or equal to the blockmap's block size we can take a shortcut got the the possible blocks.
// Otherwise get an rectangular range of blocks. This happens when maxrange is computed from low zoom levels
if (maxrange <= selectionmap.BlockSize)
{
selectionmap.GetBlockAt(pos),
selectionmap.GetBlockAt(new Vector2D(pos.x + maxrange, pos.y + maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x + maxrange, pos.y - maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x - maxrange, pos.y + maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x - maxrange, pos.y - maxrange))
};
blocks = new List<BlockEntry>
{
selectionmap.GetBlockAt(pos),
selectionmap.GetBlockAt(new Vector2D(pos.x + maxrange, pos.y + maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x + maxrange, pos.y - maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x - maxrange, pos.y + maxrange)),
selectionmap.GetBlockAt(new Vector2D(pos.x - maxrange, pos.y - maxrange))
};
}
else
{
blocks = selectionmap.GetSquareRange(pos.x - maxrange, pos.y - maxrange, maxrange * 2, maxrange * 2);
}
foreach(BlockEntry be in blocks)
{