Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
circle.h
Go to the documentation of this file.
1/*
4 * Authors:
5 * Marco Cecchetti <mrcekets at gmail.com>
6 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
7 *
8 * Copyright 2008-2014 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 */
33
34#ifndef LIB2GEOM_SEEN_CIRCLE_H
35#define LIB2GEOM_SEEN_CIRCLE_H
36
37#include <2geom/forward.h>
38#include <2geom/intersection.h>
39#include <2geom/point.h>
40#include <2geom/rect.h>
41#include <2geom/transforms.h>
42
43namespace Geom {
44
45class EllipticalArc;
46
49class Circle
50 : boost::equality_comparable1< Circle
51 , MultipliableNoncommutative< Circle, Translate
52 , MultipliableNoncommutative< Circle, Rotate
53 , MultipliableNoncommutative< Circle, Zoom
54 > > > >
55{
58
59public:
60 Circle() {}
62 : _center(cx, cy), _radius(r)
63 {}
66 {}
67
69 setCoefficients(A, B, C, D);
70 }
71
72 // Construct the unique circle passing through three points.
73 //Circle(Point const &a, Point const &b, Point const &c);
74
75 Point center() const { return _center; }
76 Coord center(Dim2 d) const { return _center[d]; }
77 Coord radius() const { return _radius; }
78 Coord area() const { return M_PI * _radius * _radius; }
79 bool isDegenerate() const { return _radius == 0; }
80
81 void setCenter(Point const &p) { _center = p; }
82 void setRadius(Coord c) { _radius = c; }
83
84 Rect boundsFast() const;
85 Rect boundsExact() const { return boundsFast(); }
86
87 Point initialPoint() const;
88 Point finalPoint() const { return initialPoint(); }
89 Point pointAt(Coord t) const;
90 Coord valueAt(Coord t, Dim2 d) const;
91 Coord timeAt(Point const &p) const;
92 Coord nearestTime(Point const &p) const;
93
94 bool contains(Point const &p) const { return distance(p, _center) <= _radius; }
95 bool contains(Rect const &other) const;
96 bool contains(Circle const &other) const;
97
98 bool intersects(Line const &l) const;
99 bool intersects(LineSegment const &l) const;
100 bool intersects(Circle const &other) const;
101
102 std::vector<ShapeIntersection> intersect(Line const &other) const;
103 std::vector<ShapeIntersection> intersect(LineSegment const &other) const;
104 std::vector<ShapeIntersection> intersect(Circle const &other) const;
105
106 // build a circle by its implicit equation:
107 // Ax^2 + Ay^2 + Bx + Cy + D = 0
108 void setCoefficients(Coord A, Coord B, Coord C, Coord D);
109 void coefficients(Coord &A, Coord &B, Coord &C, Coord &D) const;
110 std::vector<Coord> coefficients() const;
111
114
116 arc(Point const& initial, Point const& inner, Point const& final) const;
117
118 D2<SBasis> toSBasis() const;
119
121 _center *= t;
122 return *this;
123 }
125 return *this;
126 }
127 Circle &operator*=(Zoom const &z) {
128 _center *= z;
129 _radius *= z.scale();
130 return *this;
131 }
132
133 bool operator==(Circle const &other) const;
134
137 void fit(std::vector<Point> const &points);
138};
139
140bool are_near(Circle const &a, Circle const &b, Coord eps=EPSILON);
141
142std::ostream &operator<<(std::ostream &out, Circle const &c);
143
144template <>
151
152} // end namespace Geom
153
154#endif // LIB2GEOM_SEEN_CIRCLE_H
155
156/*
157 Local Variables:
158 mode:c++
159 c-file-style:"stroustrup"
160 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
161 indent-tabs-mode:nil
162 fill-column:99
163 End:
164*/
165// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cartesian point / 2D vector and related operations.
Set of all points at a fixed distance from the center.
Definition circle.h:55
Point center() const
Definition circle.h:75
Point finalPoint() const
Definition circle.h:88
Coord center(Dim2 d) const
Definition circle.h:76
Coord area() const
Definition circle.h:78
Rect boundsExact() const
Definition circle.h:85
Circle & operator*=(Rotate const &)
Definition circle.h:124
Circle & operator*=(Translate const &t)
Definition circle.h:120
Point initialPoint() const
Definition circle.cpp:104
EllipticalArc * arc(Point const &initial, Point const &inner, Point const &final) const
Definition circle.cpp:254
Circle & operator*=(Zoom const &z)
Definition circle.h:127
Zoom inverseUnitCircleTransform() const
Definition circle.cpp:94
std::vector< ShapeIntersection > intersect(Line const &other) const
Definition circle.cpp:163
Coord _radius
Definition circle.h:57
Coord valueAt(Coord t, Dim2 d) const
Definition circle.cpp:115
D2< SBasis > toSBasis() const
Definition circle.cpp:268
Point _center
Definition circle.h:56
bool isDegenerate() const
Definition circle.h:79
Coord timeAt(Point const &p) const
Definition circle.cpp:120
Zoom unitCircleTransform() const
Definition circle.cpp:88
void setRadius(Coord c)
Definition circle.h:82
void setCenter(Point const &p)
Definition circle.h:81
bool contains(Point const &p) const
Definition circle.h:94
Coord nearestTime(Point const &p) const
Definition circle.cpp:125
Coord radius() const
Definition circle.h:77
Circle(Coord A, Coord B, Coord C, Coord D)
Definition circle.h:68
Circle(Point const &center, Coord r)
Definition circle.h:64
bool intersects(LineSegment const &l) const
std::vector< Coord > coefficients() const
Definition circle.cpp:80
Circle(Coord cx, Coord cy, Coord r)
Definition circle.h:61
void setCoefficients(Coord A, Coord B, Coord C, Coord D)
Definition circle.cpp:49
Rect boundsFast() const
Definition circle.cpp:42
Point pointAt(Coord t) const
Definition circle.cpp:111
Adaptor that creates 2D functions from 1D ones.
Definition d2.h:55
Set of points with a constant sum of distances from two foci.
Definition ellipse.h:68
Elliptical arc curve.
Intersection between two shapes.
Range of real numbers that is never empty.
Definition interval.h:59
Infinite line on a plane.
Definition line.h:53
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Rotation around the origin.
Definition transforms.h:187
Translation by a vector.
Definition transforms.h:115
Combination of a translation and uniform scale.
Definition transforms.h:292
Coord scale() const
Definition transforms.h:316
double inner(valarray< double > const &x, valarray< double > const &y)
double c[8][4]
Contains forward declarations of 2geom types.
Dim2
2D axis enumeration (X or Y).
Definition coord.h:48
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
constexpr Coord EPSILON
Default "acceptably small" value.
Definition coord.h:84
Intersection utilities.
Various utility functions.
Definition affine.h:22
Angle distance(Angle const &a, Angle const &b)
Definition angle.h:163
@ intersects
Definition geom.cpp:16
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Axis-aligned rectangle.
Intersection IntersectionType
Definition circle.h:149
Affine transformation classes.