DGtal  0.9.3
Public Member Functions | Protected Attributes
LibBoard::Path Struct Reference

#include <Board/Path.h>

Collaboration diagram for LibBoard::Path:
[legend]

Public Member Functions

 Path ()
 
 Path (const std::vector< Point > &points, bool closedPath)
 
 Path (bool closedPath)
 
void clear ()
 
bool closed () const
 
bool empty () const
 
unsigned int size () const
 
void setClosed (bool closed)
 
Point center () const
 
Pathoperator<< (const Point &p)
 
Pathpop_back ()
 
Pointoperator[] (const unsigned int n)
 
const Pointoperator[] (const unsigned int n) const
 
Pathrotate (double angle, const Point &center)
 
Path rotated (double angle, const Point &center) const
 
Pathrotate (double angle)
 
Path rotated (double angle) const
 
Pathtranslate (double dx, double dy)
 
Path translated (double dx, double dy) const
 
Pathscale (double sx, double sy)
 
Pathscale (double s)
 
Path scaled (double sx, double sy) const
 
Path scaled (double s) const
 
void scaleAll (double s)
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushFIG (std::ostream &stream, const TransformFIG &transform) const
 
void flushSVGPoints (std::ostream &stream, const TransformSVG &transform) const
 
void flushSVGCommands (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairoPoints (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZPoints (std::ostream &stream, const TransformTikZ &transform) const
 
Rect boundingBox () const
 

Protected Attributes

std::vector< Point_points
 
bool _closed
 

Detailed Description

A path, according to Postscript and SVG definition.

The path structure.

Definition at line 43 of file Path.h.

Constructor & Destructor Documentation

◆ Path() [1/3]

LibBoard::Path::Path ( )
inline

Definition at line 45 of file Path.h.

Referenced by scaled().

45 : _closed( false ) { }
bool _closed
Definition: Path.h:227

◆ Path() [2/3]

LibBoard::Path::Path ( const std::vector< Point > &  points,
bool  closedPath 
)
inline

Definition at line 47 of file Path.h.

48  : _points( points ), _closed( closedPath ) { }
std::vector< Point > _points
Definition: Path.h:226
bool _closed
Definition: Path.h:227

◆ Path() [3/3]

LibBoard::Path::Path ( bool  closedPath)
inline

Definition at line 50 of file Path.h.

References center(), clear(), closed(), empty(), operator<<(), pop_back(), setClosed(), and size().

50 : _closed( closedPath ) { }
bool _closed
Definition: Path.h:227

Member Function Documentation

◆ boundingBox()

Rect LibBoard::Path::boundingBox ( ) const

Definition at line 272 of file Path.cpp.

References _points, LibBoard::Rect::height, LibBoard::Rect::left, LibBoard::Rect::top, and LibBoard::Rect::width.

Referenced by center(), operator[](), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), and LibBoard::Board::saveTikZ().

273 {
274  if ( _points.empty() )
275  return Rect( 0, 0, 0, 0 );
276  Rect rect;
277  std::vector< Point >::const_iterator i = _points.begin();
278  std::vector< Point >::const_iterator end = _points.end();
279  rect.top = i->y;
280  rect.left = i->x;
281  rect.width = 0.0;
282  rect.height = 0.0;
283  ++i;
284  while ( i != end ) {
285  if ( i->x < rect.left ) {
286  double dw = rect.left - i->x;
287  rect.left = i->x;
288  rect.width += dw;
289  } else if ( i->x > rect.left + rect.width ) {
290  rect.width = i->x - rect.left;
291  }
292  if ( i->y > rect.top ) {
293  double dh = i->y - rect.top;
294  rect.top = i->y;
295  rect.height += dh;
296  } else if ( i->y < rect.top - rect.height ) {
297  rect.height = rect.top - i->y;
298  }
299  ++i;
300  }
301  return rect;
302 }
std::vector< Point > _points
Definition: Path.h:226

◆ center()

Point LibBoard::Path::center ( ) const

Barycenter of the path

Returns
a point

Definition at line 36 of file Path.cpp.

References boundingBox(), LibBoard::Rect::height, LibBoard::Rect::left, LibBoard::Rect::top, and LibBoard::Rect::width.

Referenced by Path(), rotate(), rotated(), LibBoard::Board::scale(), and scale().

36  {
37  Rect bbox = boundingBox();
38  return Point( bbox.left + bbox.width/2.0,
39  bbox.top - bbox.height/2.0 );
40 }
Rect boundingBox() const
Definition: Path.cpp:272
MyPointD Point
Definition: testClone2.cpp:383

◆ clear()

void LibBoard::Path::clear ( )
inline

Definition at line 231 of file Path.h.

References _points.

Referenced by Path(), LibBoard::Board::setClippingPath(), and LibBoard::Board::setClippingRectangle().

232 {
233  _points.clear();
234 }
std::vector< Point > _points
Definition: Path.h:226

◆ closed()

bool LibBoard::Path::closed ( ) const
inline

Definition at line 237 of file Path.h.

References _closed.

Referenced by Path().

238 {
239  return _closed;
240 }
bool _closed
Definition: Path.h:227

◆ empty()

bool LibBoard::Path::empty ( ) const
inline

Definition at line 243 of file Path.h.

References _points.

Referenced by Path().

244 {
245  return _points.empty();
246 }
std::vector< Point > _points
Definition: Path.h:226

◆ flushCairoPoints()

void LibBoard::Path::flushCairoPoints ( cairo_t *  cr,
const TransformCairo transform 
) const

Definition at line 235 of file Path.cpp.

References _points, LibBoard::Transform::mapX(), and LibBoard::TransformCairo::mapY().

Referenced by operator[]().

237 {
238  if ( _points.empty() )
239  return;
240  std::vector<Point>::const_iterator i = _points.begin();
241  std::vector<Point>::const_iterator end = _points.end();
242  int count = 0;
243  cairo_move_to (cr, transform.mapX( i->x ), transform.mapY( i->y ));
244  ++i;
245  while ( i != end ) {
246  cairo_line_to (cr, transform.mapX( i->x ), transform.mapY( i->y ));
247  ++i;
248  count = ( count + 1 ) % 6;
249  //if ( !count ) stream << "\n ";
250  }
251 }
std::vector< Point > _points
Definition: Path.h:226

◆ flushFIG()

void LibBoard::Path::flushFIG ( std::ostream &  stream,
const TransformFIG transform 
) const

Definition at line 173 of file Path.cpp.

References _closed, _points, LibBoard::Transform::mapX(), and LibBoard::TransformFIG::mapY().

Referenced by operator[]().

175 {
176  if ( _points.empty() )
177  return;
178 
179  std::vector<Point>::const_iterator i = _points.begin();
180  std::vector<Point>::const_iterator end = _points.end();
181  while ( i != end ) {
182  stream << " " << static_cast<int>( transform.mapX( i->x ) )
183  << " " << static_cast<int>( transform.mapY( i->y ) );
184  ++i;
185  }
186  if ( _closed ) {
187  stream << " " << static_cast<int>( transform.mapX( _points.begin()->x ) )
188  << " " << static_cast<int>( transform.mapY( _points.begin()->y ) );
189  }
190 }
std::vector< Point > _points
Definition: Path.h:226
bool _closed
Definition: Path.h:227

◆ flushPostscript()

void LibBoard::Path::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const

Definition at line 154 of file Path.cpp.

References _closed, _points, LibBoard::Transform::mapX(), and LibBoard::TransformEPS::mapY().

Referenced by operator[](), and LibBoard::Board::saveEPS().

156 {
157  if ( _points.empty() )
158  return;
159  std::vector<Point>::const_iterator i = _points.begin();
160  std::vector<Point>::const_iterator end = _points.end();
161 
162  stream << transform.mapX( i->x ) << " " << transform.mapY( i->y ) << " m";
163  ++i;
164  while ( i != end ) {
165  stream << " " << transform.mapX( i->x ) << " " << transform.mapY( i->y ) << " l";
166  ++i;
167  }
168  if ( _closed ) stream << " cp";
169  stream << " ";
170 }
std::vector< Point > _points
Definition: Path.h:226
bool _closed
Definition: Path.h:227

◆ flushSVGCommands()

void LibBoard::Path::flushSVGCommands ( std::ostream &  stream,
const TransformSVG transform 
) const

Definition at line 193 of file Path.cpp.

References _closed, _points, LibBoard::Transform::mapX(), and LibBoard::TransformSVG::mapY().

Referenced by operator[](), LibBoard::Board::saveSVG(), and LibBoard::Board::saveTikZ().

195 {
196  if ( _points.empty() )
197  return;
198  std::vector<Point>::const_iterator i = _points.begin();
199  std::vector<Point>::const_iterator end = _points.end();
200  int count = 0;
201 
202  stream << "M " << transform.mapX( i->x ) << " " << transform.mapY( i->y );
203  ++i;
204  while ( i != end ) {
205  stream << " L " << transform.mapX( i->x ) << " " << transform.mapY( i->y );
206  ++i;
207  count = ( count + 1 ) % 6;
208  if ( !count ) stream << "\n ";
209  }
210  if ( _closed )
211  stream << " Z" << std::endl;
212 }
std::vector< Point > _points
Definition: Path.h:226
bool _closed
Definition: Path.h:227

◆ flushSVGPoints()

void LibBoard::Path::flushSVGPoints ( std::ostream &  stream,
const TransformSVG transform 
) const

Definition at line 215 of file Path.cpp.

References _points, LibBoard::Transform::mapX(), and LibBoard::TransformSVG::mapY().

Referenced by operator[]().

217 {
218  if ( _points.empty() )
219  return;
220  std::vector<Point>::const_iterator i = _points.begin();
221  std::vector<Point>::const_iterator end = _points.end();
222  int count = 0;
223  stream << transform.mapX( i->x ) << "," << transform.mapY( i->y );
224  ++i;
225  while ( i != end ) {
226  stream << " " << transform.mapX( i->x ) << "," << transform.mapY( i->y );
227  ++i;
228  count = ( count + 1 ) % 6;
229  if ( !count ) stream << "\n ";
230  }
231 }
std::vector< Point > _points
Definition: Path.h:226

◆ flushTikZPoints()

void LibBoard::Path::flushTikZPoints ( std::ostream &  stream,
const TransformTikZ transform 
) const

Definition at line 255 of file Path.cpp.

References _points, LibBoard::Transform::mapX(), and LibBoard::TransformSVG::mapY().

Referenced by operator[]().

257 {
258  if ( _points.empty() )
259  return;
260  std::vector<Point>::const_iterator i = _points.begin();
261  std::vector<Point>::const_iterator end = _points.end();
262  stream << '(' << transform.mapX( i->x ) << "," << transform.mapY( i->y ) << ')';
263  ++i;
264  while ( i != end ) {
265  stream << " -- "
266  << '(' << transform.mapX( i->x ) << "," << transform.mapY( i->y ) << ')';
267  ++i;
268  }
269 }
std::vector< Point > _points
Definition: Path.h:226

◆ operator<<()

Path & LibBoard::Path::operator<< ( const Point p)

Add a point at the end of the path.

Parameters
pthe point to add
Returns
a path

Definition at line 29 of file Path.cpp.

References _points.

Referenced by Path().

30 {
31  _points.push_back( p );
32  return *this;
33 }
std::vector< Point > _points
Definition: Path.h:226

◆ operator[]() [1/2]

Point& LibBoard::Path::operator[] ( const unsigned int  n)
inline

Returns the n-th point of the polyline.

Parameters
nn
Returns
a point

Definition at line 92 of file Path.h.

References _points.

92  {
93  return _points[ n ];
94  }
std::vector< Point > _points
Definition: Path.h:226

◆ operator[]() [2/2]

const Point& LibBoard::Path::operator[] ( const unsigned int  n) const
inline

Returns the n-th point of the polyline.

Parameters
nn
Returns
a point

Definition at line 103 of file Path.h.

References _points, boundingBox(), flushCairoPoints(), flushFIG(), flushPostscript(), flushSVGCommands(), flushSVGPoints(), flushTikZPoints(), rotate(), rotated(), scale(), scaleAll(), scaled(), translate(), and translated().

103  {
104  return _points[ n ];
105  }
std::vector< Point > _points
Definition: Path.h:226

◆ pop_back()

Path & LibBoard::Path::pop_back ( )
Returns
path

Definition at line 22 of file Path.cpp.

References _points.

Referenced by Path(), and LibBoard::Board::setClippingPath().

23 {
24  _points.pop_back();
25  return *this;
26 }
std::vector< Point > _points
Definition: Path.h:226

◆ rotate() [1/2]

Path & LibBoard::Path::rotate ( double  angle,
const Point center 
)
Parameters
angleangle
centercenter
Returns
a path

Definition at line 43 of file Path.cpp.

References _points.

Referenced by operator[](), LibBoard::Board::rotate(), rotate(), LibBoard::GouraudTriangle::rotate(), and rotated().

44 {
45  std::vector<Point>::iterator i = _points.begin();
46  std::vector<Point>::iterator end = _points.end();
47  while ( i != end ) {
48  i->rotate( angle, rotCenter );
49  ++i;
50  }
51  return *this;
52 }
std::vector< Point > _points
Definition: Path.h:226

◆ rotate() [2/2]

Path & LibBoard::Path::rotate ( double  angle)
Parameters
angleangle
Returns
a Path

Definition at line 68 of file Path.cpp.

References center(), and rotate().

69 {
70  return Path::rotate( angle, center() );
71 }
Point center() const
Definition: Path.cpp:36
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43

◆ rotated() [1/2]

Path LibBoard::Path::rotated ( double  angle,
const Point center 
) const
Parameters
angleangle
centercenter
Returns
a Path

Definition at line 55 of file Path.cpp.

References _points.

Referenced by operator[]().

56 {
57  Path res(*this);
58  std::vector<Point>::iterator i = res._points.begin();
59  std::vector<Point>::iterator end = res._points.end();
60  while ( i != end ) {
61  i->rotate( angle, rotCenter );
62  ++i;
63  }
64  return res;
65 }

◆ rotated() [2/2]

Path LibBoard::Path::rotated ( double  angle) const
Parameters
angleangle
Returns
rotated path

Definition at line 74 of file Path.cpp.

References center(), and rotate().

75 {
76  Path res(*this);
77  return static_cast<Path&>( res.rotate( angle, center() ) );
78 }
Point center() const
Definition: Path.cpp:36

◆ scale() [1/2]

Path & LibBoard::Path::scale ( double  sx,
double  sy 
)
Parameters
sxscale factor
syscale factor
Returns
scaled path

Definition at line 108 of file Path.cpp.

References _points, center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

Referenced by operator[](), LibBoard::Board::scale(), and scale().

109 {
110  Point c = center();
111  translate( -c.x, -c.y );
112  std::vector<Point>::iterator i = _points.begin();
113  std::vector<Point>::iterator end = _points.end();
114  while ( i != end ) {
115  i->x *= sx;
116  i->y *= sy;
117  ++i;
118  }
119  Point delta = c - center();
120  translate( delta.x, delta.y );
121  return *this;
122 }
Path & translate(double dx, double dy)
Definition: Path.cpp:81
Point center() const
Definition: Path.cpp:36
std::vector< Point > _points
Definition: Path.h:226
MyPointD Point
Definition: testClone2.cpp:383

◆ scale() [2/2]

Path & LibBoard::Path::scale ( double  s)
Parameters
sscale factor
Returns
scaled path

Definition at line 125 of file Path.cpp.

References scale().

126 {
127  return Path::scale( s, s );
128 }
Path & scale(double sx, double sy)
Definition: Path.cpp:108

◆ scaleAll()

void LibBoard::Path::scaleAll ( double  s)

Scales all the points.

Parameters
sThe scaling factor.

Definition at line 143 of file Path.cpp.

References _points.

Referenced by operator[](), and LibBoard::GouraudTriangle::scaleAll().

144 {
145  std::vector<Point>::iterator it = _points.begin();
146  std::vector<Point>::iterator end = _points.end();
147  while ( it != end ) {
148  (*it) *= s;
149  ++it;
150  }
151 }
std::vector< Point > _points
Definition: Path.h:226

◆ scaled() [1/2]

Path LibBoard::Path::scaled ( double  sx,
double  sy 
) const
Parameters
sxscale factor
syscale factor
Returns
a Path

Definition at line 131 of file Path.cpp.

References Path().

Referenced by operator[]().

132 {
133  return Path(*this).scale( sx, sy );
134 }

◆ scaled() [2/2]

Path LibBoard::Path::scaled ( double  s) const

Definition at line 137 of file Path.cpp.

References Path().

138 {
139  return Path(*this).scale( s, s );
140 }

◆ setClosed()

void LibBoard::Path::setClosed ( bool  closed)
inline

Definition at line 255 of file Path.h.

References _closed.

Referenced by Path(), LibBoard::Group::setClippingPath(), and LibBoard::Board::setClippingPath().

256 {
257  _closed = closedPath;
258 }
bool _closed
Definition: Path.h:227

◆ size()

unsigned int LibBoard::Path::size ( ) const
inline

Definition at line 249 of file Path.h.

References _points.

Referenced by Path(), LibBoard::Board::saveCairo(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), LibBoard::Board::saveTikZ(), and LibBoard::Board::setClippingPath().

250 {
251  return (unsigned int)_points.size();
252 }
std::vector< Point > _points
Definition: Path.h:226

◆ translate()

Path & LibBoard::Path::translate ( double  dx,
double  dy 
)
Parameters
dxtranslation vector
dytranslation vector
Returns
translated path

Definition at line 81 of file Path.cpp.

References _points.

Referenced by operator[](), LibBoard::Board::scale(), scale(), and LibBoard::Board::translate().

82 {
83  std::vector<Point>::iterator i = _points.begin();
84  std::vector<Point>::iterator end = _points.end();
85  Point delta( dx, dy );
86  while ( i != end ) {
87  (*i) += delta;
88  ++i;
89  }
90  return *this;
91 }
std::vector< Point > _points
Definition: Path.h:226
MyPointD Point
Definition: testClone2.cpp:383

◆ translated()

Path LibBoard::Path::translated ( double  dx,
double  dy 
) const
Parameters
dxtranslation vector
dytranslation vector
Returns
a Path

Definition at line 94 of file Path.cpp.

References _points.

Referenced by operator[]().

95 {
96  Path res(*this);
97  std::vector<Point>::iterator i = res._points.begin();
98  std::vector<Point>::iterator end = res._points.end();
99  Point delta( dx, dy );
100  while ( i != end ) {
101  (*i) += delta;
102  ++i;
103  }
104  return res;
105 }
MyPointD Point
Definition: testClone2.cpp:383

Field Documentation

◆ _closed

bool LibBoard::Path::_closed
protected

Definition at line 227 of file Path.h.

Referenced by closed(), flushFIG(), flushPostscript(), flushSVGCommands(), and setClosed().

◆ _points

std::vector<Point> LibBoard::Path::_points
protected

The documentation for this struct was generated from the following files: