OpenStructure
composite2.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef GEOM_COMPOSITE2_HH
20 #define GEOM_COMPOSITE2_HH
21 
22 #include "def.hh"
23 
24 #include <vector>
25 #include <algorithm>
26 
27 #include "circular_iterator.hh"
28 #include "vec2.hh"
29 
30 namespace geom {
31 
34 public:
35  Line2();
36  Line2(const Vec2& from, const Vec2& to);
37 
38  Vec2 At(Real r) const;
39  Vec2 GetOrigin() const;
40  Vec2 GetDirection() const;
41 private:
42  Vec2 ori_,dir_;
43 };
44 
46 public:
48  Rectangle2(Vec2 topleft, Vec2 bottomright);
49  Real GetWidth() const;
50  Real GetHeight() const;
51  Vec2 GetStart() const;
52  Vec2 GetEnd() const;
53  void SetStart(const Vec2& v);
54  void SetEnd(const Vec2& v);
55  Real GetArea() const;
56  Vec2 operator[] (unsigned index) const;
57  Vec2& operator[] (unsigned index);
58 private:
59  Vec2 topleft_;
60  Vec2 bottomright_;
61 };
62 
65 class DLLEXPORT_OST_GEOM Polygon2: public std::vector<Vec2>
66 {
67 public:
70 
72  Polygon2(const Polygon2& p);
73  Polygon2(const std::vector<Vec2>& v);
78  void AddNode(const Vec2& n){push_back(n);};
79  unsigned int GetNodeCount() const {return size();};
80  Vec2 GetNode(unsigned int i) const {return operator[](i);};
81  void SetNode(unsigned int i,const Vec2& v);
82  circular_iterator FindSegment(std::vector<Vec2>::const_iterator start,std::vector<Vec2>::const_iterator end);
83  circular_iterator FindNode(const Vec2& v) {return circular_iterator(begin(),end(),find(begin(),end(),v));}
85  Polygon2 operator+(const Vec2& v) const;
87  Real GetArea() const;
88  Vec2 GetCentroid() const;
89  void Expand(Real val);
91 private:
92  ;
93 };
94 
96 {
97 public:
99  Ellipse2(Vec2 ori,Real a,Real b,Real gamma);
100  Vec2 At(Real t) const;
101  Vec2 AtAngle(Real angle_) const;
103  Real GetA() const {return a_;}
104  Real GetB() const {return b_;}
105  Real GetGamma() const {return gamma_;}
106  Real GetArea() const {return a_*b_*M_PI;}
107  Vec2 GetOrigin() const {return origin_;}
108  void SetA(Real a) {a_=a;}
109  void SetB(Real b) {b_=b;}
110  void SetGamma(Real gamma) {gamma_=gamma;}
111  void SetOrigin(Vec2 ori) {origin_=ori;}
112 private:
113  Vec2 calc_(Real t) const;
114  Vec2 origin_;
115  Real a_;
116  Real b_;
117  Real gamma_;
118 };
119 
121 {
122 public:
124  Hyperbola2(Vec2 ori,Real a,Real b,Real gamma);
125  Vec2 At(Real t, bool righthalf=true) const;
126  Real GetA() const {return a_;}
127  Real GetB() const {return b_;}
128  Real GetGamma() const {return gamma_;}
129  Vec2 GetOrigin() const {return origin_;}
130  void SetA(Real a) {a_=a;}
131  void SetB(Real b) {b_=b;}
132  void SetGamma(Real gamma) {gamma_=gamma;}
133  void SetOrigin(Vec2 ori) {origin_=ori;}
134 private:
135  Vec2 origin_;
136  Real a_;
137  Real b_;
138  Real gamma_;
139 };
140 
142 {
143 public:
145  Circle2(const Circle2& c);
146  Circle2(const Vec2& center, Real radius);
147  void SetCenter(const Vec2& center);
148  void SetRadius(Real r);
149  Vec2 GetCenter() const;
150  Real GetRadius() const;
152  Real GetArea() const;
153 protected:
156 };
157 
158 } // ns
159 
160 #endif
161 
172 
173 
Vec2 GetCenter() const
void SetCenter(const Vec2 &center)
Real GetRadius() const
Circle2(const Circle2 &c)
void SetRadius(Real r)
Real GetCircumference() const
Circle2(const Vec2 &center, Real radius)
Real GetArea() const
void SetOrigin(Vec2 ori)
Definition: composite2.hh:111
Vec2 GetOrigin() const
Definition: composite2.hh:107
Real GetGamma() const
Definition: composite2.hh:105
void SetA(Real a)
Definition: composite2.hh:108
Real GetA() const
Definition: composite2.hh:103
Rectangle2 GetBoundingBox() const
Vec2 AtAngle(Real angle_) const
Vec2 At(Real t) const
void SetGamma(Real gamma)
Definition: composite2.hh:110
Ellipse2(Vec2 ori, Real a, Real b, Real gamma)
Real GetArea() const
Definition: composite2.hh:106
Real GetB() const
Definition: composite2.hh:104
void SetB(Real b)
Definition: composite2.hh:109
void SetOrigin(Vec2 ori)
Definition: composite2.hh:133
Vec2 GetOrigin() const
Definition: composite2.hh:129
Real GetGamma() const
Definition: composite2.hh:128
void SetA(Real a)
Definition: composite2.hh:130
Real GetA() const
Definition: composite2.hh:126
Hyperbola2(Vec2 ori, Real a, Real b, Real gamma)
void SetGamma(Real gamma)
Definition: composite2.hh:132
Vec2 At(Real t, bool righthalf=true) const
Real GetB() const
Definition: composite2.hh:127
void SetB(Real b)
Definition: composite2.hh:131
Line2.
Definition: composite2.hh:33
Vec2 GetOrigin() const
Vec2 At(Real r) const
Line2(const Vec2 &from, const Vec2 &to)
Vec2 GetDirection() const
void AddNode(const Vec2 &n)
Definition: composite2.hh:78
circular_iterator cend()
Definition: composite2.hh:75
Polygon2(const Polygon2 &p)
circular_iterator FindSegment(std::vector< Vec2 >::const_iterator start, std::vector< Vec2 >::const_iterator end)
Vec2 GetCentroid() const
void SetNode(unsigned int i, const Vec2 &v)
Vec2 GetNode(unsigned int i) const
Definition: composite2.hh:80
circular_iter< Polygon2 > circular_iterator
Definition: composite2.hh:69
unsigned int GetNodeCount() const
Definition: composite2.hh:79
Rectangle2 GetBoundingBox() const
const_circular_iterator cend() const
Definition: composite2.hh:77
void Erase(circular_iterator first, circular_iterator last)
const_circular_iter< Polygon2 > const_circular_iterator
Definition: composite2.hh:68
circular_iterator FindNode(const Vec2 &v)
Definition: composite2.hh:83
const_circular_iterator cbegin() const
Definition: composite2.hh:76
Polygon2 operator+(const Vec2 &v) const
circular_iterator cbegin()
Definition: composite2.hh:74
Real GetArea() const
Polygon2 operator*(Real d) const
void Expand(Real val)
Polygon2(const std::vector< Vec2 > &v)
Real GetWidth() const
Vec2 GetStart() const
Rectangle2(Vec2 topleft, Vec2 bottomright)
Real GetHeight() const
Vec2 GetEnd() const
Real GetArea() const
void SetStart(const Vec2 &v)
void SetEnd(const Vec2 &v)
#define DLLEXPORT_OST_GEOM
float Real
Definition: base.hh:44
pointer_it< T > end(const std::vector< T > &values)
pointer_it< T > begin(const std::vector< T > &values)