Skip to content

Commit

Permalink
Refactor: Updated all map data classes wrt changes to Vertex
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Apr 22, 2013
1 parent 2ad9eaa commit 4f0c481
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 43 deletions.
1 change: 0 additions & 1 deletion doomsday/client/include/map/bspleaf.h
Expand Up @@ -27,7 +27,6 @@
#include <de/Error>

#include "MapElement"
#include "p_dmu.h"
#ifdef __CLIENT__
# include "render/rend_bias.h"
#endif
Expand Down
10 changes: 5 additions & 5 deletions doomsday/client/include/map/hedge.h
Expand Up @@ -140,7 +140,7 @@ class HEdge : public de::MapElement
*
* @see vertex()
*/
inline const_pvec2d_t &vertexOrigin(int to) const
inline de::Vector2d const &vertexOrigin(int to) const
{
return vertex(to).origin();
}
Expand All @@ -167,11 +167,11 @@ class HEdge : public de::MapElement
*
* @see v1()
*/
inline const_pvec2d_t &v1Origin() const { return v1().origin(); }
inline de::Vector2d const &v1Origin() const { return v1().origin(); }

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

/**
* Returns the To/End vertex for the half-edge.
Expand All @@ -195,11 +195,11 @@ class HEdge : public de::MapElement
*
* @see v2()
*/
inline const_pvec2d_t &v2Origin() const { return v2().origin(); }
inline de::Vector2d const &v2Origin() const { return v2().origin(); }

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

/**
* Returns the linked @em next half-edge (clockwise) around the face of
Expand Down
22 changes: 12 additions & 10 deletions doomsday/client/include/map/line.h
Expand Up @@ -33,7 +33,6 @@
#include "MapElement"
#include "Surface"
#include "Vertex"
#include "p_dmu.h"

class HEdge;
class LineOwner;
Expand Down Expand Up @@ -593,7 +592,7 @@ class Line : public de::MapElement
*
* @see vertex()
*/
inline const_pvec2d_t &vertexOrigin(int to) const {
inline de::Vector2d const &vertexOrigin(int to) const {
return vertex(to).origin();
}

Expand All @@ -612,11 +611,11 @@ class Line : public de::MapElement
*
* @see v1()
*/
inline const_pvec2d_t &v1Origin() const { return v1().origin(); }
inline de::Vector2d const &v1Origin() const { return v1().origin(); }

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

/**
* Returns the To/End vertex for the line.
Expand All @@ -633,11 +632,11 @@ class Line : public de::MapElement
*
* @see v2()
*/
inline const_pvec2d_t &v2Origin() const { return v2().origin(); }
inline de::Vector2d const &v2Origin() const { return v2().origin(); }

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

/**
* Returns the point on the line which lies at the exact center of the
Expand Down Expand Up @@ -727,8 +726,9 @@ class Line : public de::MapElement
*/
inline coord_t pointDistance(const_pvec2d_t point, coord_t *offset) const
{
coord_t v1Direction[2] = { direction().x, direction().y };
return V2d_PointLineDistance(point, v1().origin(), v1Direction, offset);
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction().x, direction().y };
return V2d_PointLineDistance(point, fromV1, directionV1, offset);
}

/// @copydoc pointDistance()
Expand All @@ -750,8 +750,9 @@ class Line : public de::MapElement
*/
inline coord_t pointOnSide(const_pvec2d_t point) const
{
coord_t v1Direction[2] = { direction().x, direction().y };
return V2d_PointOnLineSide(point, v1().origin(), v1Direction);
coord_t fromV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction().x, direction().y };
return V2d_PointOnLineSide(point, fromV1, directionV1);
}

/// @copydoc pointOnSide()
Expand Down Expand Up @@ -828,6 +829,7 @@ class Line : public de::MapElement
inline void replaceFrom(Vertex &newVertex) { replaceVertex(From, newVertex); }
inline void replaceTo(Vertex &newVertex) { replaceVertex(To, newVertex); }

protected:
int property(setargs_t &args) const;
int setProperty(setargs_t const &args);

