Board  0.9.5
Bezier.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_BEZIER_H
27 #define BOARD_BEZIER_H
28 
29 #include "board/ShapeWithStyle.h"
30 
31 // TODO : Add a merge (+=) operation to link to bezier curve
32 
33 namespace LibBoard
34 {
35 
40 struct Bezier : public ShapeWithStyle {
41 
54  Bezier(const std::vector<Point> & points, const std::vector<Point> & controls, //
55  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
56  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle(), //
57  const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
58 
66  Bezier(const std::vector<Point> & points, const std::vector<Point> & controls, //
67  const Style & style);
68 
82  Bezier(Point p0, Point control0, Point p1, Point control1, //
83  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
84  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle(), //
85  const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
86 
95  Bezier(Point p0, Point control0, Point p1, Point control1, //
96  const Style & style);
97 
115  Bezier(double x0, double y0, double xc0, double yc0, double x1, double y1, double xc1, double yc1, //
116  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
117  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle(), //
118  const LineCap cap = Style::defaultLineCap(), const LineJoin join = Style::defaultLineJoin());
119 
132  Bezier(double x0, double y0, double xc0, double yc0, double x1, double y1, double xc1, double yc1, //
133  const Style & style);
134 
140  const std::string & name() const override;
141 
148  Bezier & rotate(double angle, const Point & center) override;
149 
150  Bezier rotated(double angle, const Point & center) const;
151 
152  Bezier & rotate(double angle) override;
153 
161  Bezier rotated(double angle) const;
162 
171  Bezier & translate(double dx, double dy) override;
172 
181  Bezier translated(double dx, double dy) const;
182 
191  Bezier & scale(double sx, double sy) override;
192 
200  Bezier & scale(double s) override;
201 
210  Bezier scaled(double sx, double sy) const;
211 
219  Bezier scaled(double s) const;
220 
227  void scaleAll(double s) override;
228 
237  Bezier resized(double w, double h, LineWidthFlag lineWidthFlag) const;
238 
239  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
240 
241  void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
242 
243  void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
244 
245  void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
246 
252  virtual void accept(ShapeVisitor & visitor) override;
253 
259  virtual void accept(const ShapeVisitor & visitor) override;
260 
266  virtual void accept(ConstShapeVisitor & visitor) const override;
267 
273  virtual void accept(const ConstShapeVisitor & visitor) const override;
274 
280  virtual Shape * accept(CompositeShapeTransform & transform) const override;
281 
287  virtual Shape * accept(const CompositeShapeTransform & transform) const override;
288 
289  Rect boundingBox(LineWidthFlag) const override;
290 
291  Bezier * clone() const override;
292 
293  inline const Path & path() const;
294 
295  inline const Path & controls() const;
296 
297  Path discretizedPath() const;
298  std::vector<Point> pathThroughLocalExtremums() const;
299 
300  Bezier & operator+=(const Bezier & other);
301 
302  Bezier operator+(const Bezier & other) const;
303 
304  static Bezier smoothedPolyline(const std::vector<Point> & path, double roundness, const Style & style = Style::defaultStyle());
305  static Bezier smoothedPolyline(const Path & path, double roundness, const Style & style = Style::defaultStyle());
306  static Bezier interpolation(const Point & y0, const Point & y1, const Point & y2, const Point & y3, const Style & style = Style::defaultStyle());
307 
308  Bezier(const Bezier &) = default;
309  Bezier(Bezier &&) = default;
310  Bezier & operator=(Bezier &&) = default;
311  Bezier & operator=(const Bezier &) = default;
312  ~Bezier() override = default;
313 
314 public: // TODO Make private
315  static const std::string _name;
316  Point eval(const Point & p0, const Point & p1, const Point & p2, const Point & p3, double t) const;
317  Point eval(Path::size_type interval, double t) const;
318 
319 protected:
320  Path _path;
321  Path _controls;
322 };
323 
324 // Inline methods
325 
326 const Path & Bezier::path() const
327 {
328  return _path;
329 }
330 
331 const Path & Bezier::controls() const
332 {
333  return _controls;
334 }
335 
336 } // namespace LibBoard
337 
338 #endif /* BOARD_BEZIER_H */
LibBoard::Style::defaultPenColor
static const Color & defaultPenColor()
defaultPenColor
Definition: Style.h:281
LibBoard::Bezier::scaleAll
void scaleAll(double s) override
Definition: Bezier.cpp:194
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::Bezier::rotate
Bezier & rotate(double angle, const Point &center) override
Rotate the Bezier curve.
Definition: Bezier.cpp:112
LibBoard::Bezier::translated
Bezier translated(double dx, double dy) const
Definition: Bezier.cpp:143
LibBoard::Bezier::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Bezier.cpp:546
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Bezier::name
const std::string & name() const override
Definition: Bezier.cpp:107
LibBoard::Style::defaultFillColor
static const Color & defaultFillColor()
defaultFillColor
Definition: Style.h:286
LibBoard::Bezier::accept
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: Bezier.cpp:587
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Bezier::clone
Bezier * clone() const override
Definition: Bezier.cpp:205
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::Bezier::translate
Bezier & translate(double dx, double dy) override
Definition: Bezier.cpp:136
LibBoard::Bezier
A cubice polygonal line described by a series of 2D points.
Definition: Bezier.h:40
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::Bezier::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: Bezier.cpp:617
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Bezier::_name
static const std::string _name
Definition: Bezier.h:315
LibBoard::Bezier::resized
Bezier resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition: Bezier.cpp:200
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::Bezier::scaled
Bezier scaled(double sx, double sy) const
Definition: Bezier.cpp:184
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Bezier::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Bezier.cpp:579
LibBoard::Shape::center
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition: Shape.cpp:59
LibBoard::Bezier::scale
Bezier & scale(double sx, double sy) override
Definition: Bezier.cpp:148
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::Bezier::Bezier
Bezier(const std::vector< Point > &points, const std::vector< Point > &controls, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
A cubic bezier curve.
Definition: Bezier.cpp:66
LibBoard::Bezier::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Bezier.cpp:537
LibBoard::Style::defaultStyle
static const Style & defaultStyle()
defaultStyle
Definition: Style.h:271
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::Bezier::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Bezier.cpp:473
LibBoard::Color
Structure representing an RGB triple.
Definition: Color.h:43
LibBoard::ShapeWithStyle
Abstract structure for a 2D shape.
Definition: ShapeWithStyle.h:38