Optimize Geometry::PointIsInSquare, which is used quite often in performance hotspots.
Original patch by mimo. Refs #3588 This was SVN commit r17236.
This commit is contained in:
parent
c2928c44d4
commit
f3b22e51a3
@ -19,24 +19,10 @@
|
||||
|
||||
#include "Geometry.h"
|
||||
|
||||
#include "maths/FixedVector2D.h"
|
||||
|
||||
using namespace Geometry;
|
||||
|
||||
// TODO: all of these things could be optimised quite easily
|
||||
|
||||
bool Geometry::PointIsInSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
|
||||
{
|
||||
fixed du = point.Dot(u);
|
||||
if (-halfSize.X <= du && du <= halfSize.X)
|
||||
{
|
||||
fixed dv = point.Dot(v);
|
||||
if (-halfSize.Y <= dv && dv <= halfSize.Y)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CFixedVector2D Geometry::GetHalfBoundingBox(CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
|
||||
{
|
||||
return CFixedVector2D(
|
||||
|
@ -24,9 +24,9 @@
|
||||
*/
|
||||
|
||||
#include "maths/Fixed.h"
|
||||
#include "maths/FixedVector2D.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
||||
class CFixedVector2D;
|
||||
|
||||
namespace Geometry
|
||||
{
|
||||
@ -36,12 +36,14 @@ namespace Geometry
|
||||
* Points precisely on an edge are considered to be inside.
|
||||
*
|
||||
* The rectangle is defined by the four vertexes
|
||||
* (+/-u*halfSize.X +/-v*halfSize.Y).
|
||||
* (+/-u*halfSize.X +/-v*halfSize.Y)
|
||||
*
|
||||
* The @p u and @p v vectors must be perpendicular.
|
||||
*/
|
||||
bool PointIsInSquare(CFixedVector2D point,
|
||||
CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize);
|
||||
inline bool PointIsInSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
|
||||
{
|
||||
return point.Dot(u).Absolute() <= halfSize.X && point.Dot(v).Absolute() <= halfSize.Y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a vector (bx,by) such that every point inside
|
||||
|
Loading…
Reference in New Issue
Block a user