remove linq methods from AABB calculation
parent
0952b77761
commit
d9bc05ee32
36
Bonk/AABB.cs
36
Bonk/AABB.cs
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using MoonTools.Core.Structs;
|
using MoonTools.Core.Structs;
|
||||||
|
|
||||||
|
@ -21,14 +20,39 @@ namespace MoonTools.Core.Bonk
|
||||||
|
|
||||||
public static AABB FromTransformedVertices(IEnumerable<Position2D> vertices, Transform2D transform)
|
public static AABB FromTransformedVertices(IEnumerable<Position2D> vertices, Transform2D transform)
|
||||||
{
|
{
|
||||||
var TransformedVertices = vertices.Select(vertex => Vector2.Transform(vertex, transform.TransformMatrix));
|
float minX = float.MaxValue;
|
||||||
|
float minY = float.MaxValue;
|
||||||
|
float maxX = float.MinValue;
|
||||||
|
float maxY = float.MinValue;
|
||||||
|
|
||||||
|
foreach (var vertex in vertices)
|
||||||
|
{
|
||||||
|
var transformedVertex = Vector2.Transform(vertex, transform.TransformMatrix);
|
||||||
|
|
||||||
|
if (transformedVertex.X < minX)
|
||||||
|
{
|
||||||
|
minX = transformedVertex.X;
|
||||||
|
}
|
||||||
|
if (transformedVertex.Y < minY)
|
||||||
|
{
|
||||||
|
minY = transformedVertex.Y;
|
||||||
|
}
|
||||||
|
if (transformedVertex.X > maxX)
|
||||||
|
{
|
||||||
|
maxX = transformedVertex.X;
|
||||||
|
}
|
||||||
|
if (transformedVertex.Y > maxY)
|
||||||
|
{
|
||||||
|
maxY = transformedVertex.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new AABB
|
return new AABB
|
||||||
{
|
{
|
||||||
MinX = TransformedVertices.Min(vertex => vertex.X),
|
MinX = minX,
|
||||||
MinY = TransformedVertices.Min(vertex => vertex.Y),
|
MinY = minY,
|
||||||
MaxX = TransformedVertices.Max(vertex => vertex.X),
|
MaxX = maxX,
|
||||||
MaxY = TransformedVertices.Max(vertex => vertex.Y)
|
MaxY = maxY
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ namespace MoonTools.Core.Bonk
|
||||||
/// <param name="transform2D"></param>
|
/// <param name="transform2D"></param>
|
||||||
public void Insert(T id, IShape2D shape, Transform2D transform2D)
|
public void Insert(T id, IShape2D shape, Transform2D transform2D)
|
||||||
{
|
{
|
||||||
if (shape == null) { throw new ArgumentNullException(nameof(shape)); }
|
|
||||||
|
|
||||||
var box = shape.AABB(transform2D);
|
var box = shape.AABB(transform2D);
|
||||||
var minHash = Hash(box.MinX, box.MinY);
|
var minHash = Hash(box.MinX, box.MinY);
|
||||||
var maxHash = Hash(box.MaxX, box.MaxY);
|
var maxHash = Hash(box.MaxX, box.MaxY);
|
||||||
|
@ -64,8 +62,6 @@ namespace MoonTools.Core.Bonk
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, IShape2D shape, Transform2D transform2D)
|
public IEnumerable<(T, IShape2D, Transform2D)> Retrieve(T id, IShape2D shape, Transform2D transform2D)
|
||||||
{
|
{
|
||||||
if (shape == null) { throw new ArgumentNullException(paramName: nameof(shape)); }
|
|
||||||
|
|
||||||
AABB box = shape.AABB(transform2D);
|
AABB box = shape.AABB(transform2D);
|
||||||
var minHash = Hash(box.MinX, box.MinY);
|
var minHash = Hash(box.MinX, box.MinY);
|
||||||
var maxHash = Hash(box.MaxX, box.MaxY);
|
var maxHash = Hash(box.MaxX, box.MaxY);
|
||||||
|
|
Loading…
Reference in New Issue