1 /**
2 * \file
3 * \brief Circle Curve
4 *
5 * Authors:
6 * Marco Cecchetti <mrcekets at gmail.com>
7 *
8 * Copyright 2008 authors
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it either under the terms of the GNU Lesser General Public
12 * License version 2.1 as published by the Free Software Foundation
13 * (the "LGPL") or, at your option, under the terms of the Mozilla
14 * Public License Version 1.1 (the "MPL"). If you do not alter this
15 * notice, a recipient may use your version of this file under either
16 * the MPL or the LGPL.
17 *
18 * You should have received a copy of the LGPL along with this library
19 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * You should have received a copy of the MPL along with this library
22 * in the file COPYING-MPL-1.1
23 *
24 * The contents of this file are subject to the Mozilla Public License
25 * Version 1.1 (the "License"); you may not use this file except in
26 * compliance with the License. You may obtain a copy of the License at
27 * http://www.mozilla.org/MPL/
28 *
29 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31 * the specific language governing rights and limitations.
32 */
35 #ifndef _2GEOM_CIRCLE_H_
36 #define _2GEOM_CIRCLE_H_
39 #include <2geom/point.h>
40 #include <2geom/exception.h>
43 namespace Geom
44 {
46 class SVGEllipticalArc;
48 class Circle
49 {
50 public:
51 Circle()
52 {}
54 Circle(double cx, double cy, double r)
55 : m_centre(cx, cy), m_ray(r)
56 {
57 }
59 Circle(double A, double B, double C, double D)
60 {
61 set(A, B, C, D);
62 }
64 Circle(std::vector<Point> const& points)
65 {
66 set(points);
67 }
69 void set(double cx, double cy, double r)
70 {
71 m_centre[X] = cx;
72 m_centre[Y] = cy;
73 m_ray = r;
74 }
77 // build a circle by its implicit equation:
78 // Ax^2 + Ay^2 + Bx + Cy + D = 0
79 void set(double A, double B, double C, double D);
81 // build up the best fitting circle wrt the passed points
82 // prerequisite: at least 3 points must be passed
83 void set(std::vector<Point> const& points);
85 SVGEllipticalArc
86 arc(Point const& initial, Point const& inner, Point const& final,
87 bool _svg_compliant = true);
89 Point center() const
90 {
91 return m_centre;
92 }
94 Coord center(Dim2 d) const
95 {
96 return m_centre[d];
97 }
99 Coord ray() const
100 {
101 return m_ray;
102 }
105 private:
106 Point m_centre;
107 Coord m_ray;
108 };
111 } // end namespace Geom
115 #endif // _2GEOM_CIRCLE_H_
118 /*
119 Local Variables:
120 mode:c++
121 c-file-style:"stroustrup"
122 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123 indent-tabs-mode:nil
124 fill-column:99
125 End:
126 */
127 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :