#define _tdebug // at some point overload << so that printing is more natural // ************************************** // Header information // ************************************** #include #include #include #include //#include // cannot use this ! #include "tvector.cpp" using namespace tvector; using namespace std; class PlanarStructure; class Node; class LineSegment; // for the purposes of this file, a line segment may not intersect another line segment class DirectedLineSegment; class Edge; class Tile; class Face; typedef PlanarStructure * PlanarStructurePtr; typedef Node * NodePtr; typedef LineSegment * LineSegmentPtr; typedef DirectedLineSegment * DirectedLineSegmentPtr; typedef Edge * EdgePtr; typedef Tile * TilePtr; typedef Face * FacePtr; typedef vector PlanarStructureSet; typedef vector NodeSet; typedef vector LineSegmentSet; typedef vector DirectedLineSegmentSet; typedef vector EdgeSet; typedef vector TileSet; typedef vector FaceSet; typedef NodeSet * NodeSetPtr; typedef LineSegmentSet * LineSegmentSetPtr; typedef DirectedLineSegmentSet * DirectedLineSegmentSetPtr; typedef EdgeSet * EdgeSetPtr; typedef TileSet * TileSetPtr; typedef FaceSet * FaceSetPtr; // ************************************** // Constants (header) // ************************************** const unsigned int kMaximumNameLength = 31; // replace with C++ strings // if the area of the triangle formed by three points is less than kLineThreshold, we consider them to be on a straight line const double kLineThreshold = 0.00001; const char kCommentStart = '#'; const char kCommentEnd = '\n'; // ************************************** // Class definitions (header) // ************************************** class Error { public: Error(const char descript[], const bool f = true) { description = new string(descript); fatal = f; } Error(const string descript, const bool f = true) { description = new string(descript); fatal = f; } string *Description() { return description; } bool isFatal() { return fatal; } private: string *description; bool fatal; }; class PlanarStructure { public: bool IsCalled(const string); string Name(); protected: string name; unsigned int LoadName(ifstream &); }; class LineSegment { public: LineSegment() { start = finish = NULL; } LineSegment(const NodePtr, const NodePtr); bool Intersects(const LineSegmentPtr, float &, float &, bool &, float &, float &, NodeSetPtr); bool Includes(const NodePtr); void ResolveStartNode(NodeSetPtr); NodePtr Start() { return start; } NodePtr Finish() { return finish; } protected: // private members double Area(const NodePtr, const NodePtr, const NodePtr); bool Vertical(); double YIntercept(); double Gradient(); bool NodeExists(double, double, NodeSetPtr); // private data NodePtr start, finish; }; class Edge : public PlanarStructure { public: Edge(ifstream &, NodeSetPtr, EdgeSetPtr) throw (Error); void ResolveEquatedNodes(NodeSetPtr); NodePtr Start(); NodePtr Finish(); protected: // private members bool Intersects(const EdgePtr, float &, float &, LineSegmentPtr &, bool &, float &, float &, NodeSetPtr); bool LiesOnMe(const NodePtr, LineSegmentPtr &); LineSegmentPtr SplitAt(const NodePtr, LineSegmentPtr &, const NodePtr=NULL); NodePtr LoadNode(ifstream &, NodeSetPtr) throw (Error); bool CheckNameForDuplication(EdgeSetPtr) throw (Error); unsigned int CalculateTileSet(EdgeSetPtr, TileSetPtr); unsigned int CalculateAllDirectedLineSegments(DirectedLineSegmentSetPtr DLS); LineSegmentSetPtr Segments(); unsigned int CalculateAllDirectedLineSegments(DirectedLineSegmentSetPtr, EdgeSetPtr); unsigned int LineSegmentsStartingAt(NodePtr, DirectedLineSegmentSetPtr, DirectedLineSegmentSetPtr); DirectedLineSegmentPtr SmallestAngle(DirectedLineSegmentPtr, DirectedLineSegmentSetPtr); bool TileSetContains(TileSetPtr, TilePtr); bool CheckForIdenticalEdges(EdgeSetPtr); bool CheckForNodesOnThisEdge(NodeSetPtr); bool CheckForIntersections(NodeSetPtr, EdgeSetPtr); // private data LineSegmentSetPtr segments; NodePtr start, finish; EdgePtr equatedTo; }; class Node : public PlanarStructure { friend bool operator==(Node &, Node &); public: Node(ifstream &, NodeSetPtr) throw(Error); Node(const float, const float, NodeSetPtr); double X(); double Y(); private: // private members NodePtr equatedTo; bool CheckNameForDuplication(NodeSetPtr) throw (Error); bool CheckForIdenticalNodes(NodeSetPtr); NodePtr ResolveEquatedNodes(NodeSetPtr, bool &); // private data double x,y; }; class DirectedLineSegment { public: DirectedLineSegment(LineSegmentPtr, bool); private: // private data bool direction; // true = start to finish, false = finish to start LineSegment line; }; class Tile : public PlanarStructure { public: Tile(); void AddEdge(DirectedLineSegmentPtr); private: // private data DirectedLineSegmentSet edges; }; class Face : public PlanarStructure { public: Face(ifstream &, const EdgeSetPtr, FaceSetPtr); TileSetPtr Tiles(); private: // private members void CheckNameForDuplication(FaceSetPtr); void LoadEdges(ifstream &, EdgeSetPtr, const EdgeSetPtr) throw(Error); EdgePtr LoadEdge(ifstream &, EdgeSetPtr) throw(Error); unsigned int ConvertToTileSet(const EdgeSetPtr, TileSetPtr); // private data TileSetPtr tiles; }; // ************************************** // Function Definitions (header) // ************************************** // input void ParseDataFile(ifstream &, NodeSetPtr, EdgeSetPtr, TileSetPtr, FaceSetPtr); unsigned int LoadNodes(ifstream &, NodeSetPtr) throw(Error); unsigned int LoadEdges(ifstream &, NodeSetPtr, EdgeSetPtr, TileSetPtr); unsigned int LoadFaces(ifstream &, EdgeSetPtr, FaceSetPtr); // output void OutputDataFile(ofstream &, NodeSetPtr, EdgeSetPtr, TileSetPtr, FaceSetPtr); //void OutputNodeSet(ofstream &, NodeSetPtr); // overload ! //void OutputEdgeSet(ofstream &, EdgeSetPtr); //void OutputTileSet(ofstream &, TileSetPtr); //void OutputFaceSet(ofstream &, FaceSetPtr); // other void ResolveEquatedNodes(NodeSetPtr, EdgeSetPtr); void ResolveEquatedEdges(EdgeSetPtr); #include "helpful.cpp" #include "minmax.cpp"