36 gsAAPolyline(gsVSegment<T> VSeg)
38 std::vector<T> newPoint(2);
39 newPoint[0] = VSeg.getX();
40 newPoint[1] = VSeg.getYDown();
41 m_vertices.push_back( newPoint );
42 newPoint[1] = VSeg.getYUp();
43 m_vertices.push_back( newPoint );
48 std::vector< std::vector< index_t > > writeParasolid();
51 std::vector< std::vector<unsigned int > > writeParasolidUnsigned();
54 inline bool addVerticalSegment(
int x,
int y0,
int y1 )
56 return ((pushBack(x, y0, y1)) ||
57 (pushBack(x, y1, y0)) ||
58 (pushFront(x, y0, y1)) ||
59 (pushFront(x, y1, y0)));
63 inline bool canBeExtended( gsVSegment<T> vert_seg )
65 return addVerticalSegment( vert_seg.getX(), vert_seg.getYDown(), vert_seg.getYUp() );
72 if ( frontY() == backY() )
75 if( frontX() == backX() )
77 m_vertices.pop_back();
78 m_vertices.front()[1] = backY();
79 m_vertices.pop_back();
87 bool mergeWith( gsAAPolyline<T>& other_poly );
89 inline std::list< std::vector<T> > getVertices()
96 return m_vertices.front()[0];
101 return m_vertices.back()[0];
106 return m_vertices.front()[1];
111 return m_vertices.back()[1];
117 std::list< std::vector<T> > m_vertices;
123 bool pushBack( T x, T y0, T y1 );
126 bool pushFront( T x, T y0, T y1 );
130 bool gsAAPolyline<T>::pushBack( T x, T y0, T y1 )
132 if( m_vertices.empty() || (y0 == backY() ))
134 if( m_vertices.empty() || x != backX() )
136 std::vector< T > newVertex (2);
140 m_vertices.push_back( newVertex );
143 m_vertices.push_back( newVertex );
146 m_vertices.back()[1] = y1;
148 m_closed = almostClosed();
157 bool gsAAPolyline<T>::pushFront( T x, T y0, T y1 )
159 if( m_vertices.empty() || y0 == frontY() )
161 if( m_vertices.empty() || x != frontX() )
163 std::vector< T > newVertex (2);
167 m_vertices.push_front( newVertex );
170 m_vertices.push_front( newVertex );
173 m_vertices.front()[1] = y1;
175 m_closed = almostClosed();
183 std::vector< std::vector< index_t > > gsAAPolyline<T>::writeParasolid()
185 std::vector< std::vector< index_t > > result;
187 if( m_vertices.size() < 4 )
189 gsWarn <<
"Function write_parasolid() says: only " << m_vertices.size() <<
" vertices.\n";
193 if( !almostClosed() )
195 gsWarn <<
"Function write_parasolid() says: your curve should be closed but it isn't.";
199 std::vector< index_t > item(4);
202 auto it_fwd = m_vertices.begin();
204 for(
auto it = m_vertices.begin(); it != m_vertices.end(); ++it, ++it_fwd)
206 if( it_fwd == m_vertices.end() )
207 it_fwd = m_vertices.begin();
210 item[0] = std::min( (*it)[0], (*it_fwd)[0] );
211 item[1] = std::min( (*it)[1], (*it_fwd)[1] );
212 item[2] = std::max( (*it)[0], (*it_fwd)[0] );
213 item[3] = std::max( (*it)[1], (*it_fwd)[1] );
215 result.push_back( item );
222 std::vector< std::vector< unsigned int > > gsAAPolyline<T>::writeParasolidUnsigned()
224 std::vector< std::vector<unsigned int > > result;
226 if( m_vertices.size() < 4 )
228 gsWarn <<
"write_parasolid() says: only " << m_vertices.size() <<
" vertices.\n";
232 if( !almostClosed() )
234 gsWarn <<
"write_parasolid() says: your curve should be closed but it isn't.";
238 std::vector< unsigned int > item(4,0);
241 auto it_fwd = m_vertices.begin();
243 for(
auto it = m_vertices.begin(); it != m_vertices.end(); ++it, ++it_fwd)
245 if( it_fwd == m_vertices.end() )
246 it_fwd = m_vertices.begin();
249 item[0] = std::min( (*it)[0], (*it_fwd)[0] );
250 item[1] = std::min( (*it)[1], (*it_fwd)[1] );
251 item[2] = std::max( (*it)[0], (*it_fwd)[0] );
252 item[3] = std::max( (*it)[1], (*it_fwd)[1] );
254 result.push_back( item );
260 bool gsAAPolyline<T>::mergeWith( gsAAPolyline<T>& otherPoly )
263 std::list< std::vector<T> > newVertices;
266 if( otherPoly.backY() == frontY() )
268 newVertices = otherPoly.getVertices();
269 if( newVertices.back() == m_vertices.front() )
271 newVertices.pop_back();
272 m_vertices.pop_front();
274 m_vertices.splice( m_vertices.begin(), newVertices );
275 m_closed = almostClosed();
279 else if( otherPoly.backY() == backY() )
281 newVertices = otherPoly.getVertices();
282 newVertices.reverse();
283 if( newVertices.front() == m_vertices.back() )
285 newVertices.pop_front();
286 m_vertices.pop_back();
288 m_vertices.splice( m_vertices.end(), newVertices );
289 m_closed = almostClosed();
293 else if( otherPoly.frontY() == frontY() )
295 newVertices = otherPoly.getVertices();
296 newVertices.reverse();
297 if( newVertices.back() == m_vertices.front() )
299 newVertices.pop_back();
300 m_vertices.pop_front();
302 m_vertices.splice( m_vertices.begin(), newVertices );
303 m_closed = almostClosed();
307 else if( otherPoly.frontY() == backY() )
309 newVertices = otherPoly.getVertices();
310 if( newVertices.front() == m_vertices.back() )
312 newVertices.pop_front();
313 m_vertices.pop_back();
315 m_vertices.splice( m_vertices.end(), newVertices );
316 m_closed = almostClosed();
Helper class for gsAAPolyline.
#define gsWarn
Definition: gsDebug.h:50