Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1/*
4 * Authors:
5 * MenTaLguY <mental@rydia.net>
6 * Marco Cecchetti <mrcekets at gmail.com>
7 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
8 *
9 * Copyright 2007-2014 Authors
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it either under the terms of the GNU Lesser General Public
13 * License version 2.1 as published by the Free Software Foundation
14 * (the "LGPL") or, at your option, under the terms of the Mozilla
15 * Public License Version 1.1 (the "MPL"). If you do not alter this
16 * notice, a recipient may use your version of this file under either
17 * the MPL or the LGPL.
18 *
19 * You should have received a copy of the LGPL along with this library
20 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * You should have received a copy of the MPL along with this library
23 * in the file COPYING-MPL-1.1
24 *
25 * The contents of this file are subject to the Mozilla Public License
26 * Version 1.1 (the "License"); you may not use this file except in
27 * compliance with the License. You may obtain a copy of the License at
28 * http://www.mozilla.org/MPL/
29 *
30 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
31 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
32 * the specific language governing rights and limitations.
33 */
34
35#ifndef LIB2GEOM_SEEN_PATH_H
36#define LIB2GEOM_SEEN_PATH_H
37
38#include <cstddef>
39#include <iterator>
40#include <algorithm>
41#include <iostream>
42#include <memory>
43#include <optional>
44#include <utility>
45#include <vector>
46
47#include <boost/operators.hpp>
48#include <boost/ptr_container/ptr_vector.hpp>
49
50#include <2geom/intersection.h>
51#include <2geom/curve.h>
52#include <2geom/bezier-curve.h>
53#include <2geom/transforms.h>
54
55namespace Geom {
56
57class Path;
58class ConvexHull;
59
60namespace PathInternal {
61
62typedef boost::ptr_vector<Curve> Sequence;
63
68
69template <typename P>
71 : public boost::random_access_iterator_helper
72 < BaseIterator<P>
73 , Curve const
74 , std::ptrdiff_t
75 , Curve const *
76 , Curve const &
77 >
78{
79 protected:
80 BaseIterator(P &p, unsigned i) : path(&p), index(i) {}
81 // default copy, default assign
83
84 public:
85 BaseIterator() : path(NULL), index(0) {}
86
87 bool operator<(BaseIterator const &other) const {
88 return path == other.path && index < other.index;
89 }
90 bool operator==(BaseIterator const &other) const {
91 return path == other.path && index == other.index;
92 }
93 Curve const &operator*() const {
94 return (*path)[index];
95 }
96
98 ++index;
99 return *this;
100 }
102 --index;
103 return *this;
104 }
105 Self &operator+=(std::ptrdiff_t d) {
106 index += d;
107 return *this;
108 }
109 Self &operator-=(std::ptrdiff_t d) {
110 index -= d;
111 return *this;
112 }
113 std::ptrdiff_t operator-(Self const &other) const {
114 assert(path == other.path);
115 return (std::ptrdiff_t)index - (std::ptrdiff_t)other.index;
116 }
117
118 private:
120 unsigned index;
121
122 friend class ::Geom::Path;
123};
124
125}
126
138 : boost::totally_ordered<PathTime>
139{
140 typedef PathInternal::Sequence::size_type size_type;
141
144
145 PathTime() : t(0), curve_index(0) {}
146 PathTime(size_type idx, Coord tval) : t(tval), curve_index(idx) {}
147
148 bool operator<(PathTime const &other) const {
149 if (curve_index < other.curve_index) return true;
150 if (curve_index == other.curve_index) {
151 return t < other.t;
152 }
153 return false;
154 }
155 bool operator==(PathTime const &other) const {
156 return curve_index == other.curve_index && t == other.t;
157 }
159 void normalizeForward(size_type path_size) {
160 if (t >= 1) {
161 curve_index = (curve_index + 1) % path_size;
162 t = 0;
163 }
164 }
166 void normalizeBackward(size_type path_size) {
167 if (t <= 0) {
168 curve_index = (curve_index - 1) % path_size;
169 t = 1;
170 }
171 }
172
173 Coord asFlatTime() const { return curve_index + t; }
174};
175
176inline std::ostream &operator<<(std::ostream &os, PathTime const &pos) {
177 os << pos.curve_index << ": " << format_coord_nice(pos.t);
178 return os;
179}
180
181
188public:
189 typedef PathInternal::Sequence::size_type size_type;
190
193 PathInterval();
194
203 PathInterval(PathTime const &from, PathTime const &to, bool cross_start, size_type path_size);
204
206 PathTime const &initialTime() const { return _from; }
208 PathTime const &finalTime() const { return _to; }
209
210 PathTime const &from() const { return _from; }
211 PathTime const &to() const { return _to; }
212
214 bool isDegenerate() const { return _from == _to; }
216 bool reverse() const { return _reverse; }
218 bool crossesStart() const { return _cross_start; }
219
221 bool contains(PathTime const &pos) const;
222
225 PathTime inside(Coord min_dist = EPSILON) const;
226
228 static PathInterval from_direction(PathTime const &from, PathTime const &to,
229 bool reversed, size_type path_size);
230
233 bool cross_start, size_type path_size) {
234 PathInterval result(from, to, cross_start, path_size);
235 return result;
236 }
237
238 size_type pathSize() const { return _path_size; }
239 size_type curveCount() const;
240
241private:
245};
246
249inline PathInterval forward_interval(PathTime const &from, PathTime const &to,
250 PathInterval::size_type path_size)
251{
252 PathInterval result = PathInterval::from_direction(from, to, false, path_size);
253 return result;
254}
255
258inline PathInterval backward_interval(PathTime const &from, PathTime const &to,
259 PathInterval::size_type path_size)
260{
261 PathInterval result = PathInterval::from_direction(from, to, true, path_size);
262 return result;
263}
264
267inline std::ostream &operator<<(std::ostream &os, PathInterval const &ival) {
268 os << "PathInterval[";
269 if (ival.crossesStart()) {
270 os << ival.from() << " -> 0: 0.0 -> " << ival.to();
271 } else {
272 os << ival.from() << " -> " << ival.to();
273 }
274 os << "]";
275 return os;
276}
277
279
280template <>
287
307
351class Path
352 : boost::equality_comparable< Path >
353{
354public:
359 typedef Sequence::size_type size_type;
360 typedef Sequence::difference_type difference_type;
361
363 public:
365 ClosingSegment(Point const &p1, Point const &p2) : LineSegment(p1, p2) {}
366 Curve *duplicate() const override { return new ClosingSegment(*this); }
367 Curve *reverse() const override { return new ClosingSegment((*this)[1], (*this)[0]); }
368 };
369
370 class StitchSegment : public LineSegment {
371 public:
373 StitchSegment(Point const &p1, Point const &p2) : LineSegment(p1, p2) {}
374 Curve *duplicate() const override { return new StitchSegment(*this); }
375 Curve *reverse() const override { return new StitchSegment((*this)[1], (*this)[0]); }
376 };
377
378 // Path(Path const &other) - use default copy constructor
379
381 explicit Path(Point const &p = Point())
382 : _data(new PathData())
383 , _closing_seg(new ClosingSegment(p, p))
384 , _closed(false)
386 {
387 _data->curves.push_back(_closing_seg);
388 }
389
391 template <typename Iter>
392 Path(Iter first, Iter last, bool closed = false, bool stitch = false)
393 : _data(new PathData())
394 , _closed(closed)
396 {
397 for (Iter i = first; i != last; ++i) {
398 _data->curves.push_back(i->duplicate());
399 }
400 if (!_data->curves.empty()) {
401 _closing_seg = new ClosingSegment(_data->curves.back().finalPoint(),
402 _data->curves.front().initialPoint());
403 } else {
405 }
406 _data->curves.push_back(_closing_seg);
407 }
408
410 explicit Path(Rect const &r);
412 explicit Path(ConvexHull const &);
414 explicit Path(Circle const &c);
416 explicit Path(Ellipse const &e);
417
418 virtual ~Path() {}
419
420 // Path &operator=(Path const &other) - use default assignment operator
421
424 void swap(Path &other) noexcept {
425 using std::swap;
426 swap(other._data, _data);
427 swap(other._closing_seg, _closing_seg);
428 swap(other._closed, _closed);
429 swap(other._exception_on_stitch, _exception_on_stitch);
430 }
433 friend inline void swap(Path &a, Path &b) noexcept { a.swap(b); }
434
436 Curve const &operator[](size_type i) const { return _data->curves[i]; }
438 Curve const &at(size_type i) const { return _data->curves.at(i); }
439
443 Curve const &front() const { return _data->curves.front(); }
445 Curve const &initialCurve() const { return _data->curves.front(); }
447 Curve const &back() const { return back_default(); }
448 Curve const &back_open() const {
449 if (empty()) return _data->curves.back();
450 return _data->curves[_data->curves.size() - 2];
451 }
452 Curve const &back_closed() const {
453 return _closing_seg->isDegenerate()
454 ? _data->curves[_data->curves.size() - 2]
455 : _data->curves[_data->curves.size() - 1];
456 }
457 Curve const &back_default() const {
459 ? back_closed()
460 : back_open();
461 }
462 Curve const &finalCurve() const { return back_default(); }
463
464 const_iterator begin() const { return const_iterator(*this, 0); }
465 const_iterator end() const { return end_default(); }
467 const_iterator end_open() const { return const_iterator(*this, size_open()); }
469 iterator begin() { return iterator(*this, 0); }
470 iterator end() { return end_default(); }
472 iterator end_open() { return iterator(*this, size_open()); }
473 iterator end_closed() { return iterator(*this, size_closed()); }
474
476 size_type size_open() const { return _data->curves.size() - 1; }
477
482 return _closing_seg->isDegenerate() ? _data->curves.size() - 1 : _data->curves.size();
483 }
484
490 size_type size() const { return size_default(); }
491
492 size_type max_size() const { return _data->curves.max_size() - 1; }
493
500 bool empty() const { return (_data->curves.size() == 1); }
501
503 bool closed() const { return _closed; }
504
510 void close(bool closed = true);
511
515 void clear();
516
520 OptRect boundsFast() const;
521
525 OptRect boundsExact() const;
526
528
530 bool operator==(Path const &other) const;
531
533 template <typename T>
534 Path &operator*=(T const &tr) {
535 BOOST_CONCEPT_ASSERT((TransformConcept<T>));
536 _unshare();
537 for (std::size_t i = 0; i < _data->curves.size(); ++i) {
538 _data->curves[i] *= tr;
539 }
540 return *this;
541 }
542
543 template <typename T>
544 friend Path operator*(Path const &path, T const &tr) {
545 BOOST_CONCEPT_ASSERT((TransformConcept<T>));
546 Path result(path);
547 result *= tr;
548 return result;
549 }
550
553 Interval timeRange() const;
554
558 Curve const &curveAt(Coord t, Coord *rest = NULL) const;
559
561 LineSegment const &closingSegment() const { return *_closing_seg; }
562
570 Point pointAt(Coord t) const;
571
573 Coord valueAt(Coord t, Dim2 d) const;
574
576 Curve const &curveAt(PathTime const &pos) const;
578 Point pointAt(PathTime const &pos) const;
580 Coord valueAt(PathTime const &pos, Dim2 d) const;
581
582 Point operator()(Coord t) const { return pointAt(t); }
583
589 PathExtrema extrema(Dim2 d) const;
590
592 std::vector<PathTime> roots(Coord v, Dim2 d) const;
593
595 std::vector<PathIntersection> intersect(Path const &other, Coord precision = EPSILON) const;
596
598 std::vector<PathIntersection> intersectSelf(Coord precision = EPSILON) const;
599
610 int winding(Point const &p) const;
611
612 std::vector<Coord> allNearestTimes(Point const &p, Coord from, Coord to) const;
613 std::vector<Coord> allNearestTimes(Point const &p) const {
614 return allNearestTimes(p, 0, size_default());
615 }
616
617 PathTime nearestTime(Point const &p, Coord *dist = NULL) const;
618 std::vector<Coord> nearestTimePerCurve(Point const &p) const;
619
620 std::vector<Point> nodes() const;
621
622 void appendPortionTo(Path &p, Coord f, Coord t) const;
623
628 void appendPortionTo(Path &p, PathTime const &from, PathTime const &to, bool cross_start = false) const {
629 PathInterval ival(from, to, cross_start, size_closed());
630 appendPortionTo(p, ival, std::nullopt, std::nullopt);
631 }
632
635 void appendPortionTo(Path &p, PathInterval const &ival) const {
636 appendPortionTo(p, ival, std::nullopt, std::nullopt);
637 }
638
642 void appendPortionTo(Path &p, PathInterval const &ival,
643 std::optional<Point> const &p_from, std::optional<Point> const &p_to) const;
644
645 Path portion(Coord f, Coord t) const {
646 Path ret;
647 ret.close(false);
648 appendPortionTo(ret, f, t);
649 return ret;
650 }
651
652 Path portion(Interval const &i) const { return portion(i.min(), i.max()); }
653
660 Path portion(PathTime const &from, PathTime const &to, bool cross_start = false) const {
661 Path ret;
662 ret.close(false);
663 appendPortionTo(ret, from, to, cross_start);
664 return ret;
665 }
666
669 Path portion(PathInterval const &ival) const {
670 Path ret;
671 ret.close(false);
672 appendPortionTo(ret, ival);
673 return ret;
674 }
675
681 Path reversed() const;
682
683 void insert(iterator pos, Curve const &curve);
684
685 template <typename Iter>
686 void insert(iterator pos, Iter first, Iter last) {
687 _unshare();
688 Sequence::iterator seq_pos(seq_iter(pos));
689 Sequence source;
690 for (; first != last; ++first) {
691 source.push_back(first->duplicate());
692 }
693 do_update(seq_pos, seq_pos, source);
694 }
695
696 void erase(iterator pos);
697 void erase(iterator first, iterator last);
698
699 // erase last segment of path
700 void erase_last() { erase(iterator(*this, size() - 1)); }
701
702 void start(Point const &p);
703
705 Point initialPoint() const { return (*_closing_seg)[1]; }
706
709 Point finalPoint() const { return (*_closing_seg)[_closed ? 1 : 0]; }
710
714 for (auto const &curve : *this) {
715 if (!curve.isDegenerate()) {
716 return curve.unitTangentAt(0.0);
717 }
718 }
719 return Point();
720 }
721
725 for (auto it = end(); it != begin();) {
726 --it;
727 if (!it->isDegenerate()) {
728 return it->unitTangentAt(1.0);
729 }
730 }
731 return Point();
732 }
733
734 void setInitial(Point const &p) {
735 _unshare();
736 _closed = false;
737 _data->curves.front().setInitial(p);
739 }
740 void setFinal(Point const &p) {
741 _unshare();
742 _closed = false;
743 _data->curves[size_open() ? size_open() - 1 : 0].setFinal(p);
745 }
746
751 _unshare();
752 stitchTo(curve->initialPoint());
754 }
755
756 void append(Curve const &curve) {
757 _unshare();
758 stitchTo(curve.initialPoint());
759 do_append(curve.duplicate());
760 }
761 void append(D2<SBasis> const &curve) {
762 _unshare();
763 stitchTo(Point(curve[X][0][0], curve[Y][0][0]));
765 }
766 void append(Path const &other) {
767 replace(end_open(), other.begin(), other.end());
768 }
769
770 void replace(iterator replaced, Curve const &curve);
771 void replace(iterator first, iterator last, Curve const &curve);
772 void replace(iterator replaced, Path const &path);
773 void replace(iterator first, iterator last, Path const &path);
774
775 template <typename Iter>
776 void replace(iterator replaced, Iter first, Iter last) {
777 replace(replaced, replaced + 1, first, last);
778 }
779
780 template <typename Iter>
781 void replace(iterator first_replaced, iterator last_replaced, Iter first, Iter last) {
782 _unshare();
783 Sequence::iterator seq_first_replaced(seq_iter(first_replaced));
784 Sequence::iterator seq_last_replaced(seq_iter(last_replaced));
785 Sequence source;
786 for (; first != last; ++first) {
787 source.push_back(first->duplicate());
788 }
789 do_update(seq_first_replaced, seq_last_replaced, source);
790 }
791
803 template <typename CurveType, typename... Args>
804 void appendNew(Args&&... args) {
805 _unshare();
806 do_append(new CurveType(finalPoint(), std::forward<Args>(args)...));
807 }
808
811 void snapEnds(Coord precision = EPSILON);
812
814 void stitchTo(Point const &p);
815
819
822 void checkContinuity() const;
823
827 void setStitching(bool x) {
829 }
830
831private:
832 static Sequence::iterator seq_iter(iterator const &iter) {
833 return iter.path->_data->curves.begin() + iter.index;
834 }
835 static Sequence::const_iterator seq_iter(const_iterator const &iter) {
836 return iter.path->_data->curves.begin() + iter.index;
837 }
838
839 // whether the closing segment is part of the path
841 return _closed && !_closing_seg->isDegenerate();
842 }
843 void _unshare() {
844 // Called before every mutation.
845 // Ensure we have our own copy of curve data and reset cached values
846 if (_data.use_count() != 1) {
847 _data.reset(new PathData(*_data));
848 _closing_seg = static_cast<ClosingSegment*>(&_data->curves.back());
849 }
850 _data->fast_bounds = OptRect();
851 }
852 PathTime _factorTime(Coord t) const;
853
854 void stitch(Sequence::iterator first_replaced, Sequence::iterator last_replaced, Sequence &sequence);
855 void do_update(Sequence::iterator first, Sequence::iterator last, Sequence &source);
856
857 // n.b. takes ownership of curve object
858 void do_append(Curve *curve);
859
860 std::shared_ptr<PathData> _data;
864}; // end class Path
865
867
868inline Coord nearest_time(Point const &p, Path const &c) {
869 PathTime pt = c.nearestTime(p);
870 return pt.curve_index + pt.t;
871}
872
873bool are_near(Path const &a, Path const &b, Coord precision = EPSILON);
874
899PathIntersection parting_point(Path const &first, Path const &second, Coord precision = EPSILON);
900
901std::ostream &operator<<(std::ostream &out, Path const &path);
902
903} // end namespace Geom
904
905
906#endif // LIB2GEOM_SEEN_PATH_H
907
908/*
909 Local Variables:
910 mode:c++
911 c-file-style:"stroustrup"
912 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
913 indent-tabs-mode:nil
914 fill-column:99
915 End:
916*/
917// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Abstract curve type.
Bezier curve.
bool isDegenerate() const override
Check whether the curve has exactly zero length.
void setInitial(Point const &v) override
Change the starting point of the curve.
void setFinal(Point const &v) override
Change the ending point of the curve.
Set of all points at a fixed distance from the center.
Definition circle.h:55
Convex hull based on the Andrew's monotone chain algorithm.
Abstract continuous curve on a plane defined on [0,1].
Definition curve.h:78
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
constexpr C min() const
constexpr C max() const
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
bool operator<(BaseIterator const &other) const
Definition path.h:87
std::ptrdiff_t operator-(Self const &other) const
Definition path.h:113
BaseIterator< P > Self
Definition path.h:82
BaseIterator(P &p, unsigned i)
Definition path.h:80
Self & operator+=(std::ptrdiff_t d)
Definition path.h:105
Curve const & operator*() const
Definition path.h:93
bool operator==(BaseIterator const &other) const
Definition path.h:90
Self & operator-=(std::ptrdiff_t d)
Definition path.h:109
Contiguous subset of the path's parameter domain.
Definition path.h:187
PathTime const & finalTime() const
Get the time value of the final point.
Definition path.h:208
PathInternal::Sequence::size_type size_type
Definition path.h:189
PathTime _to
Definition path.h:242
static PathInterval from_direction(PathTime const &from, PathTime const &to, bool reversed, size_type path_size)
Select one of two intervals with given endpoints by parameter direction.
Definition path.cpp:223
bool reverse() const
True if the interval goes in the direction of decreasing time values.
Definition path.h:216
size_type _path_size
Definition path.h:243
PathTime _from
Definition path.h:242
PathTime const & initialTime() const
Get the time value of the initial point.
Definition path.h:206
bool _cross_start
Definition path.h:244
PathTime inside(Coord min_dist=EPSILON) const
Get a time at least min_dist away in parameter space from the ends.
Definition path.cpp:136
size_type curveCount() const
Definition path.cpp:118
bool isDegenerate() const
Check whether the interval has only one point.
Definition path.h:214
PathTime const & to() const
Definition path.h:211
static PathInterval from_start_crossing(PathTime const &from, PathTime const &to, bool cross_start, size_type path_size)
Select one of two intervals with given endpoints by whether it includes the initial point.
Definition path.h:232
PathInterval backward_interval(PathTime const &from, PathTime const &to, PathInterval::size_type path_size)
Create an interval in the direction of decreasing time value.
Definition path.h:258
bool contains(PathTime const &pos) const
Test a path time for inclusion.
Definition path.cpp:102
PathInterval forward_interval(PathTime const &from, PathTime const &to, PathInterval::size_type path_size)
Create an interval in the direction of increasing time value.
Definition path.h:249
bool crossesStart() const
True if the interior of the interval contains the initial point of the path.
Definition path.h:218
PathTime const & from() const
Definition path.h:210
size_type pathSize() const
Definition path.h:238
PathInterval()
Default interval.
Definition path.cpp:53
std::ostream & operator<<(std::ostream &os, PathInterval const &ival)
Output an interval in the path's domain.
Definition path.h:267
Sequence of subpaths.
Definition pathvector.h:122
Curve * reverse() const override
Create a reversed version of this curve.
Definition path.h:367
Curve * duplicate() const override
Create an exact copy of this curve.
Definition path.h:366
ClosingSegment(Point const &p1, Point const &p2)
Definition path.h:365
Curve * duplicate() const override
Create an exact copy of this curve.
Definition path.h:374
StitchSegment(Point const &p1, Point const &p2)
Definition path.h:373
Curve * reverse() const override
Create a reversed version of this curve.
Definition path.h:375
Sequence of contiguous curves, aka spline.
Definition path.h:353
bool closed() const
Check whether the path is closed.
Definition path.h:503
Curve const & finalCurve() const
Definition path.h:462
Point finalPoint() const
Get the last point in the path.
Definition path.h:709
PathExtrema extrema(Dim2 d) const
Find the extrema of the specified coordinate.
void setStitching(bool x)
Enable or disable the throwing of exceptions when stitching discontinuities.
Definition path.h:827
void close(bool closed=true)
Set whether the path is closed.
Definition path.cpp:322
Interval timeRange() const
Get the allowed range of time values.
Definition path.cpp:434
std::shared_ptr< PathData > _data
Definition path.h:860
friend void swap(Path &a, Path &b) noexcept
Swap contents of two paths.
Definition path.h:433
bool empty() const
Check whether path is empty.
Definition path.h:500
OptRect boundsExact() const
Get a tight-fitting bounding box.
Definition path.cpp:372
Path portion(PathTime const &from, PathTime const &to, bool cross_start=false) const
Get a subset of the current path with full precision.
Definition path.h:660
Piecewise< D2< SBasis > > toPwSb() const
Definition path.cpp:388
Path & operator*=(T const &tr)
Apply a transform to each curve.
Definition path.h:534
Curve const & back_closed() const
Definition path.h:452
friend Path operator*(Path const &path, T const &tr)
Definition path.h:544
bool _exception_on_stitch
Definition path.h:863
void insert(iterator pos, Iter first, Iter last)
Definition path.h:686
Path(Point const &p=Point())
Construct an empty path starting at the specified point.
Definition path.h:381
std::vector< PathTime > roots(Coord v, Dim2 d) const
Compute intersections with axis-aligned line.
Definition path.cpp:472
const_iterator end() const
Definition path.h:465
virtual ~Path()
Definition path.h:418
Curve const & back() const
Access the last curve in the path.
Definition path.h:447
PathTime nearestTime(Point const &p, Coord *dist=NULL) const
Definition path.cpp:733
std::vector< PathIntersection > intersectSelf(Coord precision=EPSILON) const
Compute intersections of the path with itself.
Point pointAt(Coord t) const
Get the point at the specified time value.
Definition path.cpp:449
OptRect boundsFast() const
Get the approximate bounding box.
Definition path.cpp:348
iterator begin()
Definition path.h:469
size_type size_open() const
Size without the closing segment, even if the path is closed.
Definition path.h:476
void replace(iterator replaced, Iter first, Iter last)
Definition path.h:776
void clear()
Remove all curves from the path.
Definition path.cpp:337
Path withoutDegenerateCurves() const
Return a copy of the path without degenerate curves, except possibly for a degenerate closing segment...
Definition path.cpp:979
void appendPortionTo(Path &p, PathTime const &from, PathTime const &to, bool cross_start=false) const
Append a subset of this path to another path.
Definition path.h:628
void appendPortionTo(Path &p, PathInterval const &ival) const
Append a subset of this path to another path.
Definition path.h:635
Path(Iter first, Iter last, bool closed=false, bool stitch=false)
Construct a path containing a range of curves.
Definition path.h:392
const_iterator end_open() const
Definition path.h:467
Curve const & initialCurve() const
Alias for front().
Definition path.h:445
std::vector< Coord > allNearestTimes(Point const &p) const
Definition path.h:613
size_type size_default() const
Natural size of the path.
Definition path.h:486
void _unshare()
Definition path.h:843
ClosingSegment * _closing_seg
Definition path.h:861
Path portion(Coord f, Coord t) const
Definition path.h:645
Point finalUnitTangent() const
Get the unit tangent vector at the end of the path, or the zero vector if undefined.
Definition path.h:724
Curve const & back_open() const
Definition path.h:448
std::vector< PathIntersection > intersect(Path const &other, Coord precision=EPSILON) const
Compute intersections with another path.
Definition path.cpp:575
iterator end_default()
Definition path.h:471
static Sequence::const_iterator seq_iter(const_iterator const &iter)
Definition path.h:835
void replace(iterator first_replaced, iterator last_replaced, Iter first, Iter last)
Definition path.h:781
int winding(Point const &p) const
Determine the winding number at the specified point.
Definition path.cpp:595
PathInternal::Sequence Sequence
Definition path.h:356
void appendPortionTo(Path &p, Coord f, Coord t) const
Definition path.cpp:777
Path portion(PathInterval const &ival) const
Get a subset of the current path with full precision.
Definition path.h:669
Sequence::size_type size_type
Definition path.h:359
bool _includesClosingSegment() const
Definition path.h:840
Path portion(Interval const &i) const
Definition path.h:652
Curve const & back_default() const
Definition path.h:457
void append(Curve *curve)
Add a new curve to the end of the path.
Definition path.h:750
static Sequence::iterator seq_iter(iterator const &iter)
Definition path.h:832
Point initialPoint() const
Get the first point in the path.
Definition path.h:705
Curve const & front() const
Access the first curve in the path.
Definition path.h:443
void do_append(Curve *curve)
Definition path.cpp:1068
Path reversed() const
Obtain a reversed version of the current path.
Definition path.cpp:866
bool _closed
Definition path.h:862
PathInternal::PathData PathData
Definition path.h:355
void setFinal(Point const &p)
Definition path.h:740
void erase_last()
Definition path.h:700
Point initialUnitTangent() const
Get the unit tangent vector at the start of the path, or the zero vector if undefined.
Definition path.h:713
PathInternal::BaseIterator< Path const > const_iterator
Definition path.h:358
void snapEnds(Coord precision=EPSILON)
Reduce the closing segment to a point if it's shorter than precision.
Definition path.cpp:969
size_type size_closed() const
Size with the closing segment, if it makes a difference.
Definition path.h:481
size_type size() const
Natural size of the path.
Definition path.h:490
Coord valueAt(Coord t, Dim2 d) const
Get one coordinate (X or Y) at the specified time value.
Definition path.cpp:454
size_type max_size() const
Definition path.h:492
const_iterator begin() const
Definition path.h:464
void replace(iterator replaced, Curve const &curve)
Definition path.cpp:943
void append(Curve const &curve)
Definition path.h:756
Curve const & at(size_type i) const
Access a curve by index.
Definition path.h:438
void checkContinuity() const
Verify the continuity invariant.
Definition path.cpp:1090
void do_update(Sequence::iterator first, Sequence::iterator last, Sequence &source)
Definition path.cpp:997
void append(D2< SBasis > const &curve)
Definition path.h:761
void append(Path const &other)
Definition path.h:766
PathInternal::BaseIterator< Path > iterator
Definition path.h:357
void erase(iterator pos)
Definition path.cpp:913
LineSegment const & closingSegment() const
Get the closing segment of the path.
Definition path.h:561
std::vector< Coord > allNearestTimes(Point const &p, Coord from, Coord to) const
Definition path.cpp:638
void setInitial(Point const &p)
Definition path.h:734
Curve const & operator[](size_type i) const
Access a curve by index.
Definition path.h:436
PathTime _factorTime(Coord t) const
Definition path.cpp:1105
Curve const & curveAt(Coord t, Coord *rest=NULL) const
Get the curve at the specified time value.
Definition path.cpp:440
void stitch(Sequence::iterator first_replaced, Sequence::iterator last_replaced, Sequence &sequence)
void appendNew(Args &&... args)
Append a new curve to the path.
Definition path.h:804
const_iterator end_closed() const
Definition path.h:468
std::vector< Coord > nearestTimePerCurve(Point const &p) const
Definition path.cpp:723
iterator end()
Definition path.h:470
void swap(Path &other) noexcept
Swap contents with another path.
Definition path.h:424
iterator end_open()
Definition path.h:472
std::vector< Point > nodes() const
Definition path.cpp:767
const_iterator end_default() const
Definition path.h:466
Sequence::difference_type difference_type
Definition path.h:360
Point operator()(Coord t) const
Definition path.h:582
void stitchTo(Point const &p)
Append a stitching segment ending at the specified point.
Definition path.cpp:932
iterator end_closed()
Definition path.h:473
void insert(iterator pos, Curve const &curve)
Definition path.cpp:904
Function defined as discrete pieces.
Definition piecewise.h:71
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Symmetric power basis curve.
Path and its polyline approximation.
Definition Path.h:93
Css & result
double c[8][4]
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
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
Intersection utilities.
Geom::Point start
vector< vector< Point > > paths
Definition metro.cpp:36
boost::ptr_vector< Curve > Sequence
Definition path.h:62
Various utility functions.
Definition affine.h:22
Piecewise< D2< SBasis > > paths_to_pw(PathVector const &paths)
Definition path.cpp:1123
std::ostream & operator<<(std::ostream &os, const Bezier &b)
Definition bezier.h:372
PathIntersection parting_point(Path const &first, Path const &second, Coord precision=EPSILON)
Find the first point where two paths diverge away from one another.
Coord nearest_time(Point const &p, Curve const &c)
Definition curve.h:354
Intersection< PathTime > PathIntersection
Definition path.h:278
std::string format_coord_nice(Coord x)
Definition coord.cpp:89
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Stores information about the extremum points on a path, with respect to one of the coordinate axes.
Definition path.h:292
PathTime max_time
Definition path.h:305
float glance_direction_at_min
Directions in which the OTHER coordinates change at the extremum points.
Definition path.h:302
Point min_point
Points with the minimum and maximum value of a coordinate.
Definition path.h:294
float glance_direction_at_max
Definition path.h:302
Point max_point
Definition path.h:294
PathTime min_time
Path times corresponding to minimum and maximum points.
Definition path.h:305
Generalized time value in the path.
Definition path.h:139
Coord asFlatTime() const
Definition path.h:173
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
void normalizeBackward(size_type path_size)
Convert times at or before 0 to 1 on the previous curve.
Definition path.h:166
PathTime(size_type idx, Coord tval)
Definition path.h:146
void normalizeForward(size_type path_size)
Convert times at or beyond 1 to 0 on the next curve.
Definition path.h:159
PathInternal::Sequence::size_type size_type
Definition path.h:140
bool operator==(PathTime const &other) const
Definition path.h:155
bool operator<(PathTime const &other) const
Definition path.h:148
PathIntersection IntersectionType
Definition path.h:285
PathInterval IntervalType
Definition path.h:283
Type requirements for transforms.
Definition transforms.h:50
Definition curve.h:24
Affine transformation classes.