Expand Down
14 changes: 6 additions & 8 deletions doomsday/client/include/map/lineowner.h
Expand Up @@ -21,8 +21,9 @@
#ifndef DENG_WORLD_MAP_LINEOWNER
#define DENG_WORLD_MAP_LINEOWNER

#include <de/Vector>

#include <de/binangle.h>
#include <de/vector1.h> /// @todo remove me

class Line;

Expand Down Expand Up @@ -54,18 +55,15 @@ class LineOwner
binangle_t _angle;

struct ShadowVert {
vec2d_t inner;
vec2d_t extended;
de::Vector2d inner;
de::Vector2d extended;
} _shadowOffsets;

public:
/*LineOwner() : _line(0), _angle(0)
{
_link[Previous] = 0;
_link[Next] = 0;
V2d_Set(_shadowOffsets.inner, 0, 0);
V2d_Set(_shadowOffsets.extended, 0, 0);
}*/

/**
Expand Down Expand Up @@ -128,12 +126,12 @@ class LineOwner
/**
* Returns the inner shadow offset of the line owner.
*/
vec2d_t const &innerShadowOffset() const { return _shadowOffsets.inner; }
de::Vector2d const &innerShadowOffset() const { return _shadowOffsets.inner; }

/**
* Returns the extended shadow offset of the line owner.
*/
vec2d_t const &extendedShadowOffset() const { return _shadowOffsets.extended; }
de::Vector2d const &extendedShadowOffset() const { return _shadowOffsets.extended; }
};

#endif // DENG_WORLD_MAP_LINEOWNER
2 changes: 1 addition & 1 deletion doomsday/client/include/map/plane.h
Expand Up @@ -28,7 +28,6 @@
#include <de/Vector>

#include "MapElement"
#include "map/p_dmu.h"

class Sector;
class Surface;
Expand Down Expand Up @@ -188,6 +187,7 @@ class Plane : public de::MapElement
*/
Type type() const;

protected:
int property(setargs_t &args) const;
int setProperty(setargs_t const &args);

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/map/sector.h
Expand Up @@ -30,7 +30,6 @@
#include <de/Vector>

#include "MapElement"
#include "map/p_dmu.h"
#include "Plane"

class BspLeaf;
Expand Down Expand Up @@ -452,6 +451,7 @@ class Sector : public de::MapElement,
/// @todo Refactor away.
void setValidCount(int newValidCount);

protected:
int property(setargs_t &args) const;
int setProperty(setargs_t const &args);

Expand Down
15 changes: 11 additions & 4 deletions doomsday/client/src/map/bspleaf.cpp
Expand Up @@ -23,7 +23,6 @@
#include <de/Log>

#include "de_base.h"
#include "m_misc.h" // M_TriangleArea()

#include "HEdge"
#include "Polyobj"
Expand All @@ -34,6 +33,14 @@

using namespace de;

/// Compute the area of a triangle defined by three 2D point vectors.
ddouble triangleArea(Vector2d const &v1, Vector2d const &v2, Vector2d const &v3)
{
Vector2d a = v2 - v1;
Vector2d b = v3 - v1;
return (a.x * b.y - b.x * a.y) / 2;
}

