DGtal  1.5.beta
LibBoard::Path Struct Reference

A path, according to Postscript and SVG definition. More...

#include <Board/Path.h>

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
 
Path & operator<< (const Point &p)
 
Path & pop_back ()
 
Point & operator[] (const unsigned int n)
 
const Point & operator[] (const unsigned int n) const
 
Path & rotate (double angle, const Point &center)
 
Path rotated (double angle, const Point &center) const
 
Path & rotate (double angle)
 
Path rotated (double angle) const
 
Path & translate (double dx, double dy)
 
Path translated (double dx, double dy) const
 
Path & scale (double sx, double sy)
 
Path & scale (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.

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

Referenced by scaled().

◆ 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

◆ Path() [3/3]

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

Definition at line 50 of file Path.h.

50 : _closed( closedPath ) { }

Member Function Documentation

◆ boundingBox()

Rect LibBoard::Path::boundingBox ( ) const

Definition at line 272 of file Path.cpp.

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 }

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

◆ center()

Point LibBoard::Path::center ( ) const

Barycenter of the path

Returns
a point

Definition at line 36 of file Path.cpp.

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

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

◆ clear()

void LibBoard::Path::clear ( )
inline

◆ closed()

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

Definition at line 237 of file Path.h.

238 {
239  return _closed;
240 }

References _closed.

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

◆ empty()

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

◆ flushCairoPoints()

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

Definition at line 235 of file Path.cpp.

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 }

References _points.

Referenced by LibBoard::Polyline::flushCairo().

◆ flushFIG()

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

Definition at line 173 of file Path.cpp.

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 }

References _closed, and _points.

Referenced by LibBoard::Polyline::flushFIG(), LibBoard::Rectangle::flushFIG(), and LibBoard::Image::flushFIG().

◆ flushPostscript()

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

Definition at line 154 of file Path.cpp.

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 }

References _closed, and _points.

Referenced by LibBoard::Group::flushPostscript(), LibBoard::Polyline::flushPostscript(), and LibBoard::Board::saveEPS().

◆ flushSVGCommands()

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

Definition at line 193 of file Path.cpp.

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 }

References _closed, and _points.

Referenced by LibBoard::Group::flushSVG(), LibBoard::Board::saveSVG(), and LibBoard::Board::saveTikZ().

◆ flushSVGPoints()

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

Definition at line 215 of file Path.cpp.

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 }

References _points.

Referenced by LibBoard::Polyline::flushSVG().

◆ flushTikZPoints()

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

Definition at line 255 of file Path.cpp.

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 }

References _points.

Referenced by LibBoard::Polyline::flushTikZ().

◆ 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 28 of file Path.cpp.

30 {
31  _points.push_back( p );
32  return *this;
33 }

References _points.

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

92  {
93  return _points[ n ];
94  }

References _points.

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

103  {
104  return _points[ n ];
105  }

References _points.

◆ pop_back()

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

Definition at line 22 of file Path.cpp.

23 {
24  _points.pop_back();
25  return *this;
26 }

References _points.

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

◆ rotate() [1/2]

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

Definition at line 68 of file Path.cpp.

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

References center(), and rotate().

◆ rotate() [2/2]

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

Definition at line 43 of file Path.cpp.

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 }

References _points.

Referenced by rotate(), LibBoard::Board::rotate(), LibBoard::Group::rotate(), LibBoard::Polyline::rotate(), and LibBoard::GouraudTriangle::rotate().

◆ rotated() [1/2]

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

Definition at line 74 of file Path.cpp.

75 {
76  Path res(*this);
77  return static_cast<Path&>( res.rotate( angle, center() ) );
78 }

References center().

◆ rotated() [2/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.

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 }

◆ scale() [1/2]

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

Definition at line 125 of file Path.cpp.

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

References scale().

◆ scale() [2/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.

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

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

Referenced by scale(), LibBoard::Board::scale(), LibBoard::Group::scale(), and LibBoard::Polyline::scale().

◆ scaleAll()

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

Scales all the points.

Parameters
sThe scaling factor.

Definition at line 143 of file Path.cpp.

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 }

References _points.

Referenced by LibBoard::Polyline::scaleAll(), LibBoard::Rectangle::scaleAll(), and LibBoard::GouraudTriangle::scaleAll().

◆ scaled() [1/2]

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

Definition at line 137 of file Path.cpp.

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

References Path().

◆ scaled() [2/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.

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

References Path().

◆ setClosed()

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

Definition at line 255 of file Path.h.

256 {
257  _closed = closedPath;
258 }

References _closed.

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

◆ size()

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

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 }

References _points.

Referenced by LibBoard::Board::scale(), scale(), LibBoard::Group::scale(), LibBoard::Board::translate(), LibBoard::Group::translate(), and LibBoard::Polyline::translate().

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

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

◆ _closed

bool LibBoard::Path::_closed
protected

Definition at line 227 of file Path.h.

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

◆ _points


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