Board  0.9.5
Ellipse.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_ELLIPSE_H
27 #define BOARD_ELLIPSE_H
28 
29 #include "board/ShapeWithStyle.h"
30 
31 namespace LibBoard
32 {
33 
38 struct Ellipse : public ShapeWithStyle {
39 
40  enum SamplingStart
41  {
42  SamplingFromRight,
43  SamplingFromTop,
44  SamplingFromLeft,
45  SamplingFromBottom
46  };
47 
48  inline Ellipse(double x, double y, double xRadius, double yRadius, //
49  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
50  double lineWidth = Style::defaultLineWidth(), LineStyle lineStyle = Style::defaultLineStyle());
51 
52  inline Ellipse(Point center, double xRadius, double yRadius, //
53  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
54  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle());
55 
61  const std::string & name() const override;
62 
63  Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
64 
65  inline double xRadius() const;
66  inline double yRadius() const;
67  inline double angle() const;
68 
69  Ellipse & rotate(double angle, const Point & center) override;
70 
79  Ellipse rotated(double angle, const Point & center) const;
80 
81  Ellipse & rotate(double angle) override;
82 
90  Ellipse rotated(double angle) const;
91 
100  Ellipse & translate(double dx, double dy) override;
101 
110  Ellipse translated(double dx, double dy) const;
111 
120  Ellipse & scale(double sx, double sy) override;
121 
129  Ellipse & scale(double s) override;
130 
139  Ellipse scaled(double sx, double sy) const;
140 
148  Ellipse scaled(double s) const;
149 
156  void scaleAll(double s) override;
157 
166  Ellipse resized(double w, double h, LineWidthFlag lineWidthFlag) const;
167 
168  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
169 
170  void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
171 
172  void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
173 
174  void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
175 
181  virtual void accept(ShapeVisitor & visitor) override;
182 
188  virtual void accept(const ShapeVisitor & visitor) override;
189 
195  virtual void accept(ConstShapeVisitor & visitor) const override;
196 
202  virtual void accept(const ConstShapeVisitor & visitor) const override;
203 
209  virtual Shape * accept(CompositeShapeTransform & transform) const override;
210 
216  virtual Shape * accept(const CompositeShapeTransform & transform) const override;
217 
218  Rect boundingBox(LineWidthFlag) const override;
219 
220  Ellipse * clone() const override;
221 
225  void setCircleFlag();
226 
231  double perimeter() const;
232 
239  Path sampledPath(int n, SamplingStart start = SamplingFromRight) const;
240 
241  Ellipse(const Ellipse &) = default;
242  Ellipse(Ellipse &&) = default;
243  Ellipse & operator=(Ellipse &&) = default;
244  Ellipse & operator=(const Ellipse &) = default;
245  ~Ellipse() override = default;
246 
247 private:
248  static const std::string _name;
249  bool isACircle() const;
250 
251 protected:
252  Point _center;
253  double _xRadius;
254  double _yRadius;
255  double _angle;
256  bool _isCreatedAsCircle;
257 };
258 
259 Ellipse circle(double x, double y, double radius, //
260  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
261  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle());
262 
263 Ellipse circle(Point center, double radius, //
264  Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
265  double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle());
266 
267 // Inline methods
268 
269 Ellipse::Ellipse(double x, double y, double xRadius, double yRadius, Color penColor, Color fillColor, double lineWidth, LineStyle lineStyle)
270  : ShapeWithStyle(penColor, fillColor, lineWidth, lineStyle, ButtCap, MiterJoin), //
271  _center(x, y), _xRadius(xRadius), _yRadius(yRadius), _angle(0.0), _isCreatedAsCircle(false)
272 {
273  while (_angle > M_PI_2) {
274  _angle -= M_PI;
275  }
276  while (_angle < -M_PI_2) {
277  _angle += M_PI;
278  }
279 }
280 
281 Ellipse::Ellipse(Point center, double xRadius, double yRadius, Color penColor, Color fillColor, double lineWidth, const LineStyle lineStyle)
282  : ShapeWithStyle(penColor, fillColor, lineWidth, lineStyle, ButtCap, MiterJoin), //
283  _center(center), _xRadius(xRadius), _yRadius(yRadius), _angle(0.0), _isCreatedAsCircle(false)
284 {
285  while (_angle > M_PI_2) {
286  _angle -= M_PI;
287  }
288  while (_angle < -M_PI_2) {
289  _angle += M_PI;
290  }
291 }
292 
293 double Ellipse::xRadius() const
294 {
295  return _xRadius;
296 }
297 
298 double Ellipse::yRadius() const
299 {
300  return _yRadius;
301 }
302 
303 double Ellipse::angle() const
304 {
305  return _angle;
306 }
307 
308 } // namespace LibBoard
309 
310 #endif /* BOARD_ELLIPSE_H */
LibBoard::Style::defaultPenColor
static const Color & defaultPenColor()
defaultPenColor
Definition: Style.h:281
LibBoard::Ellipse::clone
Ellipse * clone() const override
Definition: Ellipse.cpp:175
LibBoard::Ellipse::perimeter
double perimeter() const
Definition: Ellipse.cpp:185
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::Ellipse::boundingBox
Rect boundingBox(LineWidthFlag) const override
Definition: Ellipse.cpp:346
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Ellipse::sampledPath
Path sampledPath(int n, SamplingStart start=SamplingFromRight) const
Definition: Ellipse.cpp:198
LibBoard::Style::defaultFillColor
static const Color & defaultFillColor()
defaultFillColor
Definition: Style.h:286
LibBoard::CompositeShapeTransform
A CompositeShapeTransform may be used to duplicate/transform a composite shape tree.
Definition: ShapeVisitor.h:103
LibBoard::Ellipse::flushFIG
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition: Ellipse.cpp:276
LibBoard::Ellipse::flushTikZ
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition: Ellipse.cpp:308
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::Ellipse::flushSVG
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition: Ellipse.cpp:298
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Ellipse::resized
Ellipse resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition: Ellipse.cpp:170
LibBoard::Ellipse::accept
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition: Ellipse.cpp:316
LibBoard::Shape
Abstract structure for a 2D shape.
Definition: Shape.h:63
LibBoard::Ellipse::center
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition: Ellipse.cpp:55
LibBoard::Ellipse::setCircleFlag
void setCircleFlag()
Definition: Ellipse.cpp:180
LibBoard::Ellipse::rotate
Ellipse & rotate(double angle, const Point &center) override
Definition: Ellipse.cpp:60
LibBoard::ConstShapeVisitor
A ConstShapeVisitor may visit const shapes of a composite shape tree in back-to-front order.
Definition: ShapeVisitor.h:78
LibBoard::Ellipse::name
const std::string & name() const override
Definition: Ellipse.cpp:50
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::Ellipse::scaled
Ellipse scaled(double sx, double sy) const
Definition: Ellipse.cpp:153
LibBoard::Ellipse::translate
Ellipse & translate(double dx, double dy) override
Definition: Ellipse.cpp:87
LibBoard::Ellipse
An ellipse.
Definition: Ellipse.h:38
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::Ellipse::translated
Ellipse translated(double dx, double dy) const
Definition: Ellipse.cpp:93
LibBoard::Style::defaultLineStyle
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition: Style.h:291
LibBoard::Ellipse::scaleAll
void scaleAll(double s) override
Definition: Ellipse.cpp:163
LibBoard::Ellipse::scale
Ellipse & scale(double sx, double sy) override
Definition: Ellipse.cpp:98
LibBoard::Ellipse::rotated
Ellipse rotated(double angle, const Point &center) const
Definition: Ellipse.cpp:72
LibBoard::Ellipse::flushPostscript
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition: Ellipse.cpp:242
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