Skip to content

Commit

Permalink
Refactor: Simplified more vector math expressions
Browse files Browse the repository at this point in the history
Also removed the v1() and v2() accessors of Line and HEdge (the more
expressive from() and to() method names are better).
  • Loading branch information
danij-deng committed Apr 25, 2013
1 parent 179ff76 commit 60a9016
Show file tree
Hide file tree
Showing 20 changed files with 186 additions and 255 deletions.
74 changes: 23 additions & 51 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -23,8 +23,6 @@

#include <de/Error>

#include "p_dmu.h"

#include "MapElement"
#include "BspLeaf"
#include "Line"
Expand All @@ -35,10 +33,6 @@
#include "render/walldiv.h"
#include "render/rend_bias.h"

// Helper macros for accessing hedge data elements.
#define FRONT 0
#define BACK 1

/**
* @defgroup hedgeFrameFlags Half-edge Frame Flags
* @ingroup map
Expand All @@ -47,17 +41,6 @@
#define HEDGEINF_FACINGFRONT 0x0001
///@}

// Logical edge identifiers:
/// @addtogroup map
///@{
#define FROM 0
#define TO 1

/// Aliases:
#define START FROM
#define END TO
///@}

/**
* Map geometry half-edge.
*
Expand Down Expand Up @@ -88,6 +71,13 @@ class HEdge : public de::MapElement
/// The referenced geometry group does not exist. @ingroup errors
DENG2_ERROR(UnknownGeometryGroupError);

/// Edge/vertex identifiers:
enum
{
From,
To
};

public: /// @todo Make private:
/// Start and End vertexes of the segment.
Vertex *_from, *_to;
Expand Down Expand Up @@ -140,66 +130,48 @@ class HEdge : public de::MapElement
*
* @see vertex()
*/
inline de::Vector2d const &vertexOrigin(int to) const
{
inline de::Vector2d const &vertexOrigin(int to) const {
return vertex(to).origin();
}

/**
* Returns the From/Start vertex for the half-edge.
*/
inline Vertex &v1() { return vertex(FROM); }

/// @copydoc v1()
inline Vertex const &v1() const { return vertex(FROM); }

/// @copydoc v1()
/// An alias of v1().
inline Vertex &from() { return v1(); }
inline Vertex &from() { return vertex(From); }

/// @copydoc from()
/// An alias of v1().
inline Vertex const &from() const { return v1(); }
inline Vertex const &from() const { return vertex(From); }

/**
* Convenient accessor method for returning the origin of the From/Start
* vertex for the half-edge.
*
* @see v1()
* @see from()
*/
inline de::Vector2d const &v1Origin() const { return v1().origin(); }

/// @copydoc v1Origin()
/// An alias of v1Origin()
inline de::Vector2d const &fromOrigin() const { return v1Origin(); }
inline de::Vector2d const &fromOrigin() const { return from().origin(); }

/**
* Returns the To/End vertex for the half-edge.
*/
inline Vertex &v2() { return vertex(TO); }

/// @copydoc v2()
inline Vertex const &v2() const { return vertex(TO); }
inline Vertex &to() { return vertex(To); }

/// @copydoc v2()
/// An alias of v2().
inline Vertex &to() { return v2(); }

/// @copydoc to()
/// An alias of v2().
inline Vertex const &to() const { return v2(); }
inline Vertex const &to() const { return vertex(To); }

/**
* Convenient accessor method for returning the origin of the To/End
* vertex for the half-edge.
*
* @see v2()
* @see to()
*/
inline de::Vector2d const &v2Origin() const { return v2().origin(); }
inline de::Vector2d const &toOrigin() const { return to().origin(); }

/// @copydoc v2Origin()
/// An alias of v2Origin()
inline de::Vector2d const &toOrigin() const { return v2Origin(); }
/**
* Returns the point on the line which lies at the exact center of the
* two vertexes.
*/
inline de::Vector2d center() const {
return de::Vector2d(fromOrigin() + to().origin()) / 2;
}

/**
* Returns the linked @em next half-edge (clockwise) around the face of
Expand Down
38 changes: 9 additions & 29 deletions doomsday/client/include/map/line.h
Expand Up @@ -599,54 +599,34 @@ class Line : public de::MapElement
/**
* Returns the From/Start vertex for the line.
*/
inline Vertex &v1() const { return vertex(From); }

/// @copydoc v1()
/// An alias of v1().
inline Vertex &from() const { return v1(); }
inline Vertex &from() const { return vertex(From); }

/**
* Convenient accessor method for returning the origin of the From/Start
* vertex for the line.
*
* @see v1()
* @see from()
*/
inline de::Vector2d const &v1Origin() const { return v1().origin(); }

/// @copydoc v1Origin()
/// An alias of v1Origin()
inline de::Vector2d const &fromOrigin() const { return v1Origin(); }
inline de::Vector2d const &fromOrigin() const { return from().origin(); }

/**
* Returns the To/End vertex for the line.
*/
inline Vertex &v2() const { return vertex(To); }

/// @copydoc v2()
/// An alias of v2().
inline Vertex &to() const { return v2(); }
inline Vertex &to() const { return vertex(To); }

/**
* Convenient accessor method for returning the origin of the To/End
* vertex for the line.
*
* @see v2()
* @see to()
*/
inline de::Vector2d const &v2Origin() const { return v2().origin(); }

/// @copydoc v2Origin()
/// An alias of v2Origin()
inline de::Vector2d const &toOrigin() const { return v2Origin(); }
inline de::Vector2d const &toOrigin() const { return to().origin(); }

/**
* Returns the point on the line which lies at the exact center of the
* two vertexes.
*/
inline de::Vector2d center() const
{
return de::Vector2d((v1Origin()[VX] + v2Origin()[VX]) / 2,
(v1Origin()[VY] + v2Origin()[VY]) / 2);
}
inline de::Vector2d center() const { return fromOrigin() + direction() / 2; }

/**
* Returns the binary angle of the line (which, is derived from the
Expand Down Expand Up @@ -726,7 +706,7 @@ class Line : public de::MapElement
*/
inline coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const
{
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction().x, direction().y };
return V2d_PointLineDistance(point, fromV1, directionV1, offset);
}
Expand All @@ -750,7 +730,7 @@ class Line : public de::MapElement
*/
inline coord_t pointOnSide(const_pvec2d_t point) const
{
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction().x, direction().y };
return V2d_PointOnLineSide(point, fromV1, directionV1);
}
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/edit_map.cpp
Expand Up @@ -458,7 +458,7 @@ static int lineAngleSorter(void const *a, void const *b)
else
{
Line *line = &own[i]->line();
Vertex const &otherVtx = line->vertex(&line->v1() == rootVtx? 1:0);
Vertex const &otherVtx = line->vertex(&line->from() == rootVtx? 1:0);

fixed_t dx = otherVtx.origin().x - rootVtx->origin().x;
fixed_t dy = otherVtx.origin().y - rootVtx->origin().y;
Expand Down Expand Up @@ -590,7 +590,7 @@ static void setVertexLineOwner(Vertex *vtx, Line *lineptr, LineOwner **storage)
vtx->_lineOwners = newOwner;

// Link the line to its respective owner node.
if(vtx == &lineptr->v1())
if(vtx == &lineptr->from())
lineptr->_vo1 = newOwner;
else
lineptr->_vo2 = newOwner;
Expand Down Expand Up @@ -908,9 +908,9 @@ boolean MPE_End()
// Create a hedge for each line of this polyobj.
foreach(Line *line, polyobj->lines())
{
HEdge *hedge = new HEdge(line->v1(), &line->front()); // Polyobj has ownership.
HEdge *hedge = new HEdge(line->from(), &line->front()); // Polyobj has ownership.

hedge->_to = &line->v2();
hedge->_to = &line->to();
hedge->_length = line->length();

line->front().setLeftHEdge(hedge);
Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/map/blockmapvisual.cpp
Expand Up @@ -59,8 +59,8 @@ static int rendLine(Line *line, void * /*parameters*/)
{
if(line->validCount() != validCount)
{
glVertex2f(line->v1Origin()[VX], line->v1Origin()[VY]);
glVertex2f(line->v2Origin()[VX], line->v2Origin()[VY]);
glVertex2f(line->fromOrigin().x, line->fromOrigin().y);
glVertex2f( line->toOrigin().x, line->toOrigin().y);

line->setValidCount(validCount);
}
Expand All @@ -81,8 +81,8 @@ static int rendBspLeaf(BspLeaf *bspLeaf, void * /*parameters*/)
HEdge *hedge = base;
do
{
V2f_Set(start, hedge->v1Origin()[VX], hedge->v1Origin()[VY]);
V2f_Set(end, hedge->v2Origin()[VX], hedge->v2Origin()[VY]);
V2f_Set(start, hedge->fromOrigin().x, hedge->fromOrigin().y);
V2f_Set(end, hedge->toOrigin().x, hedge->toOrigin().y);

glBegin(GL_LINES);
glVertex2fv(start);
Expand Down

0 comments on commit 60a9016

Please sign in to comment.