diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2015-04-30 09:17:07 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2015-04-30 09:17:07 +0000 |
| commit | 6a9762c7603a32c7ec5cc0aaed8048d84daee6e8 (patch) | |
| tree | 8cd98ce46dad85fc325bdd01ba60458de0801701 /src/2geom | |
| parent | Fix calls to Geom::cross() - sign change. (diff) | |
| download | inkscape-6a9762c7603a32c7ec5cc0aaed8048d84daee6e8.tar.gz inkscape-6a9762c7603a32c7ec5cc0aaed8048d84daee6e8.zip | |
Update 2Geom to r2347
(bzr r14059.2.3)
Diffstat (limited to 'src/2geom')
| -rw-r--r-- | src/2geom/Makefile_insert | 1 | ||||
| -rw-r--r-- | src/2geom/ellipse.cpp | 50 | ||||
| -rw-r--r-- | src/2geom/forward.h | 4 | ||||
| -rw-r--r-- | src/2geom/intersection-graph.cpp | 4 | ||||
| -rw-r--r-- | src/2geom/intersection-graph.h | 2 | ||||
| -rw-r--r-- | src/2geom/path.cpp | 49 | ||||
| -rw-r--r-- | src/2geom/path.h | 98 | ||||
| -rw-r--r-- | src/2geom/pathvector.cpp | 30 | ||||
| -rw-r--r-- | src/2geom/pathvector.h | 53 | ||||
| -rw-r--r-- | src/2geom/point-ops.h | 25 |
10 files changed, 142 insertions, 174 deletions
diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index 86e64333d..aeb0b20a1 100644 --- a/src/2geom/Makefile_insert +++ b/src/2geom/Makefile_insert @@ -84,7 +84,6 @@ 2geom/piecewise.h \ 2geom/point.cpp \ 2geom/point.h \ - 2geom/point-ops.h \ 2geom/poly.cpp \ 2geom/poly.h \ 2geom/quadtree.cpp \ diff --git a/src/2geom/ellipse.cpp b/src/2geom/ellipse.cpp index 4e26707ef..9e927c9e8 100644 --- a/src/2geom/ellipse.cpp +++ b/src/2geom/ellipse.cpp @@ -170,33 +170,31 @@ EllipticalArc * Ellipse::arc(Point const &ip, Point const &inner, Point const &fp, bool _svg_compliant) { - Point sp_cp = ip - center(); - Point ep_cp = fp - center(); - Point ip_cp = inner - center(); - - double angle1 = angle_between(sp_cp, ep_cp); - double angle2 = angle_between(sp_cp, ip_cp); - double angle3 = angle_between(ip_cp, ep_cp); - - bool large_arc_flag = true; - bool sweep_flag = true; + // This is resistant to degenerate ellipses: + // both flags evaluate to false in that case. + + bool large_arc_flag = false; + bool sweep_flag = false; + + // Determination of large arc flag: + // The arc is larger than half of the ellipse if the inner point + // is on the same side of the line going from the initial + // to the final point as the center of the ellipse + Line chord(ip, fp); + Point versor = fp - ip; + double sdist_c = cross(versor, _center - ip); + double sdist_inner = cross(versor, inner - ip); + + // if we have exactly half of an arc, do not set the large flag. + if (sdist_c != 0 && sgn(sdist_c) == sgn(sdist_inner)) { + large_arc_flag = true; + } - if (angle1 > 0) { - if (angle2 > 0 && angle3 > 0) { - large_arc_flag = false; - sweep_flag = true; - } else { - large_arc_flag = true; - sweep_flag = false; - } - } else { - if (angle2 < 0 && angle3 < 0) { - large_arc_flag = false; - sweep_flag = false; - } else { - large_arc_flag = true; - sweep_flag = true; - } + // Determination of sweep flag: + // If the inner point is on the left side of the ip-fp line, + // we go in clockwise direction. + if (sdist_inner < 0) { + sweep_flag = true; } EllipticalArc *ret_arc; diff --git a/src/2geom/forward.h b/src/2geom/forward.h index f3ab657e8..a6e420122 100644 --- a/src/2geom/forward.h +++ b/src/2geom/forward.h @@ -78,9 +78,9 @@ class SVGEllipticalArc; // paths and path sequences class Path; class PathVector; -struct PathPosition; +struct PathTime; class PathInterval; -struct PathVectorPosition; +struct PathVectorTime; // errors class Exception; diff --git a/src/2geom/intersection-graph.cpp b/src/2geom/intersection-graph.cpp index abe462e3f..b9e2feeed 100644 --- a/src/2geom/intersection-graph.cpp +++ b/src/2geom/intersection-graph.cpp @@ -119,7 +119,7 @@ PathIntersectionGraph::PathIntersectionGraph(PathVector const &a, PathVector con std::size_t pi = i->pos.path_index; PathInterval ival = forward_interval(i->pos, n->pos, pv[pi].size()); - PathPosition mid = ival.inside(precision); + PathTime mid = ival.inside(precision); // TODO check for degenerate cases // requires changes in the winding routine @@ -216,7 +216,7 @@ PathVector PathIntersectionGraph::_getResult(bool enter_a, bool enter_b) // append portion of path PathInterval ival = PathInterval::from_direction( - prev->pos.asPathPosition(), i->pos.asPathPosition(), + prev->pos.asPathTime(), i->pos.asPathTime(), reverse, (*cur)[pi].size()); (*cur)[pi].appendPortionTo(result.back(), ival, prev->p, i->p); diff --git a/src/2geom/intersection-graph.h b/src/2geom/intersection-graph.h index 2fe858c5d..dd70d3d5b 100644 --- a/src/2geom/intersection-graph.h +++ b/src/2geom/intersection-graph.h @@ -51,7 +51,7 @@ enum InOutFlag { struct IntersectionVertex { boost::intrusive::list_member_hook<> _hook; - PathVectorPosition pos; + PathVectorTime pos; Point p; // guarantees that endpoints are exact IntersectionVertex *neighbor; bool entry; // going in +t direction enters the other path diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp index 8eb5c7fcb..71b7b25bb 100644 --- a/src/2geom/path.cpp +++ b/src/2geom/path.cpp @@ -53,7 +53,7 @@ PathInterval::PathInterval() , _reverse(false) {} -PathInterval::PathInterval(Position const &from, Position const &to, bool cross_start, size_type path_size) +PathInterval::PathInterval(PathTime const &from, PathTime const &to, bool cross_start, size_type path_size) : _from(from) , _to(to) , _path_size(path_size) @@ -78,7 +78,7 @@ PathInterval::PathInterval(Position const &from, Position const &to, bool cross_ } } -bool PathInterval::contains(Position const &pos) const { +bool PathInterval::contains(PathTime const &pos) const { if (_cross_start) { if (_reverse) { return pos >= _to || _from >= pos; @@ -94,14 +94,14 @@ bool PathInterval::contains(Position const &pos) const { } } -PathPosition PathInterval::inside(Coord min_dist) const +PathTime PathInterval::inside(Coord min_dist) const { // If there is some node further than min_dist (in time coord) from the ends, // return that node. Otherwise, return the middle. - PathPosition result(0, 0.0); + PathTime result(0, 0.0); if (!_cross_start && _from.curve_index == _to.curve_index) { - PathPosition result(_from.curve_index, lerp(0.5, _from.t, _to.t)); + PathTime result(_from.curve_index, lerp(0.5, _from.t, _to.t)); return result; } // If _cross_start, then we can be sure that at least one node is in the domain. @@ -181,7 +181,7 @@ PathPosition PathInterval::inside(Coord min_dist) const return result; } -PathInterval PathInterval::from_direction(Position const &from, Position const &to, bool reversed, size_type path_size) +PathInterval PathInterval::from_direction(PathTime const &from, PathTime const &to, bool reversed, size_type path_size) { PathInterval result; result._from = from; @@ -351,7 +351,7 @@ Interval Path::timeRange() const Curve const &Path::curveAt(Coord t, Coord *rest) const { - Position pos = _getPosition(t); + PathTime pos = _factorTime(t); if (rest) { *rest = pos.t; } @@ -360,34 +360,34 @@ Curve const &Path::curveAt(Coord t, Coord *rest) const Point Path::pointAt(Coord t) const { - return pointAt(_getPosition(t)); + return pointAt(_factorTime(t)); } Coord Path::valueAt(Coord t, Dim2 d) const { - return valueAt(_getPosition(t), d); + return valueAt(_factorTime(t), d); } -Curve const &Path::curveAt(Position const &pos) const +Curve const &Path::curveAt(PathTime const &pos) const { return at(pos.curve_index); } -Point Path::pointAt(Position const &pos) const +Point Path::pointAt(PathTime const &pos) const { return at(pos.curve_index).pointAt(pos.t); } -Coord Path::valueAt(Position const &pos, Dim2 d) const +Coord Path::valueAt(PathTime const &pos, Dim2 d) const { return at(pos.curve_index).valueAt(pos.t, d); } -std::vector<PathPosition> Path::roots(Coord v, Dim2 d) const +std::vector<PathTime> Path::roots(Coord v, Dim2 d) const { - std::vector<PathPosition> res; + std::vector<PathTime> res; for (unsigned i = 0; i <= size(); i++) { std::vector<Coord> temp = (*this)[i].roots(v, d); for (unsigned j = 0; j < temp.size(); j++) - res.push_back(PathPosition(i, temp[j])); + res.push_back(PathTime(i, temp[j])); } return res; } @@ -402,7 +402,7 @@ std::vector<PathIntersection> Path::intersect(Path const &other, Coord precision for (size_type j = 0; j < other.size(); ++j) { std::vector<CurveIntersection> cx = (*this)[i].intersect(other[j], precision); for (std::size_t ci = 0; ci < cx.size(); ++ci) { - PathPosition a(i, cx[ci].first), b(j, cx[ci].second); + PathTime a(i, cx[ci].first), b(j, cx[ci].second); PathIntersection px(a, b, cx[ci].point()); result.push_back(px); } @@ -550,16 +550,10 @@ std::vector<Coord> Path::nearestTimePerCurve(Point const &p) const return np; } -Coord Path::nearestTime(Point const &p, Coord *dist) const -{ - Position pos = nearestPosition(p, dist); - return pos.curve_index + pos.t; -} - -PathPosition Path::nearestPosition(Point const &p, Coord *dist) const +PathTime Path::nearestTime(Point const &p, Coord *dist) const { Coord mindist = std::numeric_limits<Coord>::max(); - Position ret; + PathTime ret; if (_curves->size() == 1) { // naked moveto @@ -639,7 +633,7 @@ void Path::appendPortionTo(Path &target, PathInterval const &ival, return; } - Position const &from = ival.from(), &to = ival.to(); + PathTime const &from = ival.from(), &to = ival.to(); bool reverse = ival.reverse(); int di = reverse ? -1 : 1; @@ -872,14 +866,15 @@ void Path::checkContinuity() const } } -PathPosition Path::_getPosition(Coord t) const +// breaks time value into integral and fractional part +PathTime Path::_factorTime(Coord t) const { size_type sz = size_default(); if (t < 0 || t > sz) { THROW_RANGEERROR("parameter t out of bounds"); } - Position ret; + PathTime ret; Coord k; ret.t = modf(t, &k); ret.curve_index = k; diff --git a/src/2geom/path.h b/src/2geom/path.h index 8d585cd57..6a6fa05ee 100644 --- a/src/2geom/path.h +++ b/src/2geom/path.h @@ -109,7 +109,7 @@ class BaseIterator } -/** @brief Position (generalized time value) in the path. +/** @brief Generalized time value in the path. * * This class exists because when mapping the range of multiple curves onto the same interval * as the curve index, we lose some precision. For instance, a path with 16 curves will @@ -119,44 +119,46 @@ class BaseIterator * call the method again to obtain a high precision result. * * @ingroup Paths */ -struct PathPosition - : boost::totally_ordered<PathPosition> +struct PathTime + : boost::totally_ordered<PathTime> { typedef PathInternal::Sequence::size_type size_type; Coord t; ///< Time value in the curve size_type curve_index; ///< Index of the curve in the path - PathPosition() : t(0), curve_index(0) {} - PathPosition(size_type idx, Coord tval) : t(tval), curve_index(idx) {} + PathTime() : t(0), curve_index(0) {} + PathTime(size_type idx, Coord tval) : t(tval), curve_index(idx) {} - bool operator<(PathPosition const &other) const { + bool operator<(PathTime const &other) const { if (curve_index < other.curve_index) return true; if (curve_index == other.curve_index) { return t < other.t; } return false; } - bool operator==(PathPosition const &other) const { + bool operator==(PathTime const &other) const { return curve_index == other.curve_index && t == other.t; } - /// Convert positions at or beyond 1 to 0 on the next curve. + /// Convert times at or beyond 1 to 0 on the next curve. void normalizeForward(size_type path_size) { if (t >= 1) { curve_index = (curve_index + 1) % path_size; t = 0; } } - /// Convert positions at or before 0 to 1 on the previous curve. + /// Convert times at or before 0 to 1 on the previous curve. void normalizeBackward(size_type path_size) { if (t <= 0) { curve_index = (curve_index - 1) % path_size; t = 1; } } + + Coord asFlatTime() const { return curve_index + t; } }; -inline std::ostream &operator<<(std::ostream &os, PathPosition const &pos) { +inline std::ostream &operator<<(std::ostream &os, PathTime const &pos) { os << pos.curve_index << ": " << pos.t; return os; } @@ -169,7 +171,6 @@ inline std::ostream &operator<<(std::ostream &os, PathPosition const &pos) { * @ingroup Paths */ class PathInterval { public: - typedef PathPosition Position; typedef PathInternal::Sequence::size_type size_type; /** @brief Default interval. @@ -177,22 +178,22 @@ public: PathInterval(); /** @brief Construct an interval in the path's parameter domain. - * @param from Initial position - * @param to Final position + * @param from Initial time + * @param to Final time * @param cross_start If true, the interval will proceed from the initial to final - * position through the initial point of the path, wrapping around the closing segment; + * time through the initial point of the path, wrapping around the closing segment; * otherwise it will not wrap around the closing segment. * @param path_size Size of the path to which this interval applies, required * to clean up degenerate cases */ - PathInterval(Position const &from, Position const &to, bool cross_start, size_type path_size); + PathInterval(PathTime const &from, PathTime const &to, bool cross_start, size_type path_size); - /// Get the position of the initial point. - Position const &initialPosition() const { return _from; } - /// Get the position of the final point. - Position const &finalPosition() const { return _to; } + /// Get the time value of the initial point. + PathTime const &initialTime() const { return _from; } + /// Get the time value of the final point. + PathTime const &finalTime() const { return _to; } - Position const &from() const { return _from; } - Position const &to() const { return _to; } + PathTime const &from() const { return _from; } + PathTime const &to() const { return _to; } /// Check whether the interval has only one point. bool isDegenerate() const { return _from == _to; } @@ -201,19 +202,19 @@ public: /// True if the interior of the interval contains the initial point of the path. bool crossesStart() const { return _cross_start; } - /// Test a path position for inclusion. - bool contains(Position const &pos) const; + /// Test a path time for inclusion. + bool contains(PathTime const &pos) const; - /// Get a position at least @a min_dist away in parameter space from the ends. - /// If no such position exists, the middle point between these positions is returned. - Position inside(Coord min_dist = EPSILON) const; + /// Get a time at least @a min_dist away in parameter space from the ends. + /// If no such time exists, the middle point is returned. + PathTime inside(Coord min_dist = EPSILON) const; /// Select one of two intervals with given endpoints by parameter direction. - static PathInterval from_direction(Position const &from, Position const &to, + 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 whether it includes the initial point. - static PathInterval from_start_crossing(Position const &from, Position const &to, + static PathInterval from_start_crossing(PathTime const &from, PathTime const &to, bool cross_start, size_type path_size) { PathInterval result(from, to, cross_start, path_size); return result; @@ -222,14 +223,14 @@ public: size_type pathSize() const { return _path_size; } private: - Position _from, _to; + PathTime _from, _to; size_type _path_size; bool _cross_start, _reverse; }; /// Create an interval in the direction of increasing time value. /// @relates PathInterval -inline PathInterval forward_interval(PathPosition const &from, PathPosition const &to, +inline PathInterval forward_interval(PathTime const &from, PathTime const &to, PathInterval::size_type path_size) { PathInterval result = PathInterval::from_direction(from, to, false, path_size); @@ -238,7 +239,7 @@ inline PathInterval forward_interval(PathPosition const &from, PathPosition cons /// Create an interval in the direction of decreasing time value. /// @relates PathInterval -inline PathInterval backward_interval(PathPosition const &from, PathPosition const &to, +inline PathInterval backward_interval(PathTime const &from, PathTime const &to, PathInterval::size_type path_size) { PathInterval result = PathInterval::from_direction(from, to, true, path_size); @@ -258,11 +259,11 @@ inline std::ostream &operator<<(std::ostream &os, PathInterval const &ival) { return os; } -typedef Intersection<PathPosition> PathIntersection; +typedef Intersection<PathTime> PathIntersection; template <> struct ShapeTraits<Path> { - typedef PathPosition TimeType; + typedef PathTime TimeType; typedef PathInterval IntervalType; typedef Path AffineClosureType; typedef PathIntersection IntersectionType; @@ -313,7 +314,6 @@ class Path > > { public: - typedef PathPosition Position; typedef PathInternal::Sequence Sequence; typedef PathInternal::BaseIterator<Path> iterator; typedef PathInternal::BaseIterator<Path const> const_iterator; @@ -490,7 +490,7 @@ public: /** @brief Get the point at the specified time value. * Note that this method has reduced precision with respect to calling pointAt() * directly on the curve. If you want high precision results, use the version - * that takes a Position parameter. + * that takes a PathTime parameter. * * Allowed time values range from zero to the number of curves; you can retrieve * the allowed range of values with timeRange(). */ @@ -499,17 +499,17 @@ public: /// Get one coordinate (X or Y) at the specified time value. Coord valueAt(Coord t, Dim2 d) const; - /// Get the curve at the specified position. - Curve const &curveAt(Position const &pos) const; - /// Get the point at the specified position. - Point pointAt(Position const &pos) const; - /// Get one coordinate at the specified position. - Coord valueAt(Position const &pos, Dim2 d) const; + /// Get the curve at the specified path time. + Curve const &curveAt(PathTime const &pos) const; + /// Get the point at the specified path time. + Point pointAt(PathTime const &pos) const; + /// Get one coordinate at the specified path time. + Coord valueAt(PathTime const &pos, Dim2 d) const; Point operator()(Coord t) const { return pointAt(t); } /// Compute intersections with axis-aligned line. - std::vector<Position> roots(Coord v, Dim2 d) const; + std::vector<PathTime> roots(Coord v, Dim2 d) const; /// Compute intersections with another path. std::vector<PathIntersection> intersect(Path const &other, Coord precision = EPSILON) const; @@ -531,9 +531,8 @@ public: return allNearestTimes(p, 0, size_default()); } - Coord nearestTime(Point const &p, Coord *dist = NULL) const; + PathTime nearestTime(Point const &p, Coord *dist = NULL) const; std::vector<Coord> nearestTimePerCurve(Point const &p) const; - Position nearestPosition(Point const &p, Coord *dist = NULL) const; void appendPortionTo(Path &p, Coord f, Coord t) const; @@ -541,7 +540,7 @@ public: * An extra stitching segment will be inserted if the start point of the portion * and the final point of the target path do not match exactly. * The closing segment of the target path will be modified. */ - void appendPortionTo(Path &p, Position const &from, Position const &to, bool cross_start = false) const { + void appendPortionTo(Path &p, PathTime const &from, PathTime const &to, bool cross_start = false) const { PathInterval ival(from, to, cross_start, size_closed()); appendPortionTo(p, ival, boost::none, boost::none); } @@ -573,7 +572,7 @@ public: * and will cross the initial point of the path. Therefore, when @a from is larger * than @a to and @a cross_start is true, the returned portion will not be reversed, * but will "wrap around" the end of the path. */ - Path portion(Position const &from, Position const &to, bool cross_start = false) const { + Path portion(PathTime const &from, PathTime const &to, bool cross_start = false) const { Path ret; ret.close(false); appendPortionTo(ret, from, to, cross_start); @@ -785,7 +784,7 @@ private: _closing_seg = static_cast<ClosingSegment*>(&_curves->back()); } } - Position _getPosition(Coord t) const; + PathTime _factorTime(Coord t) const; void stitch(Sequence::iterator first_replaced, Sequence::iterator last_replaced, Sequence &sequence); void do_update(Sequence::iterator first, Sequence::iterator last, Sequence &source); @@ -801,7 +800,10 @@ private: Piecewise<D2<SBasis> > paths_to_pw(PathVector const &paths); -inline Coord nearest_time(Point const &p, Path const &c) { return c.nearestTime(p); } +inline Coord nearest_time(Point const &p, Path const &c) { + PathTime pt = c.nearestTime(p); + return pt.curve_index + pt.t; +} } // end namespace Geom diff --git a/src/2geom/pathvector.cpp b/src/2geom/pathvector.cpp index d2dc468c6..720428e97 100644 --- a/src/2geom/pathvector.cpp +++ b/src/2geom/pathvector.cpp @@ -77,7 +77,7 @@ Path &PathVector::pathAt(Coord t, Coord *rest) } Path const &PathVector::pathAt(Coord t, Coord *rest) const { - Position pos = _getPosition(t); + PathVectorTime pos = _factorTime(t); if (rest) { *rest = Coord(pos.curve_index) + pos.t; } @@ -85,7 +85,7 @@ Path const &PathVector::pathAt(Coord t, Coord *rest) const } Curve const &PathVector::curveAt(Coord t, Coord *rest) const { - Position pos = _getPosition(t); + PathVectorTime pos = _factorTime(t); if (rest) { *rest = pos.t; } @@ -93,12 +93,12 @@ Curve const &PathVector::curveAt(Coord t, Coord *rest) const } Coord PathVector::valueAt(Coord t, Dim2 d) const { - Position pos = _getPosition(t); + PathVectorTime pos = _factorTime(t); return at(pos.path_index).at(pos.curve_index).valueAt(pos.t, d); } Point PathVector::pointAt(Coord t) const { - Position pos = _getPosition(t); + PathVectorTime pos = _factorTime(t); return at(pos.path_index).at(pos.curve_index).pointAt(pos.t); } @@ -135,7 +135,7 @@ void PathVector::snapEnds(Coord precision) std::vector<PVIntersection> PathVector::intersect(PathVector const &other, Coord precision) const { - typedef PathVectorPosition PVPos; + typedef PathVectorTime PVPos; std::vector<PVIntersection> result; for (std::size_t i = 0; i < size(); ++i) { for (std::size_t j = 0; j < other.size(); ++j) { @@ -158,17 +158,17 @@ int PathVector::winding(Point const &p) const return wind; } -boost::optional<PathVectorPosition> PathVector::nearestPosition(Point const &p, Coord *dist) const +boost::optional<PathVectorTime> PathVector::nearestTime(Point const &p, Coord *dist) const { - boost::optional<Position> retval; + boost::optional<PathVectorTime> retval; Coord mindist = infinity(); for (size_type i = 0; i < size(); ++i) { Coord d; - PathPosition pos = (*this)[i].nearestPosition(p, &d); + PathTime pos = (*this)[i].nearestTime(p, &d); if (d < mindist) { mindist = d; - retval = Position(i, pos.curve_index, pos.t); + retval = PathVectorTime(i, pos.curve_index, pos.t); } } @@ -178,20 +178,20 @@ boost::optional<PathVectorPosition> PathVector::nearestPosition(Point const &p, return retval; } -std::vector<PathVectorPosition> PathVector::allNearestPositions(Point const &p, Coord *dist) const +std::vector<PathVectorTime> PathVector::allNearestTimes(Point const &p, Coord *dist) const { - std::vector<Position> retval; + std::vector<PathVectorTime> retval; Coord mindist = infinity(); for (size_type i = 0; i < size(); ++i) { Coord d; - PathPosition pos = (*this)[i].nearestPosition(p, &d); + PathTime pos = (*this)[i].nearestTime(p, &d); if (d < mindist) { mindist = d; retval.clear(); } if (d <= mindist) { - retval.push_back(Position(i, pos.curve_index, pos.t)); + retval.push_back(PathVectorTime(i, pos.curve_index, pos.t)); } } @@ -201,9 +201,9 @@ std::vector<PathVectorPosition> PathVector::allNearestPositions(Point const &p, return retval; } -PathVectorPosition PathVector::_getPosition(Coord t) const +PathVectorTime PathVector::_factorTime(Coord t) const { - Position ret; + PathVectorTime ret; Coord rest = 0; ret.t = modf(t, &rest); ret.curve_index = rest; diff --git a/src/2geom/pathvector.h b/src/2geom/pathvector.h index 9140e3872..375c4f0a0 100644 --- a/src/2geom/pathvector.h +++ b/src/2geom/pathvector.h @@ -43,7 +43,7 @@ namespace Geom { -/** @brief Position (generalized time value) in the path vector. +/** @brief Generalized time value in the path vector. * * This class exists because mapping the range of multiple curves onto the same interval * as the curve index, we lose some precision. For instance, a path with 16 curves will @@ -52,41 +52,41 @@ namespace Geom { * pointAt(), nearestTime() and so on. * * @ingroup Paths */ -struct PathVectorPosition - : public PathPosition - , boost::totally_ordered<PathVectorPosition> +struct PathVectorTime + : public PathTime + , boost::totally_ordered<PathVectorTime> { size_type path_index; ///< Index of the path in the vector - PathVectorPosition() : PathPosition(0, 0), path_index(0) {} - PathVectorPosition(size_type _i, size_type _c, Coord _t) - : PathPosition(_c, _t), path_index(_i) {} - PathVectorPosition(size_type _i, PathPosition const &pos) - : PathPosition(pos), path_index(_i) {} + PathVectorTime() : PathTime(0, 0), path_index(0) {} + PathVectorTime(size_type _i, size_type _c, Coord _t) + : PathTime(_c, _t), path_index(_i) {} + PathVectorTime(size_type _i, PathTime const &pos) + : PathTime(pos), path_index(_i) {} - bool operator<(PathVectorPosition const &other) const { + bool operator<(PathVectorTime const &other) const { if (path_index < other.path_index) return true; if (path_index == other.path_index) { - return static_cast<PathPosition const &>(*this) < static_cast<PathPosition const &>(other); + return static_cast<PathTime const &>(*this) < static_cast<PathTime const &>(other); } return false; } - bool operator==(PathVectorPosition const &other) const { + bool operator==(PathVectorTime const &other) const { return path_index == other.path_index - && static_cast<PathPosition const &>(*this) == static_cast<PathPosition const &>(other); + && static_cast<PathTime const &>(*this) == static_cast<PathTime const &>(other); } - PathPosition const &asPathPosition() const { - return *static_cast<PathPosition const *>(this); + PathTime const &asPathTime() const { + return *static_cast<PathTime const *>(this); } }; -typedef Intersection<PathVectorPosition> PathVectorIntersection; +typedef Intersection<PathVectorTime> PathVectorIntersection; typedef PathVectorIntersection PVIntersection; ///< Alias to save typing template <> struct ShapeTraits<PathVector> { - typedef PathVectorPosition TimeType; + typedef PathVectorTime TimeType; //typedef PathVectorInterval IntervalType; typedef PathVector AffineClosureType; typedef PathVectorIntersection IntersectionType; @@ -118,7 +118,7 @@ class PathVector { typedef std::vector<Path> Sequence; public: - typedef PathVectorPosition Position; + typedef PathVectorTime Position; typedef Sequence::iterator iterator; typedef Sequence::const_iterator const_iterator; typedef Sequence::size_type size_type; @@ -224,19 +224,19 @@ public: Coord valueAt(Coord t, Dim2 d) const; Point pointAt(Coord t) const; - Path &pathAt(Position const &pos) { + Path &pathAt(PathVectorTime const &pos) { return const_cast<Path &>(static_cast<PathVector const*>(this)->pathAt(pos)); } - Path const &pathAt(Position const &pos) const { + Path const &pathAt(PathVectorTime const &pos) const { return at(pos.path_index); } - Curve const &curveAt(Position const &pos) const { + Curve const &curveAt(PathVectorTime const &pos) const { return at(pos.path_index).at(pos.curve_index); } - Point pointAt(Position const &pos) const { + Point pointAt(PathVectorTime const &pos) const { return at(pos.path_index).at(pos.curve_index).pointAt(pos.t); } - Coord valueAt(Position const &pos, Dim2 d) const { + Coord valueAt(PathVectorTime const &pos, Dim2 d) const { return at(pos.path_index).at(pos.curve_index).valueAt(pos.t, d); } @@ -265,12 +265,11 @@ public: * This is simply the sum of winding numbers for constituent paths. */ int winding(Point const &p) const; - Coord nearestTime(Point const &p) const; - boost::optional<Position> nearestPosition(Point const &p, Coord *dist = NULL) const; - std::vector<Position> allNearestPositions(Point const &p, Coord *dist = NULL) const; + boost::optional<PathVectorTime> nearestTime(Point const &p, Coord *dist = NULL) const; + std::vector<PathVectorTime> allNearestTimes(Point const &p, Coord *dist = NULL) const; private: - Position _getPosition(Coord t) const; + PathVectorTime _factorTime(Coord t) const; Sequence _data; }; diff --git a/src/2geom/point-ops.h b/src/2geom/point-ops.h deleted file mode 100644 index 6f5eab56b..000000000 --- a/src/2geom/point-ops.h +++ /dev/null @@ -1,25 +0,0 @@ -//[[[cog -import operators - -setContext("Point", "Matrix", "Point") -make({'*':'*='}, {'/':'/='}) -apsnd({'*':'/'}, "b.inverse()") - -setContext("Point", "double", "Point") -make({'*=':'*'}, {'/=':'/'}, {'*':'*'}, {'*':'/'}) - -setContext("Point", "Point", "bool") -make({'==':'!='}) - -setContext("Point", "Point", "Point") -make({'+=':'+', '-=':'-'}) -]]] - -************** -GENERATED CODE -************** -If you wish to modify, move function out of generation region and remove the -cause of its generation. -*/ - -//[[[end]]] |
