summaryrefslogtreecommitdiffstats
path: root/src/display
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
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')
-rw-r--r--src/display/curve-test.h26
-rw-r--r--src/display/curve.cpp30
-rw-r--r--src/display/curve.h4
3 files changed, 33 insertions, 27 deletions
diff --git a/src/display/curve-test.h b/src/display/curve-test.h
index 56b49ff4c..c0b0e900b 100644
--- a/src/display/curve-test.h
+++ b/src/display/curve-test.h
@@ -185,32 +185,34 @@ public:
void testFirstPoint()
{
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path1)).first_point() , Geom::Point(0,0));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path2)).first_point() , Geom::Point(2,0));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path3)).first_point() , Geom::Point(4,0));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path4)).first_point() , Geom::Point(3,5));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path1)).first_point()) , Geom::Point(0,0));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path2)).first_point()) , Geom::Point(2,0));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path3)).first_point()) , Geom::Point(4,0));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path4)).first_point()) , Geom::Point(3,5));
Geom::PathVector pv;
+ TS_ASSERT(!SPCurve(pv).first_point());
pv.push_back(path1);
pv.push_back(path2);
pv.push_back(path3);
- TS_ASSERT_EQUALS(SPCurve(pv).first_point() , Geom::Point(0,0));
+ TS_ASSERT_EQUALS(*(SPCurve(pv).first_point()) , Geom::Point(0,0));
pv.insert(pv.begin(), path4);
- TS_ASSERT_EQUALS(SPCurve(pv).first_point() , Geom::Point(3,5));
+ TS_ASSERT_EQUALS(*(SPCurve(pv).first_point()) , Geom::Point(3,5));
}
void testLastPoint()
{
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path1)).last_point() , Geom::Point(0,0));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path2)).last_point() , Geom::Point(2,0));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path3)).last_point() , Geom::Point(8,4));
- TS_ASSERT_EQUALS(SPCurve(Geom::PathVector(1, path4)).last_point() , Geom::Point(3,5));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path1)).last_point()) , Geom::Point(0,0));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path2)).last_point()) , Geom::Point(2,0));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path3)).last_point()) , Geom::Point(8,4));
+ TS_ASSERT_EQUALS(*(SPCurve(Geom::PathVector(1, path4)).last_point()) , Geom::Point(3,5));
Geom::PathVector pv;
+ TS_ASSERT(!SPCurve(pv).last_point());
pv.push_back(path1);
pv.push_back(path2);
pv.push_back(path3);
- TS_ASSERT_EQUALS(SPCurve(pv).last_point() , Geom::Point(8,4));
+ TS_ASSERT_EQUALS(*(SPCurve(pv).last_point()) , Geom::Point(8,4));
pv.push_back(path4);
- TS_ASSERT_EQUALS(SPCurve(pv).last_point() , Geom::Point(3,5));
+ TS_ASSERT_EQUALS(*(SPCurve(pv).last_point()) , Geom::Point(3,5));
}
void testSecondPoint()
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);
diff --git a/src/display/curve.h b/src/display/curve.h
index 8bb3fb360..1b09c8c6e 100644
--- a/src/display/curve.h
+++ b/src/display/curve.h
@@ -48,8 +48,8 @@ public:
Geom::Path const * last_path() const;
Geom::Curve const * first_segment() const;
Geom::Path const * first_path() const;
- Geom::Point first_point() const;
- Geom::Point last_point() const;
+ boost::optional<Geom::Point> first_point() const;
+ boost::optional<Geom::Point> last_point() const;
boost::optional<Geom::Point> second_point() const;
boost::optional<Geom::Point> penultimate_point() const;