Skip to content

Commit

Permalink
Mesh: Added (Element) base class for all mesh geometry elements
Browse files Browse the repository at this point in the history
Plus cleanup.
  • Loading branch information
danij-deng committed Jun 7, 2013
1 parent b5e7f0d commit 6563e4c
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 248 deletions.
59 changes: 15 additions & 44 deletions doomsday/client/include/map/face.h
@@ -1,4 +1,4 @@
/** @file map/face.h World Map Face Geometry.
/** @file data/face.h Mesh Geometry Face.
*
* @authors Copyright © 2013 Daniel Swanson <danij@dengine.net>
*
Expand All @@ -17,41 +17,35 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_MAP_FACE
#define DENG_WORLD_MAP_FACE
#ifndef DENG_DATA_MESH_FACE_H
#define DENG_DATA_MESH_FACE_H

#include <de/aabox.h>

#include <de/Vector>

#include "MapElement"
#include "Mesh"

namespace de {

class HEdge;
class Mesh;

/**
* Face geometry.
* Mesh face geometry.
*
* @ingroup map
* @ingroup data
*/
class Face
class Face : public Mesh::Element
{
DENG2_NO_COPY (Face)
DENG2_NO_ASSIGN(Face)

public:
public: /// @todo make private:
/// Total number of half-edge's in the face geometry.
int _hedgeCount;

public:
explicit Face(Mesh &mesh);

/**
* Returns the mesh the face is a part of.
* Total number of half-edges in the face geometry.
*/
Mesh &mesh() const;
int hedgeCount() const;

/**
* Returns a pointer to the first half-edge in the face geometry (note that
Expand All @@ -60,15 +54,10 @@ class Face
*/
HEdge *hedge() const;

/**
* Total number of half-edges in the face geometry.
*/
int hedgeCount() const;

/**
* Change the first half-edge in the face geometry.
*/
void setHEdge(HEdge *newHEdge);
void setHEdge(HEdge const *newHEdge);

/**
* Returns the axis-aligned bounding box which encompases all the vertexes
Expand Down Expand Up @@ -105,33 +94,15 @@ class Face
bool isConvex() const;

/**
* Returns a pointer to the map element attributed to the face. May return @c 0
* if not attributed.
*/
MapElement *mapElement() const;

/**
* Change the MapElement to which the face is attributed.
*
* @param newMapElement New MapElement to attribute to the face. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see mapElement()
*/
void setMapElement(MapElement *newMapElement);

#ifdef DENG_DEBUG
/**
* Output a textual, human-readable description/representation of the face to
* the application's output log.
* Returns a textual human-readable description/representation of the face
* suitable for writing to the application's output log.
*/
void print() const;
#endif
String description() const;

private:
DENG2_PRIVATE(d)
};

} // namespace de

#endif // DENG_WORLD_MAP_FACE
#endif // DENG_DATA_MESH_FACE_H
154 changes: 60 additions & 94 deletions doomsday/client/include/map/hedge.h
@@ -1,4 +1,4 @@
/** @file map/hedge.h World Map Geometry Half-edge.
/** @file data/hedge.h Mesh Geometry Half-Edge.
*
* @authors Copyright © 2011-2013 Daniel Swanson <danij@dengine.net>
*
Expand All @@ -17,61 +17,93 @@
* 02110-1301 USA</small>
*/

#ifndef DENG_WORLD_MAP_HEDGE
#define DENG_WORLD_MAP_HEDGE
#ifndef DENG_DATA_MESH_HEDGE_H
#define DENG_DATA_MESH_HEDGE_H

#include <de/Error>
#include <de/Vector>

#include "MapElement"
#include "Mesh"
#include "Vertex"

namespace de {

class Face;
class Mesh;

/**
* Half-edge geometry.
* Mesh half-edge geometry.
*
* @ingroup map
*/
class HEdge
class HEdge : public Mesh::Element
{
DENG2_NO_COPY(HEdge)
DENG2_NO_ASSIGN(HEdge)

public:
/// Required twin half-edge is missing. @ingroup errors
DENG2_ERROR(MissingTwinError);

/// Required neighbor half-edge is missing. @ingroup errors
DENG2_ERROR(MissingNeighborError);

/// Required face is missing. @ingroup errors
DENG2_ERROR(MissingFaceError);

/// Required neighbor half-edge is missing. @ingroup errors
DENG2_ERROR(MissingNeighborError);

public:
HEdge(Mesh &mesh, Vertex &vertex);

/**
* Returns the mesh the half-edge is a part of.
*/
Mesh &mesh() const;

/**
* Returns the vertex of the half-edge.
*/
Vertex &vertex() const;

/**
* Convenient accessor method for returning the origin coordinates for the
* vertex of the half-edge.
* Convenient accessor returning the origin coordinates for the vertex of
* the half-edge.
*
* @see vertex()
*/
inline Vector2d const &origin() const { return vertex().origin(); }

/**
* Returns @c true iff a @em twin is linked to the half-edge.
*/
bool hasTwin() const;

/**
* Returns the linked @em twin of the half-edge.
*/
HEdge &twin() const;

/**
* Change the linked @em twin half-edge.
*
* @param newTwin New half-edge to attribute as the @em twin half-edge.
* Ownership is unaffected. Can be @c 0 (to clear the
* attribution).
*
* @see hasTwin(), twin()
*/
void setTwin(HEdge const *newTwin);

/**
* Returns @c true iff the half-edge is part of some Face geometry.
*/
bool hasFace() const;

/**
* Returns the Face geometry the half-edge is a part of.
*
* @see hasFace()
*/
Face &face() const;

/**
* Change the Face to which the half-edge is attributed.
*
* @param newFace New Face to attribute to the half-edge. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see hasFace(), face()
*/
void setFace(Face const *newFace);

/**
* Returns @c true iff the half-edge has a neighbor in the specifed direction
* around the face of the polyon.
Expand All @@ -90,9 +122,9 @@ class HEdge
* Change the neighbor half-edge in the specified @a direction around the
* face of the polygon.
*
* @param direction Relative direction for the new neighbor half-edge.
* @param newprev Half-edge to attribute as the new neighbor. Ownership is
* unaffected.
* @param direction Relative direction for the new neighbor half-edge.
* @param newNeighbor Half-edge to attribute as the new neighbor.
* Ownership is unaffected.
*
* @see hasNeighbor(), neighbor()
*/
Expand All @@ -118,8 +150,8 @@ class HEdge
* Change the HEdge attributed as the next (clockwise) neighbor of "this"
* half-edge.
*
* @param newNext Half-edge to attribute as the new next (clockwise) neighbor.
* Ownership is unaffected.
* @param newNext Half-edge to attribute as the new next (clockwise)
* neighbor. Ownership is unaffected.
*
* @see setNeighbor(), next()
*/
Expand Down Expand Up @@ -152,76 +184,10 @@ class HEdge
*/
inline void setPrev(HEdge *newPrev) { setNeighbor(Anticlockwise, newPrev); }

/**
* Returns @c true iff a @em twin is linked to the half-edge.
*/
bool hasTwin() const;

/**
* Returns the linked @em twin of the half-edge.
*/
HEdge &twin() const;

/**
* Returns a pointer to the linked @em twin of the half-edge; otherwise @c 0.
*
* @see hasTwin()
*/
inline HEdge *twinPtr() const { return hasTwin()? &twin() : 0; }

/**
* Change the linked @em twin half-edge.
*
* @param newTwin New half-edge to attribute as the @em twin half-edge.
* Ownership is unaffected. Can be @c 0 (to clear the
* attribution).
*
* @see hasTwin(), twin()
*/
void setTwin(HEdge const *newTwin);

/**
* Returns @c true iff the half-edge is part of some Face geometry.
*/
bool hasFace() const;

/**
* Returns the Face geometry the half-edge is a part of.
*
* @see hasFace()
*/
Face &face() const;

/**
* Change the Face to which the half-edge is attributed.
*
* @param newFace New Face to attribute to the half-edge. Ownership is
* unaffected. Can be @c 0 (to clear the attribution).
*
* @see hasFace(), face()
*/
void setFace(Face const *newFace);

/**
* Returns a pointer to the map element attributed to the half-edge. May return
* @c 0 if not attributed.
*/
MapElement *mapElement() const;

/**
* Change the MapElement to which the half-edge is attributed.
*
* @param newMapElement New MapElement to attribute to the half-edge. Ownership
* is unaffected. Can be @c 0 (to clear the attribution).
*
* @see mapElement()
*/
void setMapElement(MapElement *newMapElement);

private:
DENG2_PRIVATE(d)
};

} // namespace de

#endif // DENG_WORLD_MAP_HEDGE
#endif // DENG_DATA_MESH_HEDGE_H

0 comments on commit 6563e4c

Please sign in to comment.