DENG2_PIMPL(BspLeaf)
{
/// Vertex bounding box in the map coordinate space.
Expand Down Expand Up @@ -130,7 +137,7 @@ DENG2_PIMPL(BspLeaf)
a = &other->from();
b = &other->next().from();

if(M_TriangleArea(base->origin(), a->origin(), b->origin()) <= MIN_TRIANGLE_EPSILON)
if(de::abs(triangleArea(base->origin(), a->origin(), b->origin())) <= MIN_TRIANGLE_EPSILON)
{
// No good. We'll move on to the next vertex.
base = 0;
Expand Down Expand Up @@ -227,11 +234,11 @@ void BspLeaf::updateAABox()
if(!_hedge) return; // Very odd...

HEdge *hedgeIt = _hedge;
V2d_InitBox(d->aaBox.arvec2, hedgeIt->v1Origin());
V2d_InitBoxXY(d->aaBox.arvec2, hedgeIt->fromOrigin().x, hedgeIt->fromOrigin().y);

while((hedgeIt = &hedgeIt->next()) != _hedge)
{
V2d_AddToBox(d->aaBox.arvec2, hedgeIt->v1Origin());
V2d_AddToBoxXY(d->aaBox.arvec2, hedgeIt->fromOrigin().x, hedgeIt->fromOrigin().y);
}
}

Expand Down
8 changes: 4 additions & 4 deletions doomsday/client/src/map/gamemap.cpp
Expand Up @@ -108,16 +108,16 @@ DENG2_PIMPL(GameMap)
if(hedge->hasLineSide())
{
Vertex const &vtx = hedge->lineSide().from();
hedge->_lineOffset = V2d_Distance(hedge->v1Origin(), vtx.origin());
hedge->_lineOffset = Vector2d(vtx.origin() - hedge->v1Origin()).length();
}

// Calculate the length of the segment.
hedge->_length = V2d_Distance(hedge->v2Origin(), hedge->v1Origin());
hedge->_length = Vector2d(hedge->v1Origin() - hedge->v2Origin()).length();
if(hedge->_length == 0)
hedge->_length = 0.01f; // Hmm...

hedge->_angle = bamsAtan2(int( hedge->v2Origin()[VY] - hedge->v1Origin()[VY] ),
int( hedge->v2Origin()[VX] - hedge->v1Origin()[VX] )) << FRACBITS;
hedge->_angle = bamsAtan2(int( hedge->v2Origin().y - hedge->v1Origin().y ),
int( hedge->v2Origin().x - hedge->v1Origin().x )) << FRACBITS;

} while((hedge = &hedge->next()) != base);
}
Expand Down
18 changes: 13 additions & 5 deletions doomsday/client/src/map/hedge.cpp
Expand Up @@ -389,15 +389,23 @@ biassurface_t &HEdge::biasSurfaceForGeometryGroup(uint groupId)

coord_t HEdge::pointDistance(const_pvec2d_t point, coord_t *offset) const
{
coord_t direction[2]; V2d_Subtract(direction, _to->origin(), _from->origin());
return V2d_PointLineDistance(point, _from->origin(), direction, offset);
/// @todo Why are we calculating this every time?
Vector2d direction = _to->origin() - _from->origin();

coord_t fromOriginV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction.x, direction.y };
return V2d_PointLineDistance(point, fromOriginV1, directionV1, offset);
}

coord_t HEdge::pointOnSide(const_pvec2d_t point) const
{
DENG2_ASSERT(point);
coord_t direction[2]; V2d_Subtract(direction, _to->origin(), _from->origin());
return V2d_PointOnLineSide(point, _from->origin(), direction);
DENG_ASSERT(point != 0);
/// @todo Why are we calculating this every time?
Vector2d direction = _to->origin() - _from->origin();

coord_t fromOriginV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction.x, direction.y };
return V2d_PointOnLineSide(point, fromOriginV1, directionV1);
}

int HEdge::property(setargs_t &args) const
Expand Down
9 changes: 5 additions & 4 deletions doomsday/client/src/map/line.cpp
Expand Up @@ -571,8 +571,8 @@ AABoxd const &Line::aaBox() const

void Line::updateAABox()
{
V2d_InitBox(d->aaBox.arvec2, d->from->origin());
V2d_AddToBox(d->aaBox.arvec2, d->to->origin());
V2d_InitBoxXY(d->aaBox.arvec2, fromOrigin().x, fromOrigin().y);
V2d_AddToBoxXY(d->aaBox.arvec2, toOrigin().x, toOrigin().y);
}

coord_t Line::length() const
Expand Down Expand Up @@ -604,8 +604,9 @@ binangle_t Line::angle() const

int Line::boxOnSide(AABoxd const &box) const
{
coord_t v1Direction[2] = { direction().x, direction().y };
return M_BoxOnLineSide(&box, d->from->origin(), v1Direction);
coord_t fromOriginV1[2] = { fromOrigin().x, fromOrigin().y };
coord_t directionV1[2] = { direction().x, direction().y };
return M_BoxOnLineSide(&box, fromOriginV1, directionV1);
}

int Line::boxOnSide_FixedPrecision(AABoxd const &box) const
Expand Down

0 comments on commit 4f0c481

Please sign in to comment.