00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOM_COMPOSITE2_HH
00020 #define GEOM_COMPOSITE2_HH
00021
00022 #include "def.hh"
00023
00024 #include <vector>
00025 #include <algorithm>
00026
00027 #include "circular_iterator.hh"
00028 #include "vec2.hh"
00029
00030 namespace geom {
00031
00033 class DLLEXPORT_OST_GEOM Line2 {
00034 public:
00035 Line2();
00036 Line2(const Vec2& from, const Vec2& to);
00037
00038 Vec2 At(Real r) const;
00039 Vec2 GetOrigin() const;
00040 Vec2 GetDirection() const;
00041 private:
00042 Vec2 ori_,dir_;
00043 };
00044
00045 class DLLEXPORT_OST_GEOM Rectangle2{
00046 public:
00047 Rectangle2();
00048 Rectangle2(Vec2 topleft, Vec2 bottomright);
00049 Real GetWidth() const;
00050 Real GetHeight() const;
00051 Vec2 GetStart() const;
00052 Vec2 GetEnd() const;
00053 void SetStart(const Vec2& v);
00054 void SetEnd(const Vec2& v);
00055 Real GetArea() const;
00056 Vec2 operator[] (unsigned index) const;
00057 Vec2& operator[] (unsigned index);
00058 private:
00059 Vec2 topleft_;
00060 Vec2 bottomright_;
00061 };
00062
00065 class DLLEXPORT_OST_GEOM Polygon2: public std::vector<Vec2>
00066 {
00067 public:
00068 typedef const_circular_iter<Polygon2> const_circular_iterator;
00069 typedef circular_iter<Polygon2> circular_iterator;
00070
00071 Polygon2();
00072 Polygon2(const Polygon2& p);
00073 Polygon2(const std::vector<Vec2>& v);
00074 circular_iterator cbegin(){return circular_iterator(begin(),end());}
00075 circular_iterator cend(){return circular_iterator(begin(),end(),--end());}
00076 const_circular_iterator cbegin() const {return const_circular_iterator(begin(),end());}
00077 const_circular_iterator cend() const {return const_circular_iterator(begin(),end(),--end());}
00078 void AddNode(const Vec2& n){push_back(n);};
00079 unsigned int GetNodeCount() const {return size();};
00080 Vec2 GetNode(unsigned int i) const {return operator[](i);};
00081 void SetNode(unsigned int i,const Vec2& v);
00082 circular_iterator FindSegment(std::vector<Vec2>::const_iterator start,std::vector<Vec2>::const_iterator end);
00083 circular_iterator FindNode(const Vec2& v) {return circular_iterator(begin(),end(),find(begin(),end(),v));}
00084 void Erase(circular_iterator first,circular_iterator last);
00085 Polygon2 operator+(const Vec2& v) const;
00086 Polygon2 operator*(Real d) const;
00087 Real GetArea() const;
00088 Vec2 GetCentroid() const;
00089 void Expand(Real val);
00090 Rectangle2 GetBoundingBox() const;
00091 private:
00092 ;
00093 };
00094
00095 class DLLEXPORT_OST_GEOM Ellipse2
00096 {
00097 public:
00098 Ellipse2();
00099 Ellipse2(Vec2 ori,Real a,Real b,Real gamma);
00100 Vec2 At(Real t) const;
00101 Vec2 AtAngle(Real angle_) const;
00102 Rectangle2 GetBoundingBox() const;
00103 Real GetA() const {return a_;}
00104 Real GetB() const {return b_;}
00105 Real GetGamma() const {return gamma_;}
00106 Real GetArea() const {return a_*b_*M_PI;}
00107 Vec2 GetOrigin() const {return origin_;}
00108 void SetA(Real a) {a_=a;}
00109 void SetB(Real b) {b_=b;}
00110 void SetGamma(Real gamma) {gamma_=gamma;}
00111 void SetOrigin(Vec2 ori) {origin_=ori;}
00112 private:
00113 Vec2 calc_(Real t) const;
00114 Vec2 origin_;
00115 Real a_;
00116 Real b_;
00117 Real gamma_;
00118 };
00119
00120 class DLLEXPORT_OST_GEOM Hyperbola2
00121 {
00122 public:
00123 Hyperbola2();
00124 Hyperbola2(Vec2 ori,Real a,Real b,Real gamma);
00125 Vec2 At(Real t, bool righthalf=true) const;
00126 Real GetA() const {return a_;}
00127 Real GetB() const {return b_;}
00128 Real GetGamma() const {return gamma_;}
00129 Vec2 GetOrigin() const {return origin_;}
00130 void SetA(Real a) {a_=a;}
00131 void SetB(Real b) {b_=b;}
00132 void SetGamma(Real gamma) {gamma_=gamma;}
00133 void SetOrigin(Vec2 ori) {origin_=ori;}
00134 private:
00135 Vec2 origin_;
00136 Real a_;
00137 Real b_;
00138 Real gamma_;
00139 };
00140
00141 class DLLEXPORT_OST_GEOM Circle2
00142 {
00143 public:
00144 Circle2();
00145 Circle2(const Circle2& c);
00146 Circle2(const Vec2& center, Real radius);
00147 void SetCenter(const Vec2& center);
00148 void SetRadius(Real r);
00149 Vec2 GetCenter() const;
00150 Real GetRadius() const;
00151 Real GetCircumference() const;
00152 Real GetArea() const;
00153 protected:
00154 Vec2 center_;
00155 Real radius_;
00156 };
00157
00158 }
00159
00160 #endif
00161
00172
00173