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 b0b1693a62
commit 0eee76393b
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 HashSet<BE> GetSquareRange(double left, double top, double width, double 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);
HashSet<BE> entries = new HashSet<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

@ -3391,15 +3391,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>
HashSet<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 HashSet<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)
{