26 #ifndef _BOARD_SHAPES_H_
27 #define _BOARD_SHAPES_H_
43 #define M_PI 3.14159265358979323846
47 #define M_PI_2 1.57079632679489661923
58 enum LineCap { ButtCap = 0, RoundCap, SquareCap };
59 enum LineJoin { MiterJoin = 0, RoundJoin, BevelJoin };
60 enum LineStyle { SolidStyle = 0,
92 virtual const std::string &
name()
const;
191 virtual Shape &
scale(
double sx,
double sy ) = 0;
236 virtual void scaleAll(
double s ) = 0;
255 virtual void flushFIG( std::ostream & stream,
257 std::map<Color,int> & colormap )
const = 0;
265 virtual void flushSVG( std::ostream & stream,
274 virtual void flushTikZ( std::ostream & stream,
277 inline int depth()
const;
279 virtual void depth(
int );
281 virtual void shiftDepth(
int shift );
283 inline const Color & penColor()
const;
285 inline const Color & fillColor()
const;
289 static const std::string _name;
336 inline Dot(
double x,
double y,
346 const std::string &
name()
const;
416 Dot &
scale(
double sx,
double sy );
437 Dot scaled(
double sx,
double sy )
const;
461 void flushFIG( std::ostream & stream,
463 std::map<Color,int> & colormap )
const;
465 void flushSVG( std::ostream & stream,
477 static const std::string _name;
501 inline Line(
double x1,
double y1,
double x2,
double y2,
504 const LineStyle style = SolidStyle,
505 const LineCap cap = ButtCap,
506 const LineJoin join = MiterJoin,
514 const std::string &
name()
const;
611 void flushFIG( std::ostream & stream,
613 std::map<Color,int> & colormap )
const;
615 void flushSVG( std::ostream & stream,
626 static const std::string _name;
653 inline Arrow(
double x1,
double y1,
double x2,
double y2,
656 const LineStyle style = SolidStyle,
657 const LineCap cap = ButtCap,
658 const LineJoin join = MiterJoin,
666 const std::string &
name()
const;
719 void flushFIG( std::ostream & stream,
721 std::map<Color,int> & colormap )
const;
723 void flushSVG( std::ostream & stream,
732 static const std::string _name;
741 inline Polyline(
const std::vector<Point> & points,
745 const LineStyle lineStyle = SolidStyle,
746 const LineCap cap = ButtCap,
747 const LineJoin join = MiterJoin,
753 const LineStyle lineStyle = SolidStyle,
754 const LineCap cap = ButtCap,
755 const LineJoin join = MiterJoin,
760 const LineStyle lineStyle = SolidStyle,
761 const LineCap cap = ButtCap,
762 const LineJoin join = MiterJoin,
770 const std::string &
name()
const;
897 void flushFIG( std::ostream & stream,
899 std::map<Color,int> & colormap )
const;
901 void flushSVG( std::ostream & stream,
911 inline std::size_t vertexCount()
const;
914 static const std::string _name;
926 inline Rectangle(
double left,
double top,
double width,
double height,
929 const LineStyle style = SolidStyle,
930 const LineCap cap = ButtCap,
931 const LineJoin join = MiterJoin,
937 const LineStyle style = SolidStyle,
938 const LineCap cap = ButtCap,
939 const LineJoin join = MiterJoin,
947 const std::string &
name()
const;
948 double x()
const {
return _path[0].x; }
949 double y()
const {
return _path[0].y; }
950 double width()
const {
return (_path[1] - _path[0]).norm(); }
951 double height()
const {
return (_path[0] - _path[3]).norm(); }
952 Point topLeft()
const {
return Point( _path[0].x, _path[0].y ); }
953 Point topRight()
const {
return Point( _path[1].x, _path[1].y ); }
954 Point bottomLeft()
const {
return Point( _path[3].x, _path[3].y ); }
955 Point bottomRight()
const {
return Point( _path[2].x, _path[2].y ); }
1013 void flushFIG( std::ostream & stream,
1015 std::map<Color,int> & colormap )
const;
1017 void flushSVG( std::ostream & stream,
1026 static const std::string _name;
1042 const LineStyle style = SolidStyle,
1043 const LineCap cap = ButtCap,
1044 const LineJoin join = MiterJoin,
1046 :
Polyline( std::vector<Point>(),
true, penColor, fillColor, lineWidth, style, cap, join, depth ) {
1052 Triangle(
const double x1,
const double y1,
1053 const double x2,
const double y2,
1054 const double x3,
const double y3,
1057 const LineStyle style = SolidStyle,
1058 const LineCap cap = ButtCap,
1059 const LineJoin join = MiterJoin,
1061 :
Polyline( std::vector<Point>(),
true, penColor, fillColor, lineWidth, style, cap, join, depth ) {
1062 _path <<
Point( x1, y1 );
1063 _path << Point( x2, y2 );
1064 _path << Point( x3, y3 );
1072 const std::string &
name()
const;
1074 Triangle rotated(
double angle )
const;
1108 static const std::string _name;
1128 const Point & p1,
float brightness1,
1129 const Point & p2,
float brightness2,
1130 const Color & fillColor,
1139 const std::string &
name()
const;
1210 void flushFIG( std::ostream & stream,
1212 std::map<Color,int> & colormap )
const;
1214 void flushSVG( std::ostream & stream,
1223 static const std::string _name;
1239 double xRadius,
double yRadius,
1242 const LineStyle lineStyle = SolidStyle,
1244 :
Shape( penColor, fillColor,
1245 lineWidth, lineStyle, ButtCap, MiterJoin, depth ),
1246 _center( x, y ), _xRadius( xRadius ), _yRadius( yRadius ),
1249 while ( _angle > M_PI_2 ) _angle -= M_PI;
1250 while ( _angle < -M_PI_2 ) _angle += M_PI;
1258 const std::string &
name()
const;
1354 void flushFIG( std::ostream & stream,
1356 std::map<Color,int> & colormap )
const;
1358 void flushSVG( std::ostream & stream,
1369 static const std::string _name;
1385 Circle(
double x,
double y,
double radius,
1388 const LineStyle style = SolidStyle,
1390 :
Ellipse( x, y, radius, radius, penColor, fillColor, lineWidth, style, depth )
1398 const std::string &
name()
const;
1404 Circle rotated(
double angle,
const Point & center )
const;
1408 Circle rotated(
double angle )
const;
1476 void flushSVG( std::ostream & stream,
1485 static const std::string _name;
1508 const std::string & text,
1509 const Fonts::Font font,
1511 Color color = Color::Black,
1513 :
Shape( color,
Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depth ),
1514 _position( x, y ), _text( text ), _font( font ),
1515 _angle( 0.0 ), _size( size ),
1516 _xScale( 1.0 ), _yScale( 1.0 ) { }
1534 const std::string & text,
1535 const Fonts::Font font,
1536 const std::string & svgFont,
1538 Color color = Color::Black,
1540 :
Shape( color,
Color::None, 1.0, SolidStyle, ButtCap, MiterJoin, depth ),
1542 _text( text ), _font( font ), _svgFont( svgFont ),
1545 _xScale( 1.0 ), _yScale( 1.0 ) { }
1552 const std::string &
name()
const;
1562 Text rotated(
double angle )
const;
1633 void flushFIG( std::ostream & stream,
1635 std::map<Color,int> & colormap )
const;
1637 void flushSVG( std::ostream & stream,
1648 static const std::string _name;
1654 std::string _svgFont;
1669 bool shapeGreaterDepth(
const Shape *s1,
const Shape *s2 );
1677 #include "Shapes.ih"
Ellipse & translate(double dx, double dy)
Definition: Shapes.cpp:815
A circle.
Definition: Shapes.h:1383
Abstract structure for a 2D shape.
Definition: Shapes.h:56
Arrow translated(double dx, double dy) const
Definition: Shapes.cpp:583
GouraudTriangle translated(double dx, double dy) const
Definition: Shapes.cpp:1597
A line between two points.
Definition: Shapes.h:334
virtual Shape & rotate(double angle, const Point ¢er)=0
const std::string & name() const
Definition: Shapes.cpp:1031
Polyline * clone() const
Definition: Shapes.cpp:1252
Ellipse scaled(double sx, double sy) const
Definition: Shapes.cpp:884
Dot & scale(double sx, double sy)
Definition: Shapes.cpp:239
Structure representing an RGB triple.
Definition: Color.h:39
Shape(Color penColor, Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
int _depth
Definition: Shapes.h:293
A piece of text.
Definition: Shapes.h:1492
A polygonal line described by a series of 2D points.
Definition: Shapes.h:739
An ellipse.
Definition: Shapes.h:1236
virtual void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const =0
virtual Shape & scale(double sx, double sy)=0
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:285
virtual Point center() const
Definition: Shapes.cpp:88
Dot rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:207
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:909
Line * clone() const
Definition: Shapes.cpp:459
A line between two points with an arrow at one extremity.
Definition: Shapes.h:639
double _x1
Definition: Shapes.h:629
A triangle. Basically a Polyline with a convenient constructor.
Definition: Shapes.h:1037
Color _fillColor
Definition: Shapes.h:295
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1944
Rect boundingBox() const
Definition: Shapes.cpp:1000
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:984
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1626
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1329
Text & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:1791
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1313
Ellipse & scale(double sx, double sy)
Definition: Shapes.cpp:828
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:324
virtual void flushSVG(std::ostream &stream, const TransformSVG &transform) const =0
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Triangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1757
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:312
std::string postscriptProperties() const
Definition: Shapes.cpp:142
const std::string & name() const
Definition: Shapes.cpp:773
Ellipse * clone() const
Definition: Shapes.cpp:904
Arrow rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:564
Triangle * clone() const
Definition: Shapes.cpp:1769
Polyline & scale(double sx, double sy)
Definition: Shapes.cpp:1220
Color _penColor
Definition: Shapes.h:294
A path, according to Postscript and SVG definition.
Definition: Path.h:41
Arrow * clone() const
Definition: Shapes.cpp:611
Text(double x, double y, const std::string &text, const Fonts::Font font, const std::string &svgFont, double size, Color color=Color::Black, int depth=-1)
Definition: Shapes.h:1533
LineCap _lineCap
Definition: Shapes.h:298
Circle & translate(double dx, double dy)
Definition: Shapes.cpp:1074
const std::string & name() const
Definition: Shapes.cpp:189
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:154
Line rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:375
Dot translated(double dx, double dy) const
Definition: Shapes.cpp:233
Rect boundingBox() const
Definition: Shapes.cpp:1343
Text scaled(double sx, double sy) const
Definition: Shapes.cpp:1856
virtual void flushPostscript(std::ostream &stream, const TransformEPS &transform) const =0
A line between two points.
Definition: Shapes.h:488
Struct representing a 2D point.
Definition: Point.h:38
void scaleAll(double s)
Definition: Shapes.cpp:1114
Shape & moveCenter(double x, double y)
Definition: Shapes.cpp:95
Ellipse & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:784
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1257
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:966
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1142
Polyline & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:1181
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:1281
Point center() const
Definition: Shapes.cpp:1567
Line & scale(double sx, double sy)
Definition: Shapes.cpp:411
GouraudTriangle * clone() const
Definition: Shapes.cpp:1621
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:270
Polyline & operator<<(const Point &p)
Definition: Shapes.cpp:1169
Polyline rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:1188
Arrow scaled(double sx, double sy) const
Definition: Shapes.cpp:592
const std::string & name() const
Definition: Shapes.cpp:350
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1725
Circle translated(double dx, double dy) const
Definition: Shapes.cpp:1081
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1912
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:508
Shape & rotateDeg(double angle, const Point ¢er)
double _y1
Definition: Shapes.h:630
Line & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:361
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:938
Line translated(double dx, double dy) const
Definition: Shapes.cpp:402
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
const std::string & name() const
Definition: Shapes.cpp:1163
Polyline translated(double dx, double dy) const
Definition: Shapes.cpp:1214
GouraudTriangle & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:1572
void scaleAll(double s)
Definition: Shapes.cpp:1391
Text * clone() const
Definition: Shapes.cpp:1874
Text translated(double dx, double dy) const
Definition: Shapes.cpp:1835
virtual Shape & translate(double dx, double dy)=0
virtual ~Shape()
Definition: Shapes.h:85
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1692
const std::string & name() const
Definition: Shapes.cpp:1355
Text & scale(double sx, double sy)
Definition: Shapes.cpp:1841
LineJoin _lineJoin
Definition: Shapes.h:299
double _x2
Definition: Shapes.h:631
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1446
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:464
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:670
Point & operator[](const std::size_t n)
Definition: Shapes.h:790
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Point center() const
Definition: Shapes.cpp:356
Point center() const
Definition: Shapes.cpp:779
void scaleAll(double s)
Definition: Shapes.cpp:1868
double _y2
Definition: Shapes.h:632
Dot & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:200
const std::string & name() const
Definition: Shapes.cpp:558
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1502
const std::string & name() const
Definition: Shapes.cpp:1780
Ellipse translated(double dx, double dy) const
Definition: Shapes.cpp:822
Circle scaled(double sx, double sy) const
Definition: Shapes.cpp:1102
void scaleAll(double s)
Definition: Shapes.cpp:263
A rectangle.
Definition: Shapes.h:924
The Color structure. @copyright This source code is part of the Board project, a C++ library whose pu...
Triangle translated(double dx, double dy) const
Definition: Shapes.cpp:1751
const Point & operator[](const std::size_t n) const
Definition: Shapes.h:801
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:616
Line(double x1, double y1, double x2, double y2, Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
virtual void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const =0
Dot scaled(double sx, double sy) const
Definition: Shapes.cpp:251
Point center() const
Definition: Shapes.cpp:1786
Point center() const
Definition: Shapes.cpp:1176
double _x
Definition: Shapes.h:480
Text & translate(double dx, double dy)
Definition: Shapes.cpp:1828
Dot & translate(double dx, double dy)
Definition: Shapes.cpp:225
GouraudTriangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1603
void scaleAll(double s)
Definition: Shapes.cpp:896
Rectangle translated(double dx, double dy) const
Definition: Shapes.cpp:1373
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:111
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
virtual void scaleAll(double s)=0
Arrow(double x1, double y1, double x2, double y2, Color penColor, Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
Circle & rotate(double angle, const Point ¢er)
Definition: Shapes.cpp:1042
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:1892
const std::string & name() const
Definition: Shapes.cpp:1739
bool filled() const
Definition: Shapes.h:106
Line & translate(double dx, double dy)
Definition: Shapes.cpp:394
Line scaled(double sx, double sy) const
Definition: Shapes.cpp:431
Circle * clone() const
Definition: Shapes.cpp:1122
Text(double x, double y, const std::string &text, const Fonts::Font font, double size, Color color=Color::Black, int depth=-1)
Definition: Shapes.h:1507
virtual Rect boundingBox() const =0
Rect boundingBox() const
Definition: Shapes.cpp:2002
Ellipse rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:797
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:1655
Circle & scale(double sx, double sy)
Definition: Shapes.cpp:1087
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Shapes.cpp:1879
Polyline scaled(double sx, double sy) const
Definition: Shapes.cpp:1234
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:755
Rect boundingBox() const
Definition: Shapes.cpp:531
void scaleAll(double s)
Definition: Shapes.cpp:1246
double _lineWidth
Definition: Shapes.h:296
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:1402
Rect boundingBox() const
Definition: Shapes.cpp:333
void scaleAll(double s)
Definition: Shapes.cpp:1615
Struct representing a rectangle on the plane.
Definition: Rect.h:38
Rectangle rotated(double angle, const Point ¢er) const
Definition: Shapes.cpp:1361
double _y
Definition: Shapes.h:481
virtual Shape * clone() const =0
LineStyle _lineStyle
Definition: Shapes.h:297
Dot * clone() const
Definition: Shapes.cpp:339
Rectangle * clone() const
Definition: Shapes.cpp:1397
Polyline & translate(double dx, double dy)
Definition: Shapes.cpp:1207
Rectangle scaled(double sx, double sy) const
Definition: Shapes.cpp:1379
Point center() const
Definition: Shapes.cpp:195
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:520
void scaleAll(double s)
Definition: Shapes.cpp:450
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:703
virtual const std::string & name() const
Definition: Shapes.cpp:82
A triangle with shaded filling according to colors given for each vertex.
Definition: Shapes.h:1118
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const
Definition: Shapes.cpp:479
Point center() const
Definition: Shapes.cpp:1037
const std::string & name() const
Definition: Shapes.cpp:1516
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1127