#include #include #include "IMeshEdge.hxx" #include "IMeshPoint.hxx" COMET::IMeshEdge::IMeshEdge(COMET::IMeshPoint* a, COMET::IMeshPoint* b) { if (*a < *b) { fHead = a; fTail = b; } else { fHead = b; fTail = a; } // The edge is not added into the two end points by the constructor. It // will be added to the points by COMET::IMesh::AddEdge, iff they don't already // exist. } COMET::IMeshEdge::~IMeshEdge() { // Remove the edge from the end points so that we don't have any dangling // pointers. Notice that this makes deleting a COMET::IMesh object rather // interesting since a COMET::IMeshPoint will delete it's associated edges when // it is deleted. if (fHead) fHead->RemoveEdge(this); if (fTail) fTail->RemoveEdge(this); } COMET::IMeshPoint* COMET::IMeshEdge::GetOther(const COMET::IMeshPoint* a) const { if (a == fHead) return fTail; if (a == fTail) return fHead; return NULL; } double COMET::IMeshEdge::GetLength(void) const { return GetLength(1.0,1.0); } double COMET::IMeshEdge::GetLength(double xScale, double yScale) const { return std::sqrt(std::pow(xScale*(GetTail()->X() - GetHead()->X()),2) + std::pow(yScale*(GetTail()->Y() - GetHead()->Y()),2)); } bool COMET::IMeshEdge::operator == (const COMET::IMeshEdge& rhs) const { if (fHead != rhs.GetHead()) return false; if (fTail != rhs.GetTail()) return false; return true; } bool COMET::IMeshEdge::operator < (const COMET::IMeshEdge& rhs) const { if (*fHead < *rhs.fHead) return true; if (*rhs.fHead < *fHead) return false; if (*fTail < *rhs.fTail) return true; return false; } std::ostream& operator << (std::ostream& s, COMET::IMeshEdge& e) { s << &e << "->(" << e.GetHead() << ", " << e.GetTail() << ")"; return s; }