G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsVSegment.h
Go to the documentation of this file.
1
14#pragma once
15
16namespace gismo
17{
18
25template<class T>
27{
28public:
30 //gsVSegment() { }
31
33 gsVSegment(int x, int bottomY, int upperY, bool l)
34 {
35 m_x = x;
36 m_y = std::pair<int, int> (bottomY, upperY);
37 left = l;
38 }
39
41 //~gsVSegment() { }
42
45 bool isClosing(const gsVSegment& other) const;
46
49 bool isConnected(const gsVSegment& other) const;
50
51 T length() const;
52
56
57 // getters
58
59 inline T getX() const
60 {
61 return m_x;
62 }
63
64 inline T getYUp() const
65 {
66 return m_y.second;
67 }
68
69 inline T getYDown() const
70 {
71 return m_y.first;
72 }
73
74 inline std::pair<T,T> getY() const
75 {
76 return m_y;
77 }
78
79 // setters
80
81 inline void setX( const T& new_x )
82 {
83 m_x = new_x;
84 }
85
86 inline void setYUp( const T& new_y_up )
87 {
88 m_y.second = new_y_up;
89 }
90
91 inline void setYDown( const T& new_y_down )
92 {
93 m_y.first = new_y_down;
94 }
95
96 inline void setY( const std::pair<T,T>& new_m_y )
97 {
98 m_y = new_m_y;
99 }
100
101 bool operator< (const gsVSegment<T>& other) const
102 {
103 if(m_x == other.getX())
104 {
105 return m_y.first < other.getYDown();
106 }
107 else
108 {
109 return m_x < other.getX();
110 }
111 }
112
113 bool operator== ( const gsVSegment<T>& other ) const
114 {
115 if( (m_x == other.getX() ) && (m_y.first == other.getYDown() ) && (m_y.second == other.getYUp() ) )
116 return true;
117 else
118 return false;
119 }
120
121protected:
122
125
127 std::pair<T, T> m_y;
128
130 bool left;
131};
132
133template<class T>
134bool gsVSegment<T>::isClosing(const gsVSegment& other ) const
135{
136 return ( ( other.getYDown() == m_y.first) && (( other.getYUp() == m_y.second)) );
137}
138
139template<class T>
140bool gsVSegment<T>::isConnected(const gsVSegment& other ) const
141{
142 return ( ( other.getYUp() == m_y.first) || (( other.getYDown() == m_y.second)) );
143}
144
145template<class T>
146T gsVSegment<T>::length() const
147{
148 return (m_y.second - m_y.first);
149}
150
151template<class T>
153{
154 gsVSegment<T> tempa = *this;
155 gsVSegment<T> tempb = other;
156 std::vector<T> v(4);
157
158 v[0] = m_y.first;
159 v[1] = m_y.second;
160 v[2] = other.m_y.first;
161 v[3] = other.m_y.second;
162
163 // This is the key trick:
164 std::sort(v.begin(), v.end());
165
166 m_y.first = v[0];
167 m_y.second = v[1];
168 other.m_y.first = v[2];
169 other.m_y.second = v[3];
170
171 // iff nothing changed (or just swapped), return true
172 if( ((tempa==*this)&&(tempb==other)) || ((tempa==other)&&(tempb==*this)))
173 return true;
174 else
175 return false;
176}
177
179template<class T>
180std::ostream &operator<<(std::ostream &os, const gsVSegment<T> a)
181{
182 os<<"x:"<<a.getX() <<" , y: ["<< a.getYDown() <<" ,"<< a.getYUp() <<"] ";
183 return os;
184}
185
186} // namespace gismo
Class for representing a vertical line segment in 2D. Helper for the class gsAAPolyline.
Definition gsVSegment.h:27
gsVSegment(int x, int bottomY, int upperY, bool l)
Default empty constructor.
Definition gsVSegment.h:33
bool isConnected(const gsVSegment &other) const
Definition gsVSegment.h:140
bool isClosing(const gsVSegment &other) const
Default destructor.
Definition gsVSegment.h:134
bool cannotDeleteOverlap(gsVSegment< T > &other)
otherwise gets rid of their overlap and returns false.
Definition gsVSegment.h:152
std::pair< T, T > m_y
Lower and upper y–coordinates.
Definition gsVSegment.h:127
bool left
Whether the segment is on the left hand-side of the enclosed domain.
Definition gsVSegment.h:130
T m_x
The x-coordinate.
Definition gsVSegment.h:124
The G+Smo namespace, containing all definitions for the library.