Add BoundingBox2.Include() from Quadtree.IncludeInBoundingBox()
This commit is contained in:
parent
e84746fab0
commit
504ec41ebc
@ -57,5 +57,25 @@ namespace Quadtree
|
|||||||
Max.X += expansion;
|
Max.X += expansion;
|
||||||
Max.Y += expansion;
|
Max.Y += expansion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Include(Vector2 position)
|
||||||
|
{
|
||||||
|
if (Min.X > position.X)
|
||||||
|
{
|
||||||
|
Min.X = position.X;
|
||||||
|
}
|
||||||
|
else if (Max.X < position.X)
|
||||||
|
{
|
||||||
|
Max.X = position.X;
|
||||||
|
}
|
||||||
|
if (Min.Y > position.Y)
|
||||||
|
{
|
||||||
|
Min.Y = position.Y;
|
||||||
|
}
|
||||||
|
else if (Max.Y < position.Y)
|
||||||
|
{
|
||||||
|
Max.Y = position.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
Quadtree.cs
26
Quadtree.cs
@ -234,7 +234,7 @@ namespace Quadtree
|
|||||||
item.Next = _vertices[0].FirstChildIndex;
|
item.Next = _vertices[0].FirstChildIndex;
|
||||||
_items[itemIndex] = item;
|
_items[itemIndex] = item;
|
||||||
_vertices[0] = new QuadtreeVertex(itemIndex, _vertices[0].ChildCount + 1);
|
_vertices[0] = new QuadtreeVertex(itemIndex, _vertices[0].ChildCount + 1);
|
||||||
IncludeInBoundingBox(ref _rootBoundingBox, position);
|
_rootBoundingBox.Include(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,29 +416,5 @@ namespace Quadtree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Slightly more efficient implementation of BoundingBox.Include(), assuming that Min.X <= Max.X,
|
|
||||||
/// Min.Z <= Max.Z, and all Y = 0.
|
|
||||||
/// </summary>
|
|
||||||
private void IncludeInBoundingBox(ref BoundingBox2 boundingBox, Vector2 position)
|
|
||||||
{
|
|
||||||
if (boundingBox.Min.X > position.X)
|
|
||||||
{
|
|
||||||
boundingBox.Min.X = position.X;
|
|
||||||
}
|
|
||||||
else if (boundingBox.Max.X < position.X)
|
|
||||||
{
|
|
||||||
boundingBox.Max.X = position.X;
|
|
||||||
}
|
|
||||||
if (boundingBox.Min.Y > position.Y)
|
|
||||||
{
|
|
||||||
boundingBox.Min.Y = position.Y;
|
|
||||||
}
|
|
||||||
else if (boundingBox.Max.Y < position.Y)
|
|
||||||
{
|
|
||||||
boundingBox.Max.Y = position.Y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user