Board 0.9.6
Ellipse.h
Go to the documentation of this file.
1/* -*- mode: c++ -*- */
26#ifndef BOARD_ELLIPSE_H
27#define BOARD_ELLIPSE_H
28
30
31namespace LibBoard
32{
33
38struct Ellipse : public ShapeWithStyle {
39
41 {
46 };
47
48 inline Ellipse(double x, double y, double xRadius, double yRadius, //
51
52 inline Ellipse(Point center, double xRadius, double yRadius, //
55
56 inline Ellipse(Point center, double xRadius, double yRadius, Style style);
57
63 const std::string & name() const override;
64
65 Point center(LineWidthFlag lineWidthFlag = IgnoreLineWidth) const override;
66
67 inline double xRadius() const;
68 inline double yRadius() const;
69 inline double angle() const;
70
71 Ellipse & rotate(double angle, const Point & center) override;
72
81 Ellipse rotated(double angle, const Point & center) const;
82
83 Ellipse & rotate(double angle) override;
84
92 Ellipse rotated(double angle) const;
93
102 Ellipse & translate(double dx, double dy) override;
103
112 Ellipse translated(double dx, double dy) const;
113
122 Ellipse & scale(double sx, double sy) override;
123
131 Ellipse & scale(double s) override;
132
141 Ellipse scaled(double sx, double sy) const;
142
150 Ellipse scaled(double s) const;
151
158 void scaleAll(double s) override;
159
168 Ellipse resized(double w, double h, LineWidthFlag lineWidthFlag) const;
169
170 void flushPostscript(std::ostream & stream, const TransformEPS & transform) const override;
171
172 void flushFIG(std::ostream & stream, const TransformFIG & transform, std::map<Color, int> & colormap) const override;
173
174 void flushSVG(std::ostream & stream, const TransformSVG & transform) const override;
175
176 void flushTikZ(std::ostream & stream, const TransformTikZ & transform) const override;
177
183 virtual void accept(ShapeVisitor & visitor) override;
184
190 virtual void accept(const ShapeVisitor & visitor) override;
191
197 virtual void accept(ConstShapeVisitor & visitor) const override;
198
204 virtual void accept(const ConstShapeVisitor & visitor) const override;
205
211 virtual Shape * accept(CompositeShapeTransform & transform) const override;
212
218 virtual Shape * accept(const CompositeShapeTransform & transform) const override;
219
220 Rect boundingBox(LineWidthFlag) const override;
221
222 Ellipse * clone() const override;
223
227 void setCircleFlag();
228
233 double perimeter() const;
234
241 Path sampledPath(int n, SamplingStart start = SamplingFromRight) const;
242
243 Ellipse(const Ellipse &) = default;
244 Ellipse(Ellipse &&) = default;
245 Ellipse & operator=(Ellipse &&) = default;
246 Ellipse & operator=(const Ellipse &) = default;
247 ~Ellipse() override = default;
248
249private:
250 static const std::string _name;
251 bool isACircle() const;
252 inline void normaliseAngle();
253
254protected:
256 double _xRadius;
257 double _yRadius;
258 double _angle;
260};
261
262Ellipse circle(double x, double y, double radius, //
263 Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
264 double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle());
265
266Ellipse circle(Point center, double radius, //
267 Color penColor = Style::defaultPenColor(), Color fillColor = Style::defaultFillColor(), //
268 double lineWidth = Style::defaultLineWidth(), const LineStyle lineStyle = Style::defaultLineStyle());
269
270Ellipse circle(Point center, double radius, Style style);
271
272// Inline methods
273
274Ellipse::Ellipse(double x, double y, double xRadius, double yRadius, Color penColor, Color fillColor, double lineWidth, LineStyle lineStyle)
275 : ShapeWithStyle(penColor, fillColor, lineWidth, lineStyle, ButtCap, MiterJoin), //
276 _center(x, y), _xRadius(xRadius), _yRadius(yRadius), _angle(0.0), _isCreatedAsCircle(false)
277{
278 normaliseAngle();
279}
280
281Ellipse::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 normaliseAngle();
286}
287
288inline Ellipse::Ellipse(Point center, double xRadius, double yRadius, Style style) //
289 : ShapeWithStyle(style), //
290 _center(center), _xRadius(xRadius), _yRadius(yRadius), _angle(0.0), _isCreatedAsCircle(false)
291{
292 normaliseAngle();
293}
294
295inline void Ellipse::normaliseAngle()
296{
297 while (_angle > M_PI_2) {
298 _angle -= M_PI;
299 }
300 while (_angle < -M_PI_2) {
301 _angle += M_PI;
302 }
303}
304
305double Ellipse::xRadius() const
306{
307 return _xRadius;
308}
309
310double Ellipse::yRadius() const
311{
312 return _yRadius;
313}
314
315double Ellipse::angle() const
316{
317 return _angle;
318}
319
320} // namespace LibBoard
321
322#endif /* BOARD_ELLIPSE_H */
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
#define M_PI_2
Definition Shape.h:50
#define M_PI
Definition Shape.h:46
Structure representing an RGB triple.
Definition Color.h:43
Definition Board.h:55
Ellipse circle(double x, double y, double radius, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle())
Definition Ellipse.cpp:371
LineStyle
Definition Style.h:47
@ ButtCap
Definition Style.h:36
LineWidthFlag
Definition Style.h:57
@ IgnoreLineWidth
Definition Style.h:58
@ MiterJoin
Definition Style.h:42
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
An ellipse.
Definition Ellipse.h:38
double perimeter() const
Definition Ellipse.cpp:185
Ellipse(double x, double y, double xRadius, double yRadius, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), LineStyle lineStyle=Style::defaultLineStyle())
Definition Ellipse.h:274
void scaleAll(double s) override
Definition Ellipse.cpp:163
Point _center
Definition Ellipse.h:255
Ellipse & rotate(double angle, const Point &center) override
Definition Ellipse.cpp:60
Ellipse(Ellipse &&)=default
Ellipse resized(double w, double h, LineWidthFlag lineWidthFlag) const
Definition Ellipse.cpp:170
double _xRadius
Definition Ellipse.h:256
Path sampledPath(int n, SamplingStart start=SamplingFromRight) const
Definition Ellipse.cpp:198
Ellipse(const Ellipse &)=default
double angle() const
Definition Ellipse.h:315
Ellipse & operator=(Ellipse &&)=default
Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const override
Definition Ellipse.cpp:55
double yRadius() const
Definition Ellipse.h:310
virtual void accept(ShapeVisitor &visitor) override
Accepts a visitor object.
Definition Ellipse.cpp:316
const std::string & name() const override
Definition Ellipse.cpp:50
~Ellipse() override=default
Ellipse & translate(double dx, double dy) override
Definition Ellipse.cpp:87
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const override
Definition Ellipse.cpp:242
void flushFIG(std::ostream &stream, const TransformFIG &transform, std::map< Color, int > &colormap) const override
Definition Ellipse.cpp:276
void setCircleFlag()
Definition Ellipse.cpp:180
SamplingStart
Definition Ellipse.h:41
@ SamplingFromBottom
Definition Ellipse.h:45
@ SamplingFromRight
Definition Ellipse.h:42
@ SamplingFromLeft
Definition Ellipse.h:44
@ SamplingFromTop
Definition Ellipse.h:43
double xRadius() const
Definition Ellipse.h:305
double _yRadius
Definition Ellipse.h:257
void flushTikZ(std::ostream &stream, const TransformTikZ &transform) const override
Definition Ellipse.cpp:308
bool _isCreatedAsCircle
Definition Ellipse.h:259
Ellipse & operator=(const Ellipse &)=default
Ellipse scaled(double sx, double sy) const
Definition Ellipse.cpp:153
void flushSVG(std::ostream &stream, const TransformSVG &transform) const override
Definition Ellipse.cpp:298
Rect boundingBox(LineWidthFlag) const override
Definition Ellipse.cpp:346
Ellipse rotated(double angle, const Point &center) const
Definition Ellipse.cpp:72
Ellipse & scale(double sx, double sy) override
Definition Ellipse.cpp:98
Ellipse * clone() const override
Definition Ellipse.cpp:175
Ellipse translated(double dx, double dy) const
Definition Ellipse.cpp:93
double _angle
Definition Ellipse.h:258
A path, according to Postscript and SVG definition.
Definition Path.h:45
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
const Color & penColor() const
Definition ShapeWithStyle.h:143
Style style() const
Definition ShapeWithStyle.h:215
double lineWidth() const
Definition ShapeWithStyle.h:165
const Color & fillColor() const
Definition ShapeWithStyle.h:154
LineStyle lineStyle() const
Definition ShapeWithStyle.h:176
Abstract structure for a 2D shape.
Definition Shape.h:64
Definition Style.h:69
static const Color & defaultPenColor()
defaultPenColor
Definition Style.h:279
static const Color & defaultFillColor()
defaultFillColor
Definition Style.h:284
static const double & defaultLineWidth()
defaultLineWidth
Definition Style.h:274
static const LineStyle & defaultLineStyle()
defaultLineStyle
Definition Style.h:289
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