Code

update to latest 2geom (rev1497)
[inkscape.git] / src / 2geom / ellipse.h
1 /*
2  * Ellipse Curve
3  *
4  * Authors:
5  *      Marco Cecchetti <mrcekets at gmail.com>
6  *
7  * Copyright 2008  authors
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it either under the terms of the GNU Lesser General Public
11  * License version 2.1 as published by the Free Software Foundation
12  * (the "LGPL") or, at your option, under the terms of the Mozilla
13  * Public License Version 1.1 (the "MPL"). If you do not alter this
14  * notice, a recipient may use your version of this file under either
15  * the MPL or the LGPL.
16  *
17  * You should have received a copy of the LGPL along with this library
18  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  * You should have received a copy of the MPL along with this library
21  * in the file COPYING-MPL-1.1
22  *
23  * The contents of this file are subject to the Mozilla Public License
24  * Version 1.1 (the "License"); you may not use this file except in
25  * compliance with the License. You may obtain a copy of the License at
26  * http://www.mozilla.org/MPL/
27  *
28  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
29  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
30  * the specific language governing rights and limitations.
31  */
34 #ifndef _2GEOM_ELLIPSE_H_
35 #define _2GEOM_ELLIPSE_H_
38 #include <2geom/point.h>
39 #include <2geom/exception.h>
40 #include <2geom/matrix.h>
42 namespace Geom
43 {
45 class SVGEllipticalArc;
47 class Ellipse
48 {
49   public:
50     Ellipse()
51     {}
53     Ellipse(double cx, double cy, double rx, double ry, double a)
54         : m_centre(cx, cy), m_ray(rx, ry), m_angle(a)
55     {
56     }
58     // build an ellipse by its implicit equation:
59     // Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
60     Ellipse(double A, double B, double C, double D, double E, double F)
61     {
62         set(A, B, C, D, E, F);
63     }
65     Ellipse(std::vector<Point> const& points)
66     {
67         set(points);
68     }
70     void set(double cx, double cy, double rx, double ry, double a)
71     {
72         m_centre[X] = cx;
73         m_centre[Y] = cy;
74         m_ray[X] = rx;
75         m_ray[Y] = ry;
76         m_angle = a;
77     }
79     // build an ellipse by its implicit equation:
80     // Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
81     void set(double A, double B, double C, double D, double E, double F);
83     // biuld up the best fitting ellipse wrt the passed points
84     // prerequisite: at least 5 points must be passed
85     void set(std::vector<Point> const& points);
87     SVGEllipticalArc
88     arc(Point const& initial, Point const& inner, Point const& final,
89         bool _svg_compliant = true);
91     Point center() const
92     {
93         return m_centre;
94     }
96     Coord center(Dim2 d) const
97     {
98         return m_centre[d];
99     }
101     Coord ray(Dim2 d) const
102     {
103         return m_ray[d];
104     }
106     Coord rot_angle() const
107     {
108         return m_angle;
109     }
111     std::vector<double> implicit_form_coefficients() const;
113     Ellipse transformed(Matrix const& m) const;
115   private:
116     Point m_centre, m_ray;
117     double m_angle;
118 };
121 } // end namespace Geom
125 #endif // _2GEOM_ELLIPSE_H_
128 /*
129   Local Variables:
130   mode:c++
131   c-file-style:"stroustrup"
132   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
133   indent-tabs-mode:nil
134   fill-column:99
135   End:
136 */
137 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :