Board 0.9.6
Line.h
Go to the documentation of this file.
1/* -*- mode: c++ -*- */
26#ifndef BOARD_LINE_H
27#define BOARD_LINE_H
28
30
31namespace LibBoard
32{
33
38struct Line : public ShapeWithStyle {
39
53 inline Line(double x1, double y1, double x2, double y2, //
54 Color color, double lineWidth = Style::defaultLineWidth(), //
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(), //
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
275private:
276 static const std::string _name;
278protected:
281};
282} // namespace LibBoard
283
284/*
285 * Inline methods
286 */
287
288namespace LibBoard
289{
290
291Line::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
296Line::Line(double x1, double y1, double x2, double y2, const Style & style) //
297 : ShapeWithStyle(style), _a(x1, y1), _b(x2, y2)
298{
299}
300
301Line::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
306Line::Line(Point a, Point b, const Style & style) //
307 : ShapeWithStyle(style), _a(a), _b(b)
308{
309}
310
311const Point & Line::a() const
312{
313 return _a;
314}
315
316const Point & Line::b() const
317{
318 return _b;
319}
320} // namespace LibBoard
321
322#endif /* BOARD_LINE_H */
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
LineStyle
Definition Style.h:47
LineCap
Definition Style.h:35
LineWidthFlag
Definition Style.h:57
LineJoin
Definition Style.h:41
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition ShapeVisitor.h:104
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:79
A line between two points.
Definition Line.h:38
Point _a
Definition Line.h:279
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition Line.cpp:200
Line rotated(double angle, const Point &center) const
Definition Line.cpp:67
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition Line.cpp:157
const std::string & name() const override
Definition Line.cpp:50
Point _b
Definition Line.h:280
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition Line.cpp:193
const Point & b() const
Definition Line.h:316
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition Line.cpp:146
Line & operator=(const Line &line)
Definition Line.cpp:235
Line translated(double dx, double dy) const
Definition Line.cpp:91
Rect boundingBox(LineWidthFlag) const override
Definition Line.cpp:242
Line resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition Line.cpp:136
~Line() override=default
Line(Line &&)=default
Line & translate(double dx, double dy) override
Definition Line.cpp:84
Line & scale(double sx, double sy) override
Definition Line.cpp:99
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
const Point & a() const
Definition Line.h:311
Line scaled(double sx, double sy) const
Definition Line.cpp:118
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition Line.cpp:183
Line & rotate(double angle, const Point &center) override
Definition Line.cpp:55
Line * clone() const override
Definition Line.cpp:141
void scaleAll(double s) override
Definition Line.cpp:128
Struct representing a 2D point.
Definition Point.h:42
Struct representing a rectangle on the plane.
Definition Rect.h:40
A ShapeVisitor visits all shapes in a composite shape tree in back-to-front order.
Definition ShapeVisitor.h:54
Abstract structure for a 2D shape.
Definition ShapeWithStyle.h:38
Style style() const
Definition ShapeWithStyle.h:215
double lineWidth() const
Definition ShapeWithStyle.h:165
LineStyle lineStyle() const
Definition ShapeWithStyle.h:176
Abstract structure for a 2D shape.
Definition Shape.h:64
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59
Definition Style.h:69
static const double & defaultLineWidth()
defaultLineWidth
Definition Style.h:274
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition Style.h:289
static const LineCap & defaultLineCap()
defaultLineCap
Definition Style.h:294
static const LineJoin & defaultLineJoin()
defaultLineJoin
Definition Style.h:299
Structure representing a scaling and translation suitable for an EPS output.
Definition Transforms.h:71
Structure representing a scaling and translation suitable for an XFig output.
Definition Transforms.h:87
Structure representing a scaling and translation suitable for an SVG output.
Definition Transforms.h:109
Structure representing a scaling and translation suitable for an TikZ output.
Definition Transforms.h:126