2019-09-06 08:11:58 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using MoonTools.Core.Structs;
|
|
|
|
|
|
|
|
namespace MoonTools.Core.Bonk
|
|
|
|
{
|
|
|
|
public struct AABB
|
|
|
|
{
|
2019-09-19 00:00:43 +00:00
|
|
|
public float MinX { get; private set; }
|
|
|
|
public float MinY { get; private set; }
|
|
|
|
public float MaxX { get; private set; }
|
|
|
|
public float MaxY { get; private set; }
|
2019-09-06 08:11:58 +00:00
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
public float Width { get { return MaxX - MinX; } }
|
|
|
|
public float Height { get { return MaxY - MinY; } }
|
2019-09-06 08:11:58 +00:00
|
|
|
|
2019-09-06 20:00:35 +00:00
|
|
|
public static AABB FromTransformedVertices(IEnumerable<Position2D> vertices, Transform2D transform)
|
2019-09-06 08:11:58 +00:00
|
|
|
{
|
2019-09-06 20:00:35 +00:00
|
|
|
var TransformedVertices = vertices.Select(vertex => Vector2.Transform(vertex, transform.TransformMatrix));
|
2019-09-06 08:11:58 +00:00
|
|
|
|
|
|
|
return new AABB
|
|
|
|
{
|
2019-09-19 00:00:43 +00:00
|
|
|
MinX = TransformedVertices.Min(vertex => vertex.X),
|
|
|
|
MinY = TransformedVertices.Min(vertex => vertex.Y),
|
|
|
|
MaxX = TransformedVertices.Max(vertex => vertex.X),
|
|
|
|
MaxY = TransformedVertices.Max(vertex => vertex.Y)
|
2019-09-06 08:11:58 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-19 00:00:43 +00:00
|
|
|
public AABB(float minX, float minY, float maxX, float maxY)
|
2019-09-06 08:11:58 +00:00
|
|
|
{
|
|
|
|
MinX = minX;
|
|
|
|
MinY = minY;
|
|
|
|
MaxX = maxX;
|
|
|
|
MaxY = maxY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|