
#ifndef _JL_HALF_EDGE_H_
#define _JL_HALF_EDGE_H_

#include "vec4.h"
#include "vertex.h"

class HalfEdge {

	friend class SubdObj;
	friend class PaintersLine;
	friend class PaintersPoly;

	public:
		Vertex		*_v;			// vertex at this end of edge
		HalfEdge	*_other_half;	// the other half of edge
		HalfEdge	*_link;			// clockwise around face
		HalfEdge	*_child;		// child in subdivision
		HalfEdge	*_next;			// SubdObj maintains list of HalfEdges
		int			_flag;			// used in once-per-face operations

		static int	_allocated;		// total HalfEdges in memory

		void NullAllPointers() {
				_v = NULL; _other_half = _link = _child = _next = NULL; 
				_flag = 0;
			}

		void CopyFrom(const HalfEdge&);

	public:
		HalfEdge() { NullAllPointers(); _allocated++; }
		HalfEdge(Vertex *v) { NullAllPointers(); _v = v; _allocated++; }
		HalfEdge(const HalfEdge &he) { CopyFrom(he); _allocated++; }
		~HalfEdge() { _allocated--; }

		HalfEdge& operator=(const HalfEdge &he) { CopyFrom(he); return *this; }

		static int Allocated() { return _allocated; }
};

#endif
