GCC Code Coverage Report


Directory: ./
File: include/2geom/circle.h
Date: 2024-03-18 17:01:34
Exec Total Coverage
Lines: 2 9 22.2%
Functions: 2 5 40.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /** @file
2 * @brief Circle shape
3 *//*
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
43 namespace Geom {
44
45 class EllipticalArc;
46
47 /** @brief Set of all points at a fixed distance from the center
48 * @ingroup Shapes */
49 class Circle
50 : boost::equality_comparable1< Circle
51 , MultipliableNoncommutative< Circle, Translate
52 , MultipliableNoncommutative< Circle, Rotate
53 , MultipliableNoncommutative< Circle, Zoom
54 > > > >
55 {
56 Point _center;
57 Coord _radius;
58
59 public:
60 Circle() {}
61 Circle(Coord cx, Coord cy, Coord r)
62 : _center(cx, cy), _radius(r)
63 {}
64 Circle(Point const &center, Coord r)
65 : _center(center), _radius(r)
66 {}
67
68 Circle(Coord A, Coord B, Coord C, Coord D) {
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 10 Point center() const { return _center; }
76 Coord center(Dim2 d) const { return _center[d]; }
77 32 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
112 Zoom unitCircleTransform() const;
113 Zoom inverseUnitCircleTransform() const;
114
115 EllipticalArc *
116 arc(Point const& initial, Point const& inner, Point const& final) const;
117
118 D2<SBasis> toSBasis() const;
119
120 Circle &operator*=(Translate const &t) {
121 _center *= t;
122 return *this;
123 }
124 Circle &operator*=(Rotate const &) {
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
135 /** @brief Fit the circle to the passed points using the least squares method.
136 * @param points Samples at the perimeter of the circle */
137 void fit(std::vector<Point> const &points);
138 };
139
140 bool are_near(Circle const &a, Circle const &b, Coord eps=EPSILON);
141
142 std::ostream &operator<<(std::ostream &out, Circle const &c);
143
144 template <>
145 struct ShapeTraits<Circle> {
146 typedef Coord TimeType;
147 typedef Interval IntervalType;
148 typedef Ellipse AffineClosureType;
149 typedef Intersection<> IntersectionType;
150 };
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 :
166