DGtal 1.3.0
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Static Private Attributes
LibBoard::Arc Struct Reference

An arc. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Arc:
LibBoard::Circle LibBoard::Ellipse LibBoard::Shape

Public Member Functions

 Arc (double x, double y, double radius, double angle1, double angle2, bool negative, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)
 
const std::string & name () const
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
- Public Member Functions inherited from LibBoard::Circle
 Circle (double x, double y, double radius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)
 
const std::string & name () const
 
Point center () const
 
Circlerotate (double angle, const Point &center)
 
Circle rotated (double angle, const Point &center) const
 
Circlerotate (double angle)
 
Circle rotated (double angle) const
 
Circletranslate (double dx, double dy)
 
Circle translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Circle scaled (double sx, double sy) const
 
Circle scaled (double s) const
 
void scaleAll (double s)
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
Circleclone () const
 
- Public Member Functions inherited from LibBoard::Ellipse
 Ellipse (double x, double y, double xRadius, double yRadius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle lineStyle=SolidStyle, int depthValue=-1)
 
const std::string & name () const
 
Point center () const
 
Ellipserotate (double angle, const Point &center)
 
Ellipse rotated (double angle, const Point &center) const
 
Ellipserotate (double angle)
 
Ellipse rotated (double angle) const
 
Ellipsetranslate (double dx, double dy)
 
Ellipse translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Ellipse scaled (double sx, double sy) const
 
Ellipse 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, std::map< DGtal::Color, int > &colormap) const
 
void flushSVG (std::ostream &stream, const TransformSVG &transform) const
 
void flushCairo (cairo_t *cr, const TransformCairo &transform) const
 
void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const
 
Rect boundingBox () const
 
Ellipseclone () const
 
- Public Member Functions inherited from LibBoard::Shape
 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
virtual const std::string & name () const
 
virtual Shapeclone () const =0
 
bool filled () const
 
virtual Point center () const =0
 
virtual Shaperotate (double angle, const Point &center)=0
 
virtual Shaperotate (double angle)=0
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
virtual Shapetranslate (double dx, double dy)=0
 
virtual Shapescale (double sx, double sy)=0
 
virtual Shapescale (double s)=0
 
virtual Rect boundingBox () const =0
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
virtual void scaleAll (double s)=0
 
virtual void flushPostscript (std::ostream &stream, const TransformEPS &transform) const =0
 
virtual void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const =0
 
virtual void flushSVG (std::ostream &stream, const TransformSVG &transform) const =0
 
virtual void flushCairo (cairo_t *cr, const TransformCairo &transform) const =0
 
virtual void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const =0
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Attributes

double _angle1
 
double _angle2
 
bool _negative
 
- Protected Attributes inherited from LibBoard::Ellipse
Point _center
 
double _xRadius
 
double _yRadius
 
double _angle
 
bool _circle
 
- Protected Attributes inherited from LibBoard::Shape
int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Private Attributes

static const std::string _name
 

Additional Inherited Members

- Public Types inherited from LibBoard::Shape
enum  LineCap { ButtCap = 0 , RoundCap , SquareCap }
 
enum  LineJoin { MiterJoin = 0 , RoundJoin , BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0 , DashStyle , DotStyle , DashDotStyle ,
  DashDotDotStyle , DashDotDotDotStyle
}
 
- Protected Member Functions inherited from LibBoard::Shape
std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Detailed Description

An arc.

The arc structure.

Definition at line 1528 of file Board/Shapes.h.

Constructor & Destructor Documentation

◆ Arc()

LibBoard::Arc::Arc ( double  x,
double  y,
double  radius,
double  angle1,
double  angle2,
bool  negative,
DGtal::Color  pen,
DGtal::Color  fill,
double  lineWidth,
const LineStyle  style = SolidStyle,
int  depthValue = -1 
)
inline

Definition at line 1530 of file Board/Shapes.h.

1535 : Circle( x, y, radius, pen, fill, lineWidth, style, depthValue )
1536 { _angle1 = angle1; _angle2 = angle2; _negative = negative; }
Circle(double x, double y, double radius, DGtal::Color pen, DGtal::Color fill, double lineWidth, const LineStyle style=SolidStyle, int depthValue=-1)

References _angle1, _angle2, and _negative.

Member Function Documentation

◆ flushCairo()

void LibBoard::Arc::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Circle.

Definition at line 1500 of file Shapes.cpp.

1502{
1503 cairo_save (cr);
1504
1505 cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
1506
1507 if (_negative) // important: here for Cairo we must inverse 'cairo_arc' and 'cairo_arc_negative' and change alpha with 2.*M_PI-alpha
1508 cairo_arc (cr, transform.mapX( _center.x ), transform.mapY( _center.y ), transform.scale( _xRadius ), 2.*M_PI-_angle1, 2.*M_PI-_angle2);
1509 else
1510 cairo_arc_negative (cr, transform.mapX( _center.x ), transform.mapY( _center.y ), transform.scale( _xRadius ), 2.*M_PI-_angle1, 2.*M_PI-_angle2);
1511
1512 if ( filled() )
1513 {
1515 cairo_fill_preserve (cr);
1516 else
1517 cairo_fill (cr);
1518 }
1519
1520 //
1521
1523 {
1524 cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
1525
1526 cairo_set_line_width (cr, _lineWidth);
1527 cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
1528 cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
1530
1531 cairo_stroke (cr);
1532 }
1533
1534 cairo_restore (cr);
1535}
static const Color None
Definition: Color.h:412
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
double y
Definition: Point.h:30
double x
Definition: Point.h:29
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineJoin _lineJoin
Definition: Board/Shapes.h:301
void setCairoDashStyle(cairo_t *cr, LineStyle type) const
Definition: Shapes.cpp:153
LineStyle _lineStyle
Definition: Board/Shapes.h:299
bool filled() const
Definition: Board/Shapes.h:111

