1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /**
3  * SVG <ellipse> and related implementations
4  *
5  * Authors:
6  *   Lauris Kaplinski <lauris@kaplinski.com>
7  *   Mitsuru Oka
8  *   Tavmjong Bah
9  *
10  * Copyright (C) 1999-2002 Lauris Kaplinski
11  * Copyright (C) 2000-2001 Ximian, Inc.
12  * Copyright (C) 2013 Tavmjong Bah
13  *
14  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15  */
16 
17 #ifndef SEEN_SP_ELLIPSE_H
18 #define SEEN_SP_ELLIPSE_H
19 
20 #include "svg/svg-length.h"
21 #include "sp-shape.h"
22 
23 /* Common parent class */
24 #define SP_GENERICELLIPSE(obj) (dynamic_cast<SPGenericEllipse*>((SPObject*)obj))
25 #define SP_IS_GENERICELLIPSE(obj) (dynamic_cast<const SPGenericEllipse*>((SPObject*)obj) != NULL)
26 
27 enum GenericEllipseType {
28     SP_GENERIC_ELLIPSE_UNDEFINED, // FIXME shouldn't exist
29     SP_GENERIC_ELLIPSE_ARC,
30     SP_GENERIC_ELLIPSE_CIRCLE,
31     SP_GENERIC_ELLIPSE_ELLIPSE
32 };
33 
34 enum GenericEllipseArcType {
35     SP_GENERIC_ELLIPSE_ARC_TYPE_SLICE, // Default
36     SP_GENERIC_ELLIPSE_ARC_TYPE_ARC,
37     SP_GENERIC_ELLIPSE_ARC_TYPE_CHORD
38 };
39 
40 class SPGenericEllipse : public SPShape {
41 public:
42     SPGenericEllipse();
43     ~SPGenericEllipse() override;
44 
45     // Regardless of type, the ellipse/circle/arc is stored
46     // internally with these variables. (Circle radius is rx).
47     SVGLength cx;
48     SVGLength cy;
49     SVGLength rx;
50     SVGLength ry;
51 
52     // Return slice, chord, or arc.
arcType()53     GenericEllipseArcType arcType() { return arc_type; };
setArcType(GenericEllipseArcType type)54     void setArcType(GenericEllipseArcType type) { arc_type = type; };
55 
56     double start, end;
57     GenericEllipseType type;
58     GenericEllipseArcType arc_type;
59 
60     void build(SPDocument *document, Inkscape::XML::Node *repr) override;
61 
62     void set(SPAttr key, char const *value) override;
63     void update(SPCtx *ctx, unsigned int flags) override;
64 
65     Inkscape::XML::Node *write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override;
66     const char *displayName() const override;
67 
68     void set_shape() override;
69     void update_patheffect(bool write) override;
70     Geom::Affine set_transform(Geom::Affine const &xform) override;
71 
72     void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) const override;
73 
74     void modified(unsigned int flags) override;
75 
76     /**
77      * @brief Makes sure that start and end lie between 0 and 2 * PI.
78      */
79     void normalize();
80 
81     Geom::Point getPointAtAngle(double arg) const;
82 
83     bool set_elliptical_path_attribute(Inkscape::XML::Node *repr);
84     void position_set(double x, double y, double rx, double ry);
85 
86     double getVisibleRx() const;
87     void setVisibleRx(double rx);
88 
89     double getVisibleRy() const;
90     void setVisibleRy(double ry);
91 
92 protected:
93     /**
94      * @brief Determines whether the shape is a part of an ellipse.
95      */
96     bool _isSlice() const;
97 
98 private:
99     static double vectorStretch(Geom::Point p0, Geom::Point p1, Geom::Affine xform);
100 };
101 
102 #endif
103 
104 /*
105   Local Variables:
106   mode:c++
107   c-file-style:"stroustrup"
108   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
109   indent-tabs-mode:nil
110   fill-column:99
111   End:
112 */
113 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8 :
114