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

A line between two points. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Line:
LibBoard::Shape LibBoard::Arrow

Public Member Functions

 Line (double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
const std::string & name () const
 
Point center () const
 
Linerotate (double angle, const Point &center)
 
Line rotated (double angle, const Point &center) const
 
Linerotate (double angle)
 
Line rotated (double angle) const
 
Linetranslate (double dx, double dy)
 
Line translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Line scaled (double sx, double sy) const
 
Line 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
 
Lineclone () 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 _x1
 
double _y1
 
double _x2
 
double _y2
 
- 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

A line between two points.

The line structure.

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

Constructor & Destructor Documentation

◆ Line()

LibBoard::Line::Line ( double  x1,
double  y1,
double  x2,
double  y2,
DGtal::Color  color,
double  lineWidth,
const LineStyle  style = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

Constructs a line.

Parameters
x1First coordinate of the start point.
y1Second coordinate of the start point.
x2First coordinate of the end point.
y2Second coordinate of the end point.
colorThe color of the line.
lineWidthThe line thickness.
styleThe line style.
capThe line cap.
joinThe line join.
depthThe depth of the line.

References rotate().

Member Function Documentation

◆ boundingBox()

Rect LibBoard::Line::boundingBox ( ) const
virtual

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implements LibBoard::Shape.

Definition at line 604 of file Shapes.cpp.

605{
606 Rect rect;
607 if ( _x1 > _x2 ) {
608 rect.width = _x1 - _x2;
609 rect.left = _x2;
610 } else {
611 rect.width = _x2 - _x1;
612 rect.left = _x1;
613 }
614 if ( _y1 > _y2 ) {
615 rect.top = _y1;
616 rect.height = _y1 - _y2;
617 } else {
618 rect.top = _y2;
619 rect.height = _y2 - _y1;
620 }
621 return rect;
622}

References _x1, _x2, _y1, _y2, LibBoard::Rect::height, LibBoard::Rect::left, LibBoard::Rect::top, and LibBoard::Rect::width.

◆ center()

Point LibBoard::Line::center ( ) const
virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Implements LibBoard::Shape.

Definition at line 402 of file Shapes.cpp.

402 {
403 return 0.5 * Point( _x1 + _x2, _y1 + _y2 );
404}
MyPointD Point
Definition: testClone2.cpp:383

References _x1, _x2, _y1, and _y2.

Referenced by rotate(), rotated(), LibBoard::Arrow::rotated(), scale(), scaled(), and LibBoard::Arrow::scaled().

◆ clone()

Line * LibBoard::Line::clone ( ) const
virtual

Return a copy of the shape.

Returns
copye of the shape.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 509 of file Shapes.cpp.

509 {
510 return new Line(*this);
511}
Line(double x1, double y1, double x2, double y2, DGtal::Color color, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

◆ flushCairo()

void LibBoard::Line::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.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 571 of file Shapes.cpp.

573{
574 cairo_save (cr);
575
576 cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
577
578 cairo_move_to (cr, transform.mapX( _x1 ), transform.mapY( _y1 ));
579 cairo_line_to (cr, transform.mapX( _x2 ), transform.mapY( _y2 ));
580
581 cairo_set_line_width (cr, _lineWidth);
582 cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
583 cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
585
586 cairo_stroke (cr);
587
588 cairo_restore (cr);
589}
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
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

References LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, _x1, _x2, _y1, _y2, DGtal::Color::blue(), DGtal::Color::green(), DGtal::Color::red(), and LibBoard::Shape::setCairoDashStyle().

◆ flushFIG()

void LibBoard::Line::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< DGtal::Color, int > &  colormap 
) const
virtual

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

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

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 529 of file Shapes.cpp.

532{
533 stream << "2 1 ";
534 // Line style
535 stream << _lineStyle << " ";
536 // Thickness
537 stream << ( _penColor.valid()?transform.mapWidth( _lineWidth ):0 ) << " ";
538 // Pen color
539 stream << colormap[ _penColor ] << " ";
540 // Fill color
541 stream << "0 ";
542 // Depth
543 stream << transform.mapDepth( _depth ) << " ";
544 // Pen style
545 stream << "-1 ";
546 // Area fill, style val, join style, cap style, radius, f_arrow, b_arrow
547 stream << "-1 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 ";
548 // Number of points
549 stream << "2\n";
550 stream << " ";
551 stream << static_cast<int>( transform.mapX( _x1 ) ) << " "
552 << static_cast<int>( transform.mapY( _y1 ) ) << " "
553 << static_cast<int>( transform.mapX( _x2 ) ) << " "
554 << static_cast<int>( transform.mapY( _y2 ) ) << std::endl;
555}
bool valid() const

References LibBoard::Shape::_depth, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Shape::_penColor, _x1, _x2, _y1, _y2, and DGtal::Color::valid().

◆ flushPostscript()

void LibBoard::Line::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.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 514 of file Shapes.cpp.

516{
517 stream << "\n% Line\n";
518 stream << postscriptProperties() << " "
519 << "n "
520 << transform.mapX( _x1 ) << " "
521 << transform.mapY( _y1 ) << " "
522 << "m "
523 << transform.mapX( _x2 ) << " "
524 << transform.mapY( _y2 ) << " "
525 << "l " << _penColor.postscript() << " srgb stroke" << std::endl;
526}
std::string postscript() const
Definition: Color.cpp:150
std::string postscriptProperties() const
Definition: Shapes.cpp:140

References LibBoard::Shape::_penColor, _x1, _x2, _y1, _y2, DGtal::Color::postscript(), and LibBoard::Shape::postscriptProperties().

◆ flushSVG()

void LibBoard::Line::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.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 558 of file Shapes.cpp.

560{
561 stream << "<line x1=\"" << transform.mapX( _x1 ) << "\""
562 << " y1=\"" << transform.mapY( _y1 ) << "\""
563 << " x2=\"" << transform.mapX( _x2 ) << "\""
564 << " y2=\"" << transform.mapY( _y2 ) << "\""
565 << svgProperties( transform )
566 << " />" << std::endl;
567}
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109

References _x1, _x2, _y1, _y2, and LibBoard::Shape::svgProperties().

◆ flushTikZ()

void LibBoard::Line::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.

Implements LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 593 of file Shapes.cpp.

595{
596 stream << "\\path[" << tikzProperties(transform) << "] ("
597 << transform.mapX( _x1 ) << ',' << transform.mapY( _y1 )
598 << ") -- ("
599 << transform.mapX( _x2 ) << ',' << transform.mapY( _y2 )
600 << ");" << std::endl;
601}
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177

References _x1, _x2, _y1, _y2, and LibBoard::Shape::tikzProperties().

◆ name()

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

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

Returns
object name

Reimplemented from LibBoard::Shape.

Reimplemented in LibBoard::Arrow.

Definition at line 396 of file Shapes.cpp.

397{
398 return _name;
399}
static const std::string _name
Definition: Board/Shapes.h:649

References _name.

◆ rotate() [1/2]

Line & LibBoard::Line::rotate ( double  angle)
virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 415 of file Shapes.cpp.

416{
417 return Line::rotate( angle, center() );
418}
Line & rotate(double angle, const Point &center)
Definition: Shapes.cpp:407
Point center() const
Definition: Shapes.cpp:402

References center(), and rotate().

◆ rotate() [2/2]

Line & LibBoard::Line::rotate ( double  angle,
const Point center 
)
virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 407 of file Shapes.cpp.

408{
409 Point( _x1, _y1 ).rotate( angle, rotCenter ).get( _x1, _y1 );
410 Point( _x2, _y2 ).rotate( angle, rotCenter ).get( _x2, _y2 );
411 return *this;
412}

References _x1, _x2, _y1, _y2, LibBoard::Point::get(), and LibBoard::Point::rotate().

Referenced by Line(), and rotate().

◆ rotated() [1/2]

Line LibBoard::Line::rotated ( double  angle) const

Returns a copy of the line, rotated around its center.

Parameters
angleThe angle of rotation.
Returns
A copy of the lines, rotated around its center by the given angle.

Definition at line 430 of file Shapes.cpp.

431{
432 Line res(*this);
433 Point c = center();
434 Point( _x1, _y1 ).rotate( angle, c ).get( res._x1, res._y1 );
435 Point( _x2, _y2 ).rotate( angle, c ).get( res._x2, res._y2 );
436 return res;
437}

References _x1, _x2, _y1, _y2, center(), LibBoard::Point::get(), and LibBoard::Point::rotate().

◆ rotated() [2/2]

Line LibBoard::Line::rotated ( double  angle,
const Point center 
) const

Returns a copy of the line, rotated around a given rotation center.

Parameters
angleThe rotation angle.
centerThe center of rotation.
Returns
The rotated copy of the line.

Definition at line 421 of file Shapes.cpp.

422{
423 Line res(*this);
424 Point( _x1, _y1 ).rotate( angle, rotCenter ).get( res._x1, res._y1 );
425 Point( _x2, _y2 ).rotate( angle, rotCenter ).get( res._x2, res._y2 );
426 return res;
427}

References _x1, _x2, _y1, _y2, LibBoard::Point::get(), and LibBoard::Point::rotate().

◆ scale() [1/2]

Shape & LibBoard::Line::scale ( double  s)
virtual

Scale the shape along both axis.

Parameters
sThe scale factor along both axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 474 of file Shapes.cpp.

475{
476 scale( s, s );
477 return (*this);
478}

◆ scale() [2/2]

Shape & LibBoard::Line::scale ( double  sx,
double  sy 
)
virtual

Scale the shape along the x an y axis.

Parameters
sxThe scale factor along the x axis.
syThe scale factor along the y axis.
Returns
The shape itself.

Implements LibBoard::Shape.

Definition at line 461 of file Shapes.cpp.

462{
463 Point c = center();
464 _x1 *= sx;
465 _x2 *= sx;
466 _y1 *= sy;
467 _y2 *= sy;
468 Point delta = c - center();
469 translate( delta.x, delta.y );
470 return *this;
471}
Line & translate(double dx, double dy)
Definition: Shapes.cpp:440

References _x1, _x2, _y1, _y2, center(), translate(), LibBoard::Point::x, and LibBoard::Point::y.

◆ scaleAll()

void LibBoard::Line::scaleAll ( double  s)
virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implements LibBoard::Shape.

Definition at line 500 of file Shapes.cpp.

501{
502 _x1 *= s;
503 _y1 *= s;
504 _x2 *= s;
505 _y2 *= s;
506}

References _x1, _x2, _y1, and _y2.

◆ scaled() [1/2]

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

Definition at line 494 of file Shapes.cpp.

495{
496 return Line::scaled( s , s );
497}
Line scaled(double sx, double sy) const
Definition: Shapes.cpp:481

References scaled().

◆ scaled() [2/2]

Line LibBoard::Line::scaled ( double  sx,
double  sy 
) const

Returns a scaled copy of the line.

Parameters
sxScale factor along the x axis.
syScale factor along the y axis.
Returns
A scaled copy of the line.

Definition at line 481 of file Shapes.cpp.

482{
483 Line res(*this);
484 Point c = center();
485 res._x1 *= sx;
486 res._x2 *= sx;
487 res._y1 *= sy;
488 res._y2 *= sy;
489 Point delta = c - res.center();
490 return res.translate( delta.x, delta.y );
491}

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

Referenced by scaled().

◆ translate()

Line & LibBoard::Line::translate ( double  dx,
double  dy 
)
virtual

Translate the shape by a given offset.

Parameters
dxThe x offset.
dyThe y offset.
Returns
A reference to the shape itself.

Implements LibBoard::Shape.

Definition at line 440 of file Shapes.cpp.

441{
442 _x1 += dx;
443 _x2 += dx;
444 _y1 += dy;
445 _y2 += dy;
446 return *this;
447}

References _x1, _x2, _y1, and _y2.

Referenced by scale().

◆ translated()

Line LibBoard::Line::translated ( double  dx,
double  dy 
) const

Returns a translated copy of the line.

Parameters
dxThe shift along the x axis.
dyThe shift along the y axis.
Returns
A translated copy of the line.

Definition at line 450 of file Shapes.cpp.

451{
452 Line res(*this);
453 res._x1 += dx;
454 res._x2 += dx;
455 res._y1 += dy;
456 res._y2 += dy;
457 return *this;
458}

Field Documentation

◆ _name

const std::string LibBoard::Line::_name
staticprivate

The generic name of the shape.

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

Referenced by name().

◆ _x1

double LibBoard::Line::_x1
protected

◆ _x2

double LibBoard::Line::_x2
protected

◆ _y1

double LibBoard::Line::_y1
protected

◆ _y2

double LibBoard::Line::_y2
protected

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