OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
47  Rectangle2();
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 
71  Polygon2();
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));}
84  void Erase(circular_iterator first,circular_iterator last);
85  Polygon2 operator+(const Vec2& v) const;
86  Polygon2 operator*(Real d) const;
87  Real GetArea() const;
88  Vec2 GetCentroid() const;
89  void Expand(Real val);
90  Rectangle2 GetBoundingBox() const;
91 private:
92  ;
93 };
94 
96 {
97 public:
98  Ellipse2();
99  Ellipse2(Vec2 ori,Real a,Real b,Real gamma);
100  Vec2 At(Real t) const;
101  Vec2 AtAngle(Real angle_) const;
102  Rectangle2 GetBoundingBox() 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:
123  Hyperbola2();
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:
144  Circle2();
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;
151  Real GetCircumference() const;
152  Real GetArea() const;
153 protected:
156 };
157 
158 } // ns
159 
160 #endif
161 
172 
173 
void SetB(Real b)
Definition: composite2.hh:131
circular_iter< Polygon2 > circular_iterator
Definition: composite2.hh:69
Vec2 GetOrigin() const
Definition: composite2.hh:129
void SetOrigin(Vec2 ori)
Definition: composite2.hh:111
float Real
Definition: base.hh:44
const_circular_iter< Polygon2 > const_circular_iterator
Definition: composite2.hh:68
Vec2 operator*(const Vec2 &v, const Mat2 &m)
vector matrix multiplication
Definition: vecmat2_op.hh:99
Vec2 GetNode(unsigned int i) const
Definition: composite2.hh:80
DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle &h, Real v)
void AddNode(const Vec2 &n)
Definition: composite2.hh:78
Real GetB() const
Definition: composite2.hh:104
pointer_it< T > end(const std::vector< T > &values)
Real GetArea() const
Definition: composite2.hh:106
pointer_it< T > begin(const std::vector< T > &values)
void SetGamma(Real gamma)
Definition: composite2.hh:110
const_circular_iterator cbegin() const
Definition: composite2.hh:76
Real GetGamma() const
Definition: composite2.hh:128
const_circular_iterator cend() const
Definition: composite2.hh:77
circular_iterator FindNode(const Vec2 &v)
Definition: composite2.hh:83
Vec2 GetOrigin() const
Definition: composite2.hh:107
Real GetB() const
Definition: composite2.hh:127
Real GetGamma() const
Definition: composite2.hh:105
Real GetA() const
Definition: composite2.hh:103
void SetA(Real a)
Definition: composite2.hh:108
circular_iterator cbegin()
Definition: composite2.hh:74
Real GetA() const
Definition: composite2.hh:126
void SetA(Real a)
Definition: composite2.hh:130
Line2.
Definition: composite2.hh:33
unsigned int GetNodeCount() const
Definition: composite2.hh:79
circular_iterator cend()
Definition: composite2.hh:75
void SetOrigin(Vec2 ori)
Definition: composite2.hh:133
void SetGamma(Real gamma)
Definition: composite2.hh:132
#define DLLEXPORT_OST_GEOM
void SetB(Real b)
Definition: composite2.hh:109