Board  0.9.5
Line.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_LINE_H
27 #define BOARD_LINE_H
28 
29 #include "board/ShapeWithStyle.h"
30 
31 namespace LibBoard
32 {
33 
38 struct Line : public ShapeWithStyle {
39 
53  inline Line(double x1, double y1, double x2, double y2, //
54  Color color, double lineWidth = Style::defaultLineWidth(), //
55  const LineStyle lineStyle = Style::defaultLineStyle(), const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
56 
66  inline Line(double x1, double y1, double x2, double y2, const Style & style);
67 
79  inline Line(Point a, Point b, Color color, double lineWidth = Style::defaultLineWidth(), //
80  const LineStyle lineStyle = Style::defaultLineStyle(), const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
81 
89  inline Line(Point a, Point b, const Style & style);
90 
96  const std::string & name() const override;
97 
98  Line & rotate(double angle, const Point & center) override;
99 
108  Line rotated(double angle, const Point & center) const;
109 
110  Line & rotate(double angle) override;
111 
119  Line rotated(double angle) const;
120 
129  Line & translate(double dx, double dy) override;
130 
139  Line translated(double dx, double dy) const;
140 
149  Line & scale(double sx, double sy) override;
150 
158  Line & scale(double s) override;
159 
168  Line scaled(double sx, double sy) const;
169 
177  Line scaled(double s) const;
178 
185  void scaleAll(double s) override;
186 
195  Line resized(double w, double h, LineWidthFlag lineWidthFlag) const;
196 
202  Rect boundingBox(LineWidthFlag) const override;
203 
204  Line * clone() const override;
205 
206  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
207 
208  void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
209 
210  void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
211 
212  void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
213 
219  virtual void accept(ShapeVisitor & visitor) override;
220 
226  virtual void accept(const ShapeVisitor & visitor) override;
227 
233  virtual void accept(ConstShapeVisitor & visitor) const override;
234 
240  virtual void accept(const ConstShapeVisitor & visitor) const override;
241 
247  virtual Shape * accept(CompositeShapeTransform & transform) const override;
248 
254  virtual Shape * accept(const CompositeShapeTransform & transform) const override;
255 
261  inline const Point & a() const;
262 
268  inline const Point & b() const;
269 
270  Line(const Line & other);
271  Line(Line &&) = default;
272  Line & operator=(const Line & line);
273  ~Line() override = default;
274 
275 private:
276  static const std::string _name;
278 protected:
281 };
282 } // namespace LibBoard
283 
284 /*
285  * Inline methods
286  */
287 
288 namespace LibBoard
289 {
290 
291 Line::Line(double x1, double y1, double x2, double y2, Color color, double lineWidth, const LineStyle style, const LineCap cap, const LineJoin join)
292  : ShapeWithStyle(color, Color::Null, lineWidth, style, cap, join), _a(x1, y1), _b(x2, y2)
293 {
294 }
295 
296 Line::Line(double x1, double y1, double x2, double y2, const Style & style) //
297  : ShapeWithStyle(style), _a(x1, y1), _b(x2, y2)
298 {
299 }
300 
301 Line::Line(Point a, Point b, Color color, double lineWidth, const LineStyle style, const LineCap cap, const LineJoin join)
302  : ShapeWithStyle(color, Color::Null, lineWidth, style, cap, join), _a(a), _b(b)
303 {
304 }
305 
306 Line::Line(Point a, Point b, const Style & style) //
307  : ShapeWithStyle(style), _a(a), _b(b)
308 {
309 }
310 
311 const Point & Line::a() const
312 {
313  return _a;
314 }
315 
316 const Point & Line::b() const
317 {
318  return _b;
319 }
320 } // namespace LibBoard
321 
322 #endif /* BOARD_LINE_H */
LibBoard::Line::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Line.cpp:193
LibBoard::Line::a
const Point & a() const
Definition: Line.h:311
LibBoard::Line::rotate
Line & rotate(double angle, const Point &center) override
Definition: Line.cpp:55
LibBoard::Style
Definition: Style.h:69
ShapeWithStyle.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Style::defaultLineWidth
static const double & defaultLineWidth()
defaultLineWidth
Definition: Style.h:276
LibBoard::Line::b
const Point & b() const
Definition: Line.h:316
LibBoard::Line::_a
Point _a
Definition: Line.h:279
LibBoard::Line::accept
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: Line.cpp:200
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Line::scaled
Line scaled(double sx, double sy) const
Definition: Line.cpp:118
LibBoard::Line::scale
Line & scale(double sx, double sy) override
Definition: Line.cpp:99
LibBoard::Line::translate
Line & translate(double dx, double dy) override
Definition: Line.cpp:84
LibBoard::Line::rotated
Line rotated(double angle, const Point &center) const
Definition: Line.cpp:67
LibBoard::Line::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: Line.cpp:242
LibBoard::Line::resized
Line resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition: Line.cpp:136
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Line::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Line.cpp:146
LibBoard::Line::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Line.cpp:157
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Line
A line between two points.
Definition: Line.h:38
LibBoard::Line::scaleAll
void scaleAll(double s) override
Definition: Line.cpp:128
LibBoard::Line::translated
Line translated(double dx, double dy) const
Definition: Line.cpp:91
LibBoard::Style::defaultLineCap
static const LineCap & defaultLineCap()
defaultLineCap
Definition: Style.h:296
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Line::name
const std::string & name() const override
Definition: Line.cpp:50
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::Line::clone
Line * clone() const override
Definition: Line.cpp:141
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Line::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Line.cpp:183
LibBoard::Shape::center
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shape.cpp:59
LibBoard::Line::Line
Line(double x1, double y1, double x2, double y2, Color color, double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition: Line.h:291
LibBoard::Style::defaultLineJoin
static const LineJoin & defaultLineJoin()
defaultLineJoin
Definition: Style.h:301
LibBoard::Style::defaultLineStyle
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition: Style.h:291
LibBoard::Line::_b
Point _b
Definition: Line.h:280
LibBoard::ShapeVisitor
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:53
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109
LibBoard::Color
Structure representing an RGB triple.
Definition: Color.h:43
LibBoard::ShapeWithStyle
Abstract structure for a 2D shape.
Definition: ShapeWithStyle.h:38