// SurfPolygon.h #ifndef SurfPolygon_H #define SurfPolygon_H // ZPlane with trapezoid boundaries. // DLA 14oct98 // answered by SK 09nov99 // This class is in a pretty bad state. // // 1. It is called SurfPolygon but the above comment implies it only // works for trapezoids, not arbitrary polygons. // Which is it? // // It's for any convex surface . And it never says anything about trapezoids // // 2. Boundary vertices are specified as objects of type polygon::Pair. // The name pair is not descriptive and the introduction of a namespace // to be used only within this class is not appropriate. // // Pair means X,Y coordinate pair. And namespace is defined in header file // and is used not only in this class but in any class that creates // SurfPolygon and there is nothing wrong in using namespace in such a manner // Since there are many representations of Points I wanted mine to be in a // unique namespace // // 3. There is no method to return the vertices of the boundary. // // There is none. But I never meant having it since why would you need it? // If somebody ever needed it I'd created one for him, but I didn't want to // face a question who would manage pointers to pairs. I keep them in an // array of bare pointers for a faster access. // // 4. There are three attributes: _plist, _size and where. Apparently // _plist is an array holding the vertices. I assume _size is the length // of the array. I have no idea what where is. // // They are private atributes. You are not supposed to know what they mean. // But if curious, polygon vertexes can be given in a clockwise or // counterclockwise order, and _where remembers this order. It is set // automatically in the constructor. // // I am adding a new constructor and method to return the vertices. // Both use vector to specify the boundary points. // // The constructor you added already existed. I don't understand why do we need // two of them. I can't create a new contructer for any representaion of a // point, i chose one if it's a bad choice I can switch to another. But having // two of them is wrong. #include "SurfZPlane.h" #include #include "ref_count/RefCounter.hpp" #include "ptr/Ptr.h" #include "ptr/LocalSharedDeletePolicy.h" #include "spacegeom/TwoSpacePoint.h" #define MAXPOINTS 100 //************************ // // Helper // //******************** namespace trf { class SurfPolygon; namespace polygon{ class Pair; std::ostream& operator<<(std::ostream& stream, const Pair& pr); class Pair : public RefCounter { protected: double _x; double _y; public: Pair(double x,double y) ; Pair(const Pair& pr) ; Pair& operator=(const Pair&pr) ; bool operator==(const Pair&) const; bool operator!=(const Pair&) const; inline double x() const ; inline double y() const ; friend std::ostream& operator<<(std::ostream& stream, const Pair& pr); friend class trf::SurfPolygon; }; typedef Ptr PairPtr; #ifndef DEFECT_NO_STDLIB_NAMESPACES typedef std::vector PairList; #else typedef vector PairList; #endif inline double Pair::x() const {return _x;} inline double Pair::y() const {return _y;} } //*************************************************** class SurfPolygon : public SurfZPlane { public: enum {UP=0,DOWN=1,ON=2,UNDEFINED=3}; public: // Return the type name. static TypeName get_type_name() { return "SurfPolygon"; } // Return the creator. static ObjCreator get_creator(); // Return the type. static Type get_static_type() { return get_creator(); } private: polygon::Pair* _plist[MAXPOINTS]; int where; int _size; // output stream void ostr(std::ostream& stream) const; // equality bool safe_bound_equal(const Surface& srf) const; // calculate crossing status from VTrack and error in (x,y)_track // This is used by both the public status methods. CrossStat status(const VTrack& trv, double dx, double dy) const; private: // constructor SurfPolygon(double zpos, polygon::Pair* const [MAXPOINTS],const int _where, const int size); void check(); // Adds point to polygon void add_point(double x,double y); public: // constructor SurfPolygon(double zpos,const polygon::PairList& plist); // destructor virtual ~SurfPolygon() ; // return type Type get_type() const { return get_static_type(); }; // Write the object data. ObjData write_data() const; // clone Surface* new_surface() const; // calculate crossing status CrossStat status(const VTrack& trv) const; CrossStat status(const ETrack& trv) const; // Following added by DLA public: // List of boundary vertices. #ifndef DEFECT_NO_STDLIB_NAMESPACES typedef std::vector Points; #else typedef vector Points; #endif // Constructor. SurfPolygon(double zpos, const Points& pts); // Return the boundary vertices. Points get_vertices() const; // End added by dla }; typedef Ptr SurfPolygonPtr; } // end namespace trf #endif