DGtal  0.9.4beta
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

LibBoard::Path::Path ( )
inline

Definition at line 45 of file Path.h.

Referenced by scaled().

45 : _closed( false ) { }
bool _closed
Definition: Path.h:227
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
LibBoard::Path::Path ( bool  closedPath)
inline

Definition at line 50 of file Path.h.

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

Member Function Documentation

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 LibBoard::Group::boundingBox(), LibBoard::Polyline::boundingBox(), center(), 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
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 LibBoard::Polyline::center(), rotate(), rotated(), LibBoard::Board::scale(), scale(), and LibBoard::Group::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
void LibBoard::Path::clear ( )
inline

Definition at line 231 of file Path.h.

References _points.

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

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

Definition at line 237 of file Path.h.

References _closed.

Referenced by LibBoard::Polyline::flushCairo(), LibBoard::Polyline::flushFIG(), LibBoard::Polyline::flushSVG(), and LibBoard::Polyline::flushTikZ().

238 {
239  return _closed;
240 }
bool _closed
Definition: Path.h:227
bool LibBoard::Path::empty ( ) const
inline

Definition at line 243 of file Path.h.

References _points.

Referenced by LibBoard::Polyline::flushCairo(), LibBoard::Polyline::flushFIG(), LibBoard::Polyline::flushPostscript(), LibBoard::Polyline::flushSVG(), and LibBoard::Polyline::flushTikZ().

244 {
245  return _points.empty();
246 }
std::vector< Point > _points
Definition: Path.h:226
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 LibBoard::Polyline::flushCairo().

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
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 LibBoard::Polyline::flushFIG(), LibBoard::Rectangle::flushFIG(), and LibBoard::Image::flushFIG().

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
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 LibBoard::Group::flushPostscript(), LibBoard::Polyline::flushPostscript(), 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
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 LibBoard::Group::flushSVG(), 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
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 LibBoard::Polyline::flushSVG().

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
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 LibBoard::Polyline::flushTikZ().

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
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.

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

103  {
104  return _points[ n ];
105  }
std::vector< Point > _points
Definition: Path.h:226
Path & LibBoard::Path::pop_back ( )
Returns
path

Definition at line 22 of file Path.cpp.

References _points.

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

23 {
24  _points.pop_back();
25  return *this;
26 }
std::vector< Point > _points
Definition: Path.h:226
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 LibBoard::Board::rotate(), rotate(), LibBoard::Group::rotate(), LibBoard::Polyline::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
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
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.

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 }
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
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 LibBoard::Board::scale(), scale(), LibBoard::Group::scale(), and LibBoard::Polyline::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
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
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 LibBoard::Polyline::scaleAll(), LibBoard::Rectangle::scaleAll(), 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
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().

132 {
133  return Path(*this).scale( sx, sy );
134 }
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 }
void LibBoard::Path::setClosed ( bool  closed)
inline

Definition at line 255 of file Path.h.

References _closed.

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

256 {
257  _closed = closedPath;
258 }
bool _closed
Definition: Path.h:227
unsigned int LibBoard::Path::size ( ) const
inline
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 LibBoard::Board::scale(), scale(), LibBoard::Group::scale(), LibBoard::Board::translate(), LibBoard::Group::translate(), and LibBoard::Polyline::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
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.

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 }

Field Documentation

bool LibBoard::Path::_closed
protected

Definition at line 227 of file Path.h.

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

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

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