DGtal  1.2.0
Public Member Functions | Protected Attributes | Static Private Attributes
LibBoard::Rectangle Struct Reference

A rectangle. More...

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Rectangle:
[legend]

Public Member Functions

 Rectangle (double x, double y, double width, double height, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Rectangle (const Rect &rect, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
const std::string & name () const
 
double x () const
 
double y () const
 
double width ()
 
double height ()
 
Point topLeft ()
 
Point topRight ()
 
Point bottomLeft ()
 
Point bottomRight ()
 
Rectangle rotated (double angle, const Point &center) const
 
Rectangle rotated (double angle) const
 
Rectangle translated (double dx, double dy) const
 
Rectangle scaled (double sx, double sy) const
 
Rectangle scaled (double s) const
 
void scaleAll (double s)
 
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
 
Rectangleclone () const
 
- Public Member Functions inherited from LibBoard::Polyline
 Polyline (const std::vector< Point > &points, bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (const Path &path, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
 Polyline (bool closed, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle lineStyle=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)
 
Point center () const
 
Polylineoperator<< (const Point &p)
 
Pointoperator[] (const unsigned int n)
 
Polylinerotate (double angle, const Point &center)
 
Polyline rotated (double angle, const Point &center) const
 
Polylinerotate (double angle)
 
Polyline rotated (double angle) const
 
Polylinetranslate (double dx, double dy)
 
Polyline translated (double dx, double dy) const
 
Shapescale (double sx, double sy)
 
Shapescale (double s)
 
Polyline scaled (double sx, double sy) const
 
Polyline scaled (double s) const
 
void flushPostscript (std::ostream &stream, const TransformEPS &transform) const
 
Rect boundingBox () 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 ()
 
bool filled () const
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Attributes

bool _isRectangle
 
- Protected Attributes inherited from LibBoard::Polyline
Path _path
 
- 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 rectangle.

The rectangle structure.

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

Constructor & Destructor Documentation

◆ Rectangle() [1/2]

LibBoard::Rectangle::Rectangle ( double  x,
double  y,
double  width,
double  height,
DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
const LineStyle  style = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

Referenced by clone(), rotated(), scaled(), and translated().

◆ Rectangle() [2/2]

LibBoard::Rectangle::Rectangle ( const Rect rect,
DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
const LineStyle  style = SolidStyle,
const LineCap  cap = ButtCap,
const LineJoin  join = MiterJoin,
int  depth = -1 
)
inline

Member Function Documentation

◆ bottomLeft()

Point LibBoard::Rectangle::bottomLeft ( )
inline

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

943 { return Point( _path[3].x, _path[3].y ); }
MyPointD Point
Definition: testClone2.cpp:383

References LibBoard::Polyline::_path.

◆ bottomRight()

Point LibBoard::Rectangle::bottomRight ( )
inline

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

944 { return Point( _path[2].x, _path[2].y ); }

References LibBoard::Polyline::_path.

◆ clone()

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

Return a copy of the shape.

Returns
copye of the shape.

Reimplemented from LibBoard::Polyline.

Reimplemented in LibBoard::Image.

Definition at line 1921 of file Shapes.cpp.

1921  {
1922  return new Rectangle(*this);
1923 }
Rectangle(double x, double y, double width, double height, DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, const LineStyle style=SolidStyle, const LineCap cap=ButtCap, const LineJoin join=MiterJoin, int depth=-1)

References Rectangle().

◆ flushCairo()

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

Reimplemented in LibBoard::Image.

Definition at line 2010 of file Shapes.cpp.

2012 {
2013  {
2014  double x1 = _path[1].x - _path[0].x;
2015  double y1 = _path[1].y - _path[0].y;
2016  double x2 = _path[3].x - _path[0].x;
2017  double y2 = _path[3].y - _path[0].y;
2018  if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
2019  Polyline::flushCairo( cr, transform );
2020  return;
2021  }
2022  }
2023 
2024  cairo_save (cr);
2025 
2026  cairo_set_source_rgba (cr, _fillColor.red()/255.0, _fillColor.green()/255.0, _fillColor.blue()/255.0, 1.);
2027 
2028  if ( _path[0].y == _path[1].y )
2029  cairo_rectangle (cr, transform.mapX( _path[0].x ), transform.mapY( _path[0].y ), transform.scale( _path[1].x - _path[0].x ), transform.scale( _path[0].y - _path[3].y ));
2030  else
2031  {
2032  Point v = _path[1] - _path[0];
2033  v /= v.norm();
2034  double angle = ( _path[1].y > _path[0].y ) ? acos( v * Point(1,0) ) : -acos( v * Point( 1, 0 ) );
2035 
2036  // tr
2037  cairo_translate (cr, transform.mapX( _path[0].x )+transform.scale( _path[1].x - _path[0].x )/2., transform.mapY( _path[0].y )+transform.scale( _path[0].y - _path[3].y )/2.);
2038  cairo_rotate (cr, angle);
2039  // tr
2040 
2041  cairo_rectangle (cr, -transform.scale( _path[1].x - _path[0].x )/2., -transform.scale( _path[0].y - _path[3].y )/2., transform.scale( (_path[1] - _path[0]).norm() ), transform.scale( (_path[0] - _path[3]).norm() ));
2042  }
2043 
2044  if ( filled() )
2045  {
2046  if ( _penColor != DGtal::Color::None )
2047  cairo_fill_preserve (cr);
2048  else
2049  cairo_fill (cr);
2050  }
2051 
2052  //
2053 
2054  if ( _penColor != DGtal::Color::None )
2055  {
2056  cairo_set_source_rgba (cr, _penColor.red()/255.0, _penColor.green()/255.0, _penColor.blue()/255.0, 1.);
2057 
2058  cairo_set_line_width (cr, _lineWidth);
2059  cairo_set_line_cap (cr, cairoLineCap[_lineCap]);
2060  cairo_set_line_join (cr, cairoLineJoin[_lineJoin]);
2062 
2063  cairo_stroke (cr);
2064  }
2065 
2066  cairo_restore (cr);
2067 }
static const Color None
Definition: Color.h:388
void green(const unsigned char aGreenValue)
void red(const unsigned char aRedValue)
void blue(const unsigned char aBlueValue)
void flushCairo(cairo_t *cr, const TransformCairo &transform) const
Definition: Shapes.cpp:1809
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 LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Polyline::_path, LibBoard::Shape::_penColor, DGtal::Color::blue(), LibBoard::Shape::filled(), LibBoard::Polyline::flushCairo(), DGtal::Color::green(), DGtal::Color::None, DGtal::Color::red(), and LibBoard::Shape::setCairoDashStyle().

◆ flushFIG()

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

Reimplemented from LibBoard::Polyline.

Reimplemented in LibBoard::Image.

Definition at line 1926 of file Shapes.cpp.

1929 {
1930  if ( _path[0].y != _path[1].y ) {
1931  Polyline::flushFIG( stream, transform, colormap );
1932  return;
1933  }
1934  if ( _path[0].x != _path[3].x ) {
1935  Polyline::flushFIG( stream, transform, colormap );
1936  return;
1937  }
1938  {
1939  double x1 = _path[1].x - _path[0].x;
1940  double y1 = _path[1].y - _path[0].y;
1941  double x2 = _path[3].x - _path[0].x;
1942  double y2 = _path[3].y - _path[0].y;
1943  if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
1944  Polyline::flushFIG( stream, transform, colormap );
1945  return;
1946  }
1947  }
1948 
1949  stream << "2 2 " << _lineStyle << " ";
1950  // Thickness
1951  stream << ( _penColor.valid()?transform.mapWidth( _lineWidth ):0 ) << " ";
1952  // Pen color
1953  stream << colormap[ _penColor ] << " ";
1954  // Fill color
1955  stream << colormap[ _fillColor ] << " ";
1956  // Depth
1957  stream << transform.mapDepth( _depth ) << " ";
1958  // Pen style
1959  stream << "-1 ";
1960  // Area fill, style val, join style, cap style, radius, f_arrow, b_arrow, number of points
1961  if ( filled() )
1962  stream << "20 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 5\n";
1963  else
1964  stream << "-1 " << (_lineStyle?"4.000 ":"0.000 ") << _lineJoin << " " << _lineCap << " -1 0 0 5\n";
1965  stream << " ";
1966  _path.flushFIG( stream, transform );
1967  stream << std::endl;
1968 }
bool valid() const
void flushFIG(std::ostream &stream, const TransformFIG &transform) const
Definition: Path.cpp:173
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const
Definition: Shapes.cpp:1760

References LibBoard::Shape::_depth, LibBoard::Shape::_fillColor, LibBoard::Shape::_lineCap, LibBoard::Shape::_lineJoin, LibBoard::Shape::_lineStyle, LibBoard::Shape::_lineWidth, LibBoard::Polyline::_path, LibBoard::Shape::_penColor, LibBoard::Shape::filled(), LibBoard::Path::flushFIG(), LibBoard::Polyline::flushFIG(), and DGtal::Color::valid().

◆ flushSVG()

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

Reimplemented in LibBoard::Image.

Definition at line 1971 of file Shapes.cpp.

1973 {
1974  {
1975  double x1 = _path[1].x - _path[0].x;
1976  double y1 = _path[1].y - _path[0].y;
1977  double x2 = _path[3].x - _path[0].x;
1978  double y2 = _path[3].y - _path[0].y;
1979  if ( fabs(x1*x2 + y1*y2) > 0.01 ) {
1980  Polyline::flushSVG( stream, transform );
1981  return;
1982  }
1983  }
1984 
1985  if ( _path[0].y == _path[1].y ) {
1986  stream << "<rect x=\"" << transform.mapX( _path[0].x ) << '"'
1987  << " y=\"" << transform.mapY( _path[0].y ) << '"'
1988  << " width=\"" << transform.scale( _path[1].x - _path[0].x ) << '"'
1989  << " height=\"" << transform.scale( _path[0].y - _path[3].y ) << '"'
1990  << svgProperties( transform )
1991  << " />" << std::endl;
1992  } else {
1993  Point v = _path[1] - _path[0];
1994  v /= v.norm();
1995  double angle = ( _path[1].y > _path[0].y ) ? acos( v * Point(1,0) ) : -acos( v * Point( 1, 0 ) );
1996  angle = ( angle * 180 ) / M_PI;
1997  stream << "<rect x=\"" << transform.mapX( _path[0].x ) << '"'
1998  << " y=\"" << transform.mapY( _path[0].y ) << '"'
1999  << " width=\"" << transform.scale( (_path[1] - _path[0]).norm() ) << '"'
2000  << " height=\"" << transform.scale( (_path[0] - _path[3]).norm() ) << '"'
2001  << svgProperties( transform ) << ' '
2002  << " transform=\"rotate(" << -angle << ", "
2003  << transform.mapX( _path[0].x ) << ", " << transform.mapY( _path[0].y ) << ") \" "
2004  << " />" << std::endl;
2005  }
2006 }
Path & scale(double sx, double sy)
Definition: Path.cpp:108
void flushSVG(std::ostream &stream, const TransformSVG &transform) const
Definition: Shapes.cpp:1792
std::string svgProperties(const TransformSVG &transform) const
Definition: Shapes.cpp:109

References LibBoard::Polyline::_path, LibBoard::Polyline::flushSVG(), and LibBoard::Shape::svgProperties().

◆ flushTikZ()

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

Reimplemented in LibBoard::Image.

Definition at line 2071 of file Shapes.cpp.

2073 {
2074  Polyline::flushTikZ( stream, transform );
2075  return;
2076 
2077  stream << "\\path[" << tikzProperties(transform) << "] ("
2078  << _path[0].x << ',' << _path[0].y << ')'
2079  << " rectangle (" << _path[1].x << ',' << _path[3].y << "); ";
2080 }
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const
Definition: Shapes.cpp:1850
std::string tikzProperties(const TransformTikZ &transform) const
Definition: Shapes.cpp:177

References LibBoard::Polyline::_path, LibBoard::Polyline::flushTikZ(), and LibBoard::Shape::tikzProperties().

◆ height()

double LibBoard::Rectangle::height ( )
inline

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

940 { return (_path[0] - _path[3]).norm(); }

References LibBoard::Polyline::_path.

◆ name()

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

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

Returns
object name

Reimplemented from LibBoard::Polyline.

Reimplemented in LibBoard::Image.

Definition at line 1879 of file Shapes.cpp.

1880 {
1881  return _name;
1882 }
static const std::string _name

References _name.

◆ rotated() [1/2]

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

Returns a copy of the arrow, 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 1891 of file Shapes.cpp.

1892 {
1893  return static_cast<Rectangle &>( Rectangle(*this).rotate( angle, center() ) );
1894 }
Point center() const
Definition: Shapes.cpp:1655

References LibBoard::Polyline::center(), and Rectangle().

◆ rotated() [2/2]

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

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

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

Definition at line 1885 of file Shapes.cpp.

1886 {
1887  return static_cast<Rectangle &>( Rectangle(*this).rotate( angle, rotCenter ) );
1888 }

References Rectangle().

◆ scaleAll()

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

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

Parameters
sThe scaling factor.

Reimplemented from LibBoard::Polyline.

Definition at line 1915 of file Shapes.cpp.

1916 {
1917  _path.scaleAll( s );
1918 }
void scaleAll(double s)
Definition: Path.cpp:143

References LibBoard::Polyline::_path, and LibBoard::Path::scaleAll().

◆ scaled() [1/2]

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

Definition at line 1909 of file Shapes.cpp.

1910 {
1911  return static_cast<Rectangle &>( Rectangle(*this).scale( s, s ) );
1912 }

References Rectangle().

◆ scaled() [2/2]

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

Returns a scaled copy of the arrow.

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

Definition at line 1903 of file Shapes.cpp.

1904 {
1905  return static_cast<Rectangle &>( Rectangle(*this).scale( sx, sy ) );
1906 }

References Rectangle().

◆ topLeft()

Point LibBoard::Rectangle::topLeft ( )
inline

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

941 { return Point( _path[0].x, _path[0].y ); }

References LibBoard::Polyline::_path.

◆ topRight()

Point LibBoard::Rectangle::topRight ( )
inline

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

942 { return Point( _path[1].x, _path[1].y ); }

References LibBoard::Polyline::_path.

◆ translated()

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

Returns a translated copy of the arrow.

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

Definition at line 1897 of file Shapes.cpp.

1898 {
1899  return static_cast<Rectangle &>( Rectangle(*this).translate( dx, dy ) );
1900 }

References Rectangle().

◆ width()

double LibBoard::Rectangle::width ( )
inline

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

939 { return (_path[1] - _path[0]).norm(); }

References LibBoard::Polyline::_path.

◆ x()

double LibBoard::Rectangle::x ( ) const
inline

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

937 { return _path[0].x; }

References LibBoard::Polyline::_path.

◆ y()

double LibBoard::Rectangle::y ( ) const
inline

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

938 { return _path[0].y; }

References LibBoard::Polyline::_path.

Field Documentation

◆ _isRectangle

bool LibBoard::Rectangle::_isRectangle
protected

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

◆ _name

const std::string LibBoard::Rectangle::_name
staticprivate

The generic name of the shape.

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

Referenced by name().


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