References _angle1, _angle2, LibBoard::Ellipse::_center, LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, _negative, LibBoard::Shape::_penColor, LibBoard::Ellipse::_xRadius, DGtal::Color::blue(), LibBoard::Shape::filled(), DGtal::Color::green(), DGtal::Color::None, DGtal::Color::red(), LibBoard::Shape::setCairoDashStyle(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushPostscript()

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

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Ellipse.

Definition at line 1539 of file Shapes.cpp.

1541{
1542
1543//The arc is generated by sweeping a line segment of length r, and tied at the point (x-coord y-coord), in a counter-clockwise direction from an angle _angle1 to an angle _angle2.
1544//Thus, we have to swap _angle1 and _angle2 according to bool _negative
1545 double a1, a2;
1546 if (_negative == true)
1547 {
1548 a1 = _angle2;
1549 a2 = _angle1;
1550 }
1551 else
1552 {
1553 a1 = _angle1;
1554 a2 = _angle2;
1555 }
1556
1557 stream << "\n% Arc\n";
1558 if ( filled() ) {
1559 stream << "gs "
1560 << transform.mapX( _center.x ) << " " << transform.mapY( _center.y ) << " "
1561 << transform.scale( _xRadius )<< " " << (a1*180/M_PI) << " "
1562 << (a2*180/M_PI) << " "<< "arc ";
1563 stream << " " << _fillColor.postscript() << " srgb";
1564 stream << " fill gr" << std::endl;
1565 }
1566
1567 if ( _penColor != DGtal::Color::None ) {
1568
1569 stream << "gs "
1570 << transform.mapX( _center.x ) << " " << transform.mapY( _center.y ) << " "
1571 << transform.scale( _xRadius )<< " " << (a1*180/M_PI) << " "
1572 << (a2*180/M_PI) << " "<< "arc ";
1573 _penColor.flushPostscript( stream );
1574 stream << " stroke gr" << std::endl;
1575 }
1576}
std::string postscript() const
Definition: Color.cpp:150
void flushPostscript(std::ostream &) const
Definition: Color.cpp:142

References _angle1, _angle2, LibBoard::Ellipse::_center, LibBoard::Shape::_fillColor, _negative, LibBoard::Shape::_penColor, LibBoard::Ellipse::_xRadius, LibBoard::Shape::filled(), DGtal::Color::flushPostscript(), DGtal::Color::None, DGtal::Color::postscript(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushSVG()

void LibBoard::Arc::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Circle.

Definition at line 1579 of file Shapes.cpp.

1581{
1582
1583double fx = _center.x + _xRadius*std::cos(_angle1);
1584double fy = _center.y + _xRadius*std::sin(_angle1);
1585double lx = _center.x + _xRadius*std::cos(_angle2);
1586double ly = _center.y + _xRadius*std::sin(_angle2);
1587
1588stream << "<path ";
1589stream << svgProperties( transform ) << " ";
1590//first point
1591stream << "d='M " << transform.mapX( fx );
1592stream << "," << transform.mapY( fy );
1593//arc
1594stream << " A " << transform.scale( _xRadius ) << " " << transform.scale( _xRadius );
1595//something
1596stream << " 0";
1597//orientation and center position
1598if (_negative)
1599{
1600 if ( (std::cos(_angle1)*std::sin(_angle2) - std::sin(_angle1)*std::cos(_angle2))<0 )
1601 {
1602 stream << " 0 1";
1603 } else
1604 {
1605 stream << " 1 1";
1606 }
1607} else
1608{
1609 if ( (std::cos(_angle1)*std::sin(_angle2) - std::sin(_angle1)*std::cos(_angle2))<0 )
1610 {
1611 stream << " 1 0";
1612 } else
1613 {
1614 stream << " 0 0";
1615 }
1616}
1617//last point
1618stream << " " << transform.mapX( lx );
1619stream << "," << transform.mapY( ly );
1620stream << "' />";
1621
1622}
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109

References _angle1, _angle2, LibBoard::Ellipse::_center, _negative, LibBoard::Ellipse::_xRadius, LibBoard::Shape::svgProperties(), LibBoard::Point::x, and LibBoard::Point::y.

◆ flushTikZ()

void LibBoard::Arc::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Reimplemented from LibBoard::Circle.

Definition at line 1625 of file Shapes.cpp.

1627{
1628 stream << "\\path[" << tikzProperties(transform) << "] ("
1629 << transform.mapX( _center.x ) << ',' << transform.mapY( _center.y ) << ')' // center
1630 << " +(" << -_angle1/M_PI*180. << ':' << transform.scale( _xRadius) << ')' // first point of arc
1631 << " arc (" << -_angle1/M_PI*180. << ':' << -_angle2/M_PI*180. + _negative * 360. << ':' << transform.scale( _xRadius ) << ");"
1632 << std::endl;
1633}
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177

References _angle1, _angle2, LibBoard::Ellipse::_center, _negative, LibBoard::Ellipse::_xRadius, LibBoard::Shape::tikzProperties(), LibBoard::Point::x, and LibBoard::Point::y.

◆ name()

const std::string & LibBoard::Arc::name ( ) const
virtual

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name

Reimplemented from LibBoard::Circle.

Definition at line 1493 of file Shapes.cpp.

1494{
1495 return _name;
1496}
static const std::string _name

References _name.

Field Documentation

◆ _angle1

double LibBoard::Arc::_angle1
protected

Definition at line 1564 of file Board/Shapes.h.

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().

◆ _angle2

double LibBoard::Arc::_angle2
protected

Definition at line 1565 of file Board/Shapes.h.

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().

◆ _name

const std::string LibBoard::Arc::_name
staticprivate

The generic name of the shape.

Definition at line 1561 of file Board/Shapes.h.

Referenced by name().

◆ _negative

bool LibBoard::Arc::_negative
protected

Definition at line 1566 of file Board/Shapes.h.

Referenced by Arc(), flushCairo(), flushPostscript(), flushSVG(), and flushTikZ().


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