Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
pathvector.h
Go to the documentation of this file.
1/*
4 * Authors:
5 * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
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_PATHVECTOR_H
35#define LIB2GEOM_SEEN_PATHVECTOR_H
36
37#include <optional>
38#include <boost/concept/requires.hpp>
39#include <boost/range/algorithm/equal.hpp>
40#include <2geom/forward.h>
41#include <2geom/path.h>
42#include <2geom/transforms.h>
43
44namespace Geom {
45
56 : public PathTime
57 , boost::totally_ordered<PathVectorTime>
58{
60
63 : PathTime(_c, _t), path_index(_i) {}
65 : PathTime(pos), path_index(_i) {}
66
67 bool operator<(PathVectorTime const &other) const {
68 if (path_index < other.path_index) return true;
69 if (path_index == other.path_index) {
70 return static_cast<PathTime const &>(*this) < static_cast<PathTime const &>(other);
71 }
72 return false;
73 }
74 bool operator==(PathVectorTime const &other) const {
75 return path_index == other.path_index
76 && static_cast<PathTime const &>(*this) == static_cast<PathTime const &>(other);
77 }
78
79 PathTime const &asPathTime() const {
80 return *static_cast<PathTime const *>(this);
81 }
82};
83
84inline std::ostream &operator<<(std::ostream &os, PathVectorTime const &pvt) {
85 os << pvt.path_index << ": " << pvt.asPathTime();
86 return os;
87}
88
91
92template <>
95 //typedef PathVectorInterval IntervalType;
98};
99
113 : MultipliableNoncommutative< PathVector, Affine
114 , MultipliableNoncommutative< PathVector, Translate
115 , MultipliableNoncommutative< PathVector, Scale
116 , MultipliableNoncommutative< PathVector, Rotate
117 , MultipliableNoncommutative< PathVector, HShear
118 , MultipliableNoncommutative< PathVector, VShear
119 , MultipliableNoncommutative< PathVector, Zoom
120 , boost::equality_comparable< PathVector
121 > > > > > > > >
122{
123 typedef std::vector<Path> Sequence;
124public:
126 typedef Sequence::iterator iterator;
127 typedef Sequence::const_iterator const_iterator;
128 typedef Sequence::size_type size_type;
130 typedef Path &reference;
131 typedef Path const &const_reference;
132 typedef Path *pointer;
133 typedef std::ptrdiff_t difference_type;
134
136 PathVector(Path const &p)
137 : _data(1, p)
138 {}
139 template <typename InputIter>
140 PathVector(InputIter first, InputIter last)
141 : _data(first, last)
142 {}
143
145 bool empty() const { return _data.empty(); }
147 size_type size() const { return _data.size(); }
149 size_type curveCount() const;
150
151 iterator begin() { return _data.begin(); }
152 iterator end() { return _data.end(); }
153 const_iterator begin() const { return _data.begin(); }
154 const_iterator end() const { return _data.end(); }
156 return _data[index];
157 }
159 return _data[index];
160 }
162 return _data.at(index);
163 }
164 Path const &at(size_type index) const {
165 return _data.at(index);
166 }
167 Path &front() { return _data.front(); }
168 Path const &front() const { return _data.front(); }
169 Path &back() { return _data.back(); }
170 Path const &back() const { return _data.back(); }
172 void push_back(Path const &path) {
173 _data.push_back(path);
174 }
176 void pop_back() {
177 _data.pop_back();
178 }
179 iterator insert(iterator pos, Path const &p) {
180 return _data.insert(pos, p);
181 }
182 template <typename InputIter>
183 void insert(iterator out, InputIter first, InputIter last) {
184 _data.insert(out, first, last);
185 }
188 return _data.erase(i);
189 }
192 return _data.erase(first, last);
193 }
195 void clear() { _data.clear(); }
199 void resize(size_type n) { _data.resize(n); }
204 void reverse(bool reverse_paths = true);
209 PathVector reversed(bool reverse_paths = true) const;
210
213 Interval ret(0, curveCount()); return ret;
214 }
218 return _data.front().initialPoint();
219 }
223 return _data.back().finalPoint();
224 }
227 std::vector<PathVectorIntersection> intersectSelf(Coord precision = EPSILON) const;
228 Path &pathAt(Coord t, Coord *rest = NULL);
229 Path const &pathAt(Coord t, Coord *rest = NULL) const;
230 Curve const &curveAt(Coord t, Coord *rest = NULL) const;
231 Coord valueAt(Coord t, Dim2 d) const;
232 Point pointAt(Coord t) const;
233
235 return const_cast<Path &>(static_cast<PathVector const*>(this)->pathAt(pos));
236 }
237 Path const &pathAt(PathVectorTime const &pos) const {
238 return at(pos.path_index);
239 }
240 Curve const &curveAt(PathVectorTime const &pos) const {
241 return at(pos.path_index).at(pos.curve_index);
242 }
243 Point pointAt(PathVectorTime const &pos) const {
244 return at(pos.path_index).at(pos.curve_index).pointAt(pos.t);
245 }
246 Coord valueAt(PathVectorTime const &pos, Dim2 d) const {
247 return at(pos.path_index).at(pos.curve_index).valueAt(pos.t, d);
248 }
249
250 OptRect boundsFast() const;
251 OptRect boundsExact() const;
252
253 template <typename T>
255 operator*=(T const &t) {
256 if (empty()) return *this;
257 for (auto & i : *this) {
258 i *= t;
259 }
260 return *this;
261 }
262
263 bool operator==(PathVector const &other) const {
264 return boost::range::equal(_data, other._data);
265 }
266
267 void snapEnds(Coord precision = EPSILON);
268
269 std::vector<PVIntersection> intersect(PathVector const &other, Coord precision = EPSILON) const;
270
273 int winding(Point const &p) const;
274
275 std::optional<PathVectorTime> nearestTime(Point const &p, Coord *dist = NULL) const;
276 std::vector<PathVectorTime> allNearestTimes(Point const &p, Coord *dist = NULL) const;
277
278 std::vector<Point> nodes() const;
279
280private:
282
284};
285
286inline OptRect bounds_fast(PathVector const &pv) { return pv.boundsFast(); }
287inline OptRect bounds_exact(PathVector const &pv) { return pv.boundsExact(); }
288
289std::ostream &operator<<(std::ostream &out, PathVector const &pv);
290
291} // end namespace Geom
292
293#endif // LIB2GEOM_SEEN_PATHVECTOR_H
294
295/*
296 Local Variables:
297 mode:c++
298 c-file-style:"stroustrup"
299 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
300 indent-tabs-mode:nil
301 fill-column:99
302 End:
303*/
304// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Path - a sequence of contiguous curves.
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
virtual Coord valueAt(Coord t, Dim2 d) const
Evaluate one of the coordinates at the specified time value.
Definition curve.h:116
virtual Point pointAt(Coord t) const
Evaluate the curve at a specified time value.
Definition curve.h:110
Intersection between two shapes.
Range of real numbers that is never empty.
Definition interval.h:59
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Sequence of subpaths.
Definition pathvector.h:122
PathVector(Path const &p)
Definition pathvector.h:136
std::vector< PathVectorTime > allNearestTimes(Point const &p, Coord *dist=NULL) const
PathVectorTime _factorTime(Coord t) const
size_type size() const
Get the number of paths in the vector.
Definition pathvector.h:147
Path & pathAt(PathVectorTime const &pos)
Definition pathvector.h:234
Coord valueAt(Coord t, Dim2 d) const
void insert(iterator out, InputIter first, InputIter last)
Definition pathvector.h:183
std::vector< Point > nodes() const
const_iterator end() const
Definition pathvector.h:154
void push_back(Path const &path)
Append a path at the end.
Definition pathvector.h:172
Sequence::const_iterator const_iterator
Definition pathvector.h:127
bool operator==(PathVector const &other) const
Definition pathvector.h:263
OptRect boundsExact() const
BOOST_CONCEPT_REQUIRES(((TransformConcept< T >)),(PathVector &)) operator*
Definition pathvector.h:254
Coord valueAt(PathVectorTime const &pos, Dim2 d) const
Definition pathvector.h:246
iterator erase(iterator first, iterator last)
Remove a range of paths from the vector.
Definition pathvector.h:191
std::ptrdiff_t difference_type
Definition pathvector.h:133
Curve const & curveAt(PathVectorTime const &pos) const
Definition pathvector.h:240
Path & operator[](size_type index)
Definition pathvector.h:155
int winding(Point const &p) const
Determine the winding number at the specified point.
std::vector< Path > Sequence
Definition pathvector.h:123
Point finalPoint() const
Get the last point in the last path of the vector.
Definition pathvector.h:222
Interval timeRange() const
Get the range of allowed time values.
Definition pathvector.h:212
Point pointAt(Coord t) const
Point initialPoint() const
Get the first point in the first path of the vector.
Definition pathvector.h:217
PathVectorTime Position
Definition pathvector.h:125
Sequence::size_type size_type
Definition pathvector.h:128
void snapEnds(Coord precision=EPSILON)
Path const & back() const
Definition pathvector.h:170
iterator erase(iterator i)
Remove a path from the vector.
Definition pathvector.h:187
OptRect boundsFast() const
void pop_back()
Remove the last path.
Definition pathvector.h:176
Curve const & curveAt(Coord t, Coord *rest=NULL) const
Path const & pathAt(PathVectorTime const &pos) const
Definition pathvector.h:237
Path & at(size_type index)
Definition pathvector.h:161
void clear()
Remove all paths from the vector.
Definition pathvector.h:195
Path const & operator[](size_type index) const
Definition pathvector.h:158
bool empty() const
Check whether the vector contains any paths.
Definition pathvector.h:145
Path const & front() const
Definition pathvector.h:168
iterator insert(iterator pos, Path const &p)
Definition pathvector.h:179
PathVector reversed(bool reverse_paths=true) const
Get a new vector with reversed direction of paths.
std::optional< PathVectorTime > nearestTime(Point const &p, Coord *dist=NULL) const
Path const & at(size_type index) const
Definition pathvector.h:164
void reverse(bool reverse_paths=true)
Reverse the direction of paths in the vector.
Path const & const_reference
Definition pathvector.h:131
PathVector(InputIter first, InputIter last)
Definition pathvector.h:140
Point pointAt(PathVectorTime const &pos) const
Definition pathvector.h:243
std::vector< PathVectorIntersection > intersectSelf(Coord precision=EPSILON) const
Get all intersections of the path-vector with itself.
void resize(size_type n)
Change the number of paths.
Definition pathvector.h:199
iterator begin()
Definition pathvector.h:151
size_type curveCount() const
Get the total number of curves in the vector.
iterator end()
Definition pathvector.h:152
std::vector< PVIntersection > intersect(PathVector const &other, Coord precision=EPSILON) const
Path & pathAt(Coord t, Coord *rest=NULL)
const_iterator begin() const
Definition pathvector.h:153
Sequence::iterator iterator
Definition pathvector.h:126
Sequence of contiguous curves, aka spline.
Definition path.h:353
Curve const & back() const
Access the last curve in the path.
Definition path.h:447
Curve const & front() const
Access the first curve in the path.
Definition path.h:443
Curve const & at(size_type i) const
Access a curve by index.
Definition path.h:438
Two-dimensional point that doubles as a vector.
Definition point.h:66
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
Various utility functions.
Definition affine.h:22
OptInterval bounds_exact(Bezier const &b)
Definition bezier.cpp:310
Intersection< PathVectorTime > PathVectorIntersection
Definition pathvector.h:89
std::ostream & operator<<(std::ostream &os, const Bezier &b)
Definition bezier.h:372
D2< T > operator*=(D2< T > &a, Point const &b)
Definition d2.h:268
PathVectorIntersection PVIntersection
Alias to save typing.
Definition pathvector.h:90
OptInterval bounds_fast(Bezier const &b)
Definition bezier.cpp:305
Noncommutative multiplication helper.
Definition utils.h:60
Generalized time value in the path.
Definition path.h:139
size_type curve_index
Index of the curve in the path.
Definition path.h:143
Coord t
Time value in the curve.
Definition path.h:142
PathInternal::Sequence::size_type size_type
Definition path.h:140
Generalized time value in the path vector.
Definition pathvector.h:58
PathVectorTime(size_type _i, PathTime const &pos)
Definition pathvector.h:64
size_type path_index
Index of the path in the vector.
Definition pathvector.h:59
bool operator<(PathVectorTime const &other) const
Definition pathvector.h:67
PathTime const & asPathTime() const
Definition pathvector.h:79
bool operator==(PathVectorTime const &other) const
Definition pathvector.h:74
PathVectorTime(size_type _i, size_type _c, Coord _t)
Definition pathvector.h:62
PathVectorIntersection IntersectionType
Definition pathvector.h:97
Type requirements for transforms.
Definition transforms.h:50
int index
Affine transformation classes.