You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
76 lines
2.9 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace Sog
|
|
{
|
|
public class Oriented2DBBox
|
|
{
|
|
public Fixed64Vector2 BottomLeft;
|
|
|
|
public Fixed64Vector2 Right;
|
|
|
|
public Fixed64Vector2 Up;
|
|
|
|
public Oriented2DBBox(Fixed64Vector2 bottomLeft, Fixed64Vector2 right, Fixed64Vector2 up)
|
|
{
|
|
BottomLeft = bottomLeft;
|
|
Right = right;
|
|
Up = up;
|
|
}
|
|
|
|
public bool Intersects(Fixed64Rect r)
|
|
{
|
|
Fixed64Vector2 vector = new Fixed64Vector2(r.xMin, r.yMin);
|
|
Fixed64Vector2 vector2 = BottomLeft - vector;
|
|
Fixed64Vector2 vector3 = BottomLeft + Right - vector;
|
|
Fixed64Vector2 vector4 = BottomLeft + Right + Up - vector;
|
|
Fixed64Vector2 vector5 = BottomLeft + Up - vector;
|
|
if (vector2.x < 0f && vector3.x < 0f && vector4.x < 0f && vector5.x < 0f)
|
|
{
|
|
return false;
|
|
}
|
|
if (vector2.y < 0f && vector3.y < 0f && vector4.y < 0f && vector5.y < 0f)
|
|
{
|
|
return false;
|
|
}
|
|
Fixed64 width = r.width;
|
|
if (vector2.x > width && vector3.x > width && vector4.x > width && vector5.x > width)
|
|
{
|
|
return false;
|
|
}
|
|
Fixed64 height = r.height;
|
|
if (vector2.y > height && vector3.y > height && vector4.y > height && vector5.y > height)
|
|
{
|
|
return false;
|
|
}
|
|
Fixed64Vector2 a = vector - BottomLeft;
|
|
Fixed64Vector2 a2 = a + new Fixed64Vector2(r.width, 0f);
|
|
Fixed64Vector2 a3 = a + new Fixed64Vector2(r.width, r.height);
|
|
Fixed64Vector2 a4 = a + new Fixed64Vector2(0f, r.height);
|
|
if (Right.x * a.x + Right.y * a.y < 0f && Right.x * a2.x + Right.y * a2.y < 0f && Right.x * a3.x + Right.y * a3.y < 0f && Right.x * a4.x + Right.y * a4.y < 0f)
|
|
{
|
|
return false;
|
|
}
|
|
if (Up.x * a.x + Up.y * a.y < 0f && Up.x * a2.x + Up.y * a2.y < 0f && Up.x * a3.x + Up.y * a3.y < 0f && Up.x * a4.x + Up.y * a4.y < 0f)
|
|
{
|
|
return false;
|
|
}
|
|
Fixed64Vector2 b = Up + Right;
|
|
Fixed64Vector2 vector6 = a - b;
|
|
Fixed64Vector2 vector7 = a2 - b;
|
|
Fixed64Vector2 vector8 = a3 - b;
|
|
Fixed64Vector2 vector9 = a4 - b;
|
|
if (Right.x * vector6.x + Right.y * vector6.y > 0f && Right.x * vector7.x + Right.y * vector7.y > 0f && Right.x * vector8.x + Right.y * vector8.y > 0f && Right.x * vector9.x + Right.y * vector9.y > 0f)
|
|
{
|
|
return false;
|
|
}
|
|
if (Up.x * vector6.x + Up.y * vector6.y > 0f && Up.x * vector7.x + Up.y * vector7.y > 0f && Up.x * vector8.x + Up.y * vector8.y > 0f && Up.x * vector9.x + Up.y * vector9.y > 0f)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|