summaryrefslogtreecommitdiffstats
path: root/src/display/curve.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-08-13 19:06:18 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-08-13 19:06:18 +0000
commit9c33efba40912d582a4844e4e82a72c13c8c4887 (patch)
tree0375f8c5f56a9ce8d03bc483ab0c14d223d6f39e /src/display/curve.cpp
parentreturn boost::optional for second and penultimate points of SPCurve (diff)
downloadinkscape-9c33efba40912d582a4844e4e82a72c13c8c4887.tar.gz
inkscape-9c33efba40912d582a4844e4e82a72c13c8c4887.zip
make spcurve::first_point and last_point boost::optional
(bzr r6617)
Diffstat (limited to 'src/display/curve.cpp')
-rw-r--r--src/display/curve.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/display/curve.cpp b/src/display/curve.cpp
index 9f6c34981..8b1d977f5 100644
--- a/src/display/curve.cpp
+++ b/src/display/curve.cpp
@@ -360,15 +360,18 @@ SPCurve::first_path() const
}
/**
- * Return first point of first subpath or (0,0). TODO: shouldn't this be (NR_HUGE, NR_HUGE) to be able to tell it apart from normal (0,0) ?
+ * Return first point of first subpath or nothing when the path is empty.
*/
-Geom::Point
+boost::optional<Geom::Point>
SPCurve::first_point() const
{
- if (is_empty())
- return Geom::Point(0, 0);
+ boost::optional<Geom::Point> retval;
+
+ if (!is_empty()) {
+ retval = _pathv.front().initialPoint();
+ }
- return _pathv.front().initialPoint();
+ return retval;
}
/**
@@ -414,7 +417,7 @@ SPCurve::penultimate_point() const
}
/**
- * Return last point of last subpath or (0,0). TODO: shouldn't this be (NR_HUGE, NR_HUGE) to be able to tell it apart from normal (0,0) ?
+ * Return last point of last subpath or nothing when the curve is empty.
* If the last path is only a moveto, then return that point.
*/
boost::optional<Geom::Point>
@@ -422,10 +425,11 @@ SPCurve::last_point() const
{
boost::optional<Geom::Point> retval;
- if (is_empty())
- return Geom::Point(0, 0);
+ if (!is_empty()) {
+ retval = _pathv.back().finalPoint();
+ }
- return _pathv.back().finalPoint();
+ return retval;
}
/**
@@ -500,8 +504,8 @@ SPCurve::append_continuous(SPCurve const *c1, gdouble tolerance)
return this;
}
- if ( (fabs(this->last_point()[X] - c1->first_point()[X]) <= tolerance)
- && (fabs(this->last_point()[Y] - c1->first_point()[Y]) <= tolerance) )
+ if ( (fabs((*this->last_point())[X] - (*c1->first_point())[X]) <= tolerance)
+ && (fabs((*this->last_point())[Y] - (*c1->first_point())[Y]) <= tolerance) )
{
// c1's first subpath can be appended to this curve's last subpath
Geom::PathVector::const_iterator path_it = c1->_pathv.begin();
@@ -548,8 +552,8 @@ SPCurve::stretch_endpoints(Geom::Point const &new_p0, Geom::Point const &new_p1)
return;
}
- Geom::Point const offset0( new_p0 - first_point() );
- Geom::Point const offset1( new_p1 - last_point() );
+ Geom::Point const offset0( new_p0 - *first_point() );
+ Geom::Point const offset1( new_p1 - *last_point() );
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _pathv.front().toPwSb();
Geom::Piecewise<Geom::SBasis> arclength = Geom::arcLengthSb(pwd2);