Mark several CFixedVector2D as const and passed by reference in Geometry and a few other places. Mark some functions (that probably already were) inline.

Also make sure we don't include Geometry.h where it's not necessary.

This was SVN commit r17238.
This commit is contained in:
wraitii 2015-11-11 20:50:02 +00:00
parent f3b22e51a3
commit 913545aa41
10 changed files with 36 additions and 35 deletions

View File

@ -198,7 +198,7 @@ public:
/**
* Compute the dot product of this vector with another.
*/
fixed Dot(const CFixedVector2D& v)
fixed Dot(const CFixedVector2D& v) const
{
i64 x = FIXED_MUL_I64_I32_I32(X.GetInternalValue(), v.X.GetInternalValue());
i64 y = FIXED_MUL_I64_I32_I32(Y.GetInternalValue(), v.Y.GetInternalValue());
@ -212,7 +212,7 @@ public:
return ret;
}
CFixedVector2D Perpendicular()
CFixedVector2D Perpendicular() const
{
return CFixedVector2D(Y, -X);
}

View File

@ -640,7 +640,7 @@ private:
/**
* Return whether the given point is within the world bounds by at least r
*/
bool IsInWorld(entity_pos_t x, entity_pos_t z, entity_pos_t r)
inline bool IsInWorld(entity_pos_t x, entity_pos_t z, entity_pos_t r)
{
return (m_WorldX0+r <= x && x <= m_WorldX1-r && m_WorldZ0+r <= z && z <= m_WorldZ1-r);
}
@ -648,7 +648,7 @@ private:
/**
* Return whether the given point is within the world bounds
*/
bool IsInWorld(CFixedVector2D p)
inline bool IsInWorld(const CFixedVector2D& p)
{
return (m_WorldX0 <= p.X && p.X <= m_WorldX1 && m_WorldZ0 <= p.Y && p.Y <= m_WorldZ1);
}

View File

@ -36,7 +36,6 @@
#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "simulation2/components/ICmpObstructionManager.h"
#include "simulation2/helpers/Geometry.h"
#include "simulation2/helpers/LongPathfinder.h"
class SceneCollector;

View File

@ -133,7 +133,7 @@ static const entity_pos_t EDGE_EXPAND_DELTA = entity_pos_t::FromInt(1)/16;
* Check whether a ray from 'a' to 'b' crosses any of the edges.
* (Edges are one-sided so it's only considered a cross if going from front to back.)
*/
inline static bool CheckVisibility(CFixedVector2D a, CFixedVector2D b, const std::vector<Edge>& edges)
inline static bool CheckVisibility(const CFixedVector2D& a, const CFixedVector2D& b, const std::vector<Edge>& edges)
{
CFixedVector2D abn = (b - a).Perpendicular();
@ -177,7 +177,7 @@ inline static bool CheckVisibility(CFixedVector2D a, CFixedVector2D b, const std
// They assume the caller has already excluded edges for which 'a' is
// on the wrong side.)
inline static bool CheckVisibilityLeft(CFixedVector2D a, CFixedVector2D b, const std::vector<EdgeAA>& edges)
inline static bool CheckVisibilityLeft(const CFixedVector2D& a, const CFixedVector2D& b, const std::vector<EdgeAA>& edges)
{
if (a.X >= b.X)
return true;
@ -205,7 +205,7 @@ inline static bool CheckVisibilityLeft(CFixedVector2D a, CFixedVector2D b, const
return true;
}
inline static bool CheckVisibilityRight(CFixedVector2D a, CFixedVector2D b, const std::vector<EdgeAA>& edges)
inline static bool CheckVisibilityRight(const CFixedVector2D& a, const CFixedVector2D& b, const std::vector<EdgeAA>& edges)
{
if (a.X <= b.X)
return true;
@ -233,7 +233,7 @@ inline static bool CheckVisibilityRight(CFixedVector2D a, CFixedVector2D b, cons
return true;
}
inline static bool CheckVisibilityBottom(CFixedVector2D a, CFixedVector2D b, const std::vector<EdgeAA>& edges)
inline static bool CheckVisibilityBottom(const CFixedVector2D& a, const CFixedVector2D& b, const std::vector<EdgeAA>& edges)
{
if (a.Y >= b.Y)
return true;
@ -261,7 +261,7 @@ inline static bool CheckVisibilityBottom(CFixedVector2D a, CFixedVector2D b, con
return true;
}
inline static bool CheckVisibilityTop(CFixedVector2D a, CFixedVector2D b, const std::vector<EdgeAA>& edges)
inline static bool CheckVisibilityTop(const CFixedVector2D& a, const CFixedVector2D& b, const std::vector<EdgeAA>& edges)
{
if (a.Y <= b.Y)
return true;
@ -480,7 +480,7 @@ static void AddTerrainEdges(std::vector<Edge>& edges, std::vector<Vertex>& verte
}
}
static void SplitAAEdges(CFixedVector2D a,
static void SplitAAEdges(const CFixedVector2D& a,
const std::vector<Edge>& edges,
const std::vector<Square>& squares,
std::vector<Edge>& edgesUnaligned,

View File

@ -36,7 +36,6 @@
#include "simulation2/components/ICmpPlayerManager.h"
#include "simulation2/components/ICmpPosition.h"
#include "simulation2/components/ICmpTerritoryInfluence.h"
#include "simulation2/helpers/Geometry.h"
#include "simulation2/helpers/Grid.h"
#include "simulation2/helpers/Render.h"

View File

@ -23,7 +23,7 @@ using namespace Geometry;
// TODO: all of these things could be optimised quite easily
CFixedVector2D Geometry::GetHalfBoundingBox(CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
CFixedVector2D Geometry::GetHalfBoundingBox(const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize)
{
return CFixedVector2D(
u.X.Multiply(halfSize.X).Absolute() + v.X.Multiply(halfSize.Y).Absolute(),
@ -36,7 +36,7 @@ float Geometry::ChordToCentralAngle(const float chordLength, const float radius)
return acosf(1.f - SQR(chordLength)/(2.f*SQR(radius))); // cfr. law of cosines
}
fixed Geometry::DistanceToSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize, bool countInsideAsZero)
fixed Geometry::DistanceToSquare(const CFixedVector2D& point, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize, bool countInsideAsZero)
{
/*
* Relative to its own coordinate system, we have a square like:
@ -102,7 +102,7 @@ fixed Geometry::DistanceToSquare(CFixedVector2D point, CFixedVector2D u, CFixedV
// Same as above except it does not use Length.
// For explanations refer to DistanceToSquare
fixed Geometry::DistanceToSquareSquared(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize, bool countInsideAsZero)
fixed Geometry::DistanceToSquareSquared(const CFixedVector2D& point, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize, bool countInsideAsZero)
{
fixed du = point.Dot(u);
fixed dv = point.Dot(v);
@ -140,7 +140,7 @@ fixed Geometry::DistanceToSquareSquared(CFixedVector2D point, CFixedVector2D u,
}
}
CFixedVector2D Geometry::NearestPointOnSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
CFixedVector2D Geometry::NearestPointOnSquare(const CFixedVector2D& point, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize)
{
/*
* Relative to its own coordinate system, we have a square like:
@ -214,7 +214,7 @@ CFixedVector2D Geometry::NearestPointOnSquare(CFixedVector2D point, CFixedVector
}
}
bool Geometry::TestRaySquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
bool Geometry::TestRaySquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize)
{
/*
* We only consider collisions to be when the ray goes from outside to inside the shape (and possibly out again).
@ -262,7 +262,7 @@ bool Geometry::TestRaySquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D
return false;
}
bool Geometry::TestRayAASquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D halfSize)
bool Geometry::TestRayAASquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& halfSize)
{
// Exactly like TestRaySquare with u=(1,0), v=(0,1)
@ -308,7 +308,7 @@ bool Geometry::TestRayAASquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2
* Separating axis test; returns true if the square defined by u/v/halfSize at the origin
* is not entirely on the clockwise side of a line in direction 'axis' passing through 'a'
*/
static bool SquareSAT(CFixedVector2D a, CFixedVector2D axis, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
static bool SquareSAT(const CFixedVector2D& a, const CFixedVector2D& axis, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize)
{
fixed hw = halfSize.X;
fixed hh = halfSize.Y;
@ -327,8 +327,8 @@ static bool SquareSAT(CFixedVector2D a, CFixedVector2D axis, CFixedVector2D u, C
}
bool Geometry::TestSquareSquare(
CFixedVector2D c0, CFixedVector2D u0, CFixedVector2D v0, CFixedVector2D halfSize0,
CFixedVector2D c1, CFixedVector2D u1, CFixedVector2D v1, CFixedVector2D halfSize1)
const CFixedVector2D& c0, const CFixedVector2D& u0, const CFixedVector2D& v0, const CFixedVector2D& halfSize0,
const CFixedVector2D& c1, const CFixedVector2D& u1, const CFixedVector2D& v1, const CFixedVector2D& halfSize1)
{
// TODO: need to test this carefully

View File

@ -27,7 +27,6 @@
#include "maths/FixedVector2D.h"
#include "maths/MathUtil.h"
namespace Geometry
{
@ -40,7 +39,7 @@ namespace Geometry
*
* The @p u and @p v vectors must be perpendicular.
*/
inline bool PointIsInSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize)
inline bool PointIsInSquare(const CFixedVector2D& point, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize)
{
return point.Dot(u).Absolute() <= halfSize.X && point.Dot(v).Absolute() <= halfSize.Y;
}
@ -53,7 +52,7 @@ inline bool PointIsInSquare(CFixedVector2D point, CFixedVector2D u, CFixedVector
* The rectangle is defined by the four vertexes
* (+/-u*halfSize.X +/-v*halfSize.Y).
*/
CFixedVector2D GetHalfBoundingBox(CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize);
CFixedVector2D GetHalfBoundingBox(const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize);
/**
* Returns the minimum Euclidean distance from the given point to
@ -69,15 +68,15 @@ CFixedVector2D GetHalfBoundingBox(CFixedVector2D u, CFixedVector2D v, CFixedVect
*
* The @p u and @p v vectors must be perpendicular and unit length.
*/
fixed DistanceToSquare(CFixedVector2D point,
CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize,
fixed DistanceToSquare(const CFixedVector2D& point,
const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize,
bool countInsideAsZero = false);
/**
* Similar to above but never uses sqrt, so it returns the squared distance.
*/
fixed DistanceToSquareSquared(CFixedVector2D point,
CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize,
fixed DistanceToSquareSquared(const CFixedVector2D& point,
const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize,
bool countInsideAsZero = false);
/**
* Returns a point on the boundary of the given rotated rectangle
@ -89,8 +88,8 @@ fixed DistanceToSquareSquared(CFixedVector2D point,
*
* The @p u and @p v vectors must be perpendicular and unit length.
*/
CFixedVector2D NearestPointOnSquare(CFixedVector2D point,
CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize);
CFixedVector2D NearestPointOnSquare(const CFixedVector2D& point,
const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize);
/**
* Given a circle of radius @p radius, and a chord of length @p chordLength
@ -101,13 +100,13 @@ CFixedVector2D NearestPointOnSquare(CFixedVector2D point,
*/
float ChordToCentralAngle(const float chordLength, const float radius);
bool TestRaySquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D u, CFixedVector2D v, CFixedVector2D halfSize);
bool TestRaySquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& u, const CFixedVector2D& v, const CFixedVector2D& halfSize);
bool TestRayAASquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D halfSize);
bool TestRayAASquare(const CFixedVector2D& a, const CFixedVector2D& b, const CFixedVector2D& halfSize);
bool TestSquareSquare(
CFixedVector2D c0, CFixedVector2D u0, CFixedVector2D v0, CFixedVector2D halfSize0,
CFixedVector2D c1, CFixedVector2D u1, CFixedVector2D v1, CFixedVector2D halfSize1);
const CFixedVector2D& c0, const CFixedVector2D& u0, const CFixedVector2D& v0, const CFixedVector2D& halfSize0,
const CFixedVector2D& c1, const CFixedVector2D& u1, const CFixedVector2D& v1, const CFixedVector2D& halfSize1);
} // namespace

View File

@ -22,6 +22,8 @@
#include "lib/bits.h"
#include "ps/Profile.h"
#include "Geometry.h"
/**
* Jump point cache.
*

View File

@ -22,6 +22,8 @@
#include "graphics/Terrain.h"
#include "Pathfinding.h"
#include "Geometry.h"
static bool NavcellContainsCircle(int i, int j, fixed x, fixed z, fixed r, bool inside)
{
// Accept any navcell (i,j) that contains a point which is inside[/outside]

View File

@ -18,11 +18,11 @@
#ifndef INCLUDED_PATHFINDING
#define INCLUDED_PATHFINDING
#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "simulation2/system/ParamNode.h"
#include "graphics/Terrain.h"
#include "Geometry.h"
#include "Grid.h"
#include "PathGoal.h"