summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2015-05-09 15:23:25 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2015-05-09 15:23:25 +0000
commit6d9c35c80d9cabfe44682ecfa724bd0d517c56f4 (patch)
tree777d318fe9153e0c24abef521f3c44af66234ab3
parentMerge from trunk (diff)
downloadinkscape-6d9c35c80d9cabfe44682ecfa724bd0d517c56f4.tar.gz
inkscape-6d9c35c80d9cabfe44682ecfa724bd0d517c56f4.zip
Fix eraser tool
(bzr r14059.2.12)
-rw-r--r--src/2geom/CMakeLists.txt316
-rw-r--r--src/2geom/path.cpp18
-rw-r--r--src/2geom/path.h3
-rw-r--r--src/display/curve.cpp14
-rw-r--r--src/ui/tools/eraser-tool.cpp24
5 files changed, 222 insertions, 153 deletions
diff --git a/src/2geom/CMakeLists.txt b/src/2geom/CMakeLists.txt
index eb25074ef..38f39ab40 100644
--- a/src/2geom/CMakeLists.txt
+++ b/src/2geom/CMakeLists.txt
@@ -1,136 +1,186 @@
+#generate parser file with ragel
+SET(SVG_PARSER_CPP "${CMAKE_CURRENT_SOURCE_DIR}/svg-path-parser.cpp")
+SET(SVG_PARSER_TMP "${CMAKE_CURRENT_SOURCE_DIR}/svg-path-parser.tmp")
+SET(SVG_PARSER_RL "${CMAKE_CURRENT_SOURCE_DIR}/svg-path-parser.rl")
+SET(GENERATE_SVG_PARSER NOT EXISTS "${SVG_PARSER_CPP}")
+SET(REGENERATE_SVG_PARSER "${SVG_PARSER_CPP}" IS_NEWER_THAN "${SVG_PARSER_RL}")
+find_program(RAGEL_PROGRAM
+ NAMES ragel
+ ragel.exe
+ DOC "Find ragel program"
+ HINTS /usr/bin
+ /usr/local/bin
+ ${RAGEL_BIN}
+ ${MINGW_BIN}
+)
+IF( RAGEL_PROGRAM )
+IF(GENERATE_SVG_PARSER OR REGENERATE_SVG_PARSER)
+ ADD_CUSTOM_COMMAND(OUTPUT "${SVG_PARSER_CPP}"
+ COMMAND ${RAGEL_PROGRAM} -C -T0 -o "${SVG_PARSER_CPP}" "${SVG_PARSER_RL}"
+ DEPENDS "${SVG_PARSER_RL}"
+ WORKING_DIRECTORY "${CURRENT_SOURCE_DIR}"
+ COMMENT "Generating svg_path_parser.cpp with ragel"
+ )
+ENDIF(GENERATE_SVG_PARSER OR REGENERATE_SVG_PARSER)
+ENDIF( RAGEL_PROGRAM )
+
+SET(2GEOM_SRC
+
+affine.cpp
+affine.h
+angle.h
+
+basic-intersection.cpp
+basic-intersection.h
+bezier.cpp
+bezier.h
+bezier-clipping.cpp
+bezier-curve.cpp
+bezier-curve.h
+bezier-to-sbasis.h
+bezier-utils.cpp
+bezier-utils.h
+
+cairo-path-sink.h
+cairo-path-sink.cpp
+choose.h
+circle.cpp
+circle.h
+concepts.cpp
+concepts.h
+conicsec.cpp
+conicsec.h
+conic_section_clipper.h
+conic_section_clipper_cr.h
+conic_section_clipper_impl.cpp
+conic_section_clipper_impl.h
+convex-hull.cpp
+convex-hull.h
+coord.cpp
+coord.h
+crossing.cpp
+crossing.h
+curve.cpp
+curve.h
+curves.h
+
+d2-sbasis.cpp
+d2-sbasis.h
+d2.h
+
+ellipse.cpp
+ellipse.h
+elliptical-arc.cpp
+elliptical-arc.h
+exception.h
+
+forward.h
+
+geom.cpp
+geom.h
+
+intersection.h
+intersection-graph.cpp
+intersection-graph.h
+
+line.cpp
+line.h
+linear.h
+
+math-utils.h
+
+nearest-time.cpp
+nearest-time.h
+
+numeric/matrix.cpp
-set(2geom_SRC
- affine.cpp
- basic-intersection.cpp
- bezier.cpp
- bezier-clipping.cpp
- bezier-curve.cpp
- bezier-utils.cpp
- cairo-path-sink.cpp
- circle-circle.cpp
- circle.cpp
- # conic_section_clipper_impl.cpp
- # conicsec.cpp
- convex-hull.cpp
- coord.cpp
- crossing.cpp
- curve.cpp
- d2-sbasis.cpp
- ellipse.cpp
- elliptical-arc.cpp
- geom.cpp
- intersection-graph.cpp
- line.cpp
- nearest-time.cpp
- numeric/matrix.cpp
- path-intersection.cpp
- path-sink.cpp
- path.cpp
- pathvector.cpp
- piecewise.cpp
- point.cpp
- poly.cpp
- quadtree.cpp
- rect.cpp
- # recursive-bezier-intersection.cpp
- sbasis-2d.cpp
- sbasis-geometric.cpp
- sbasis-math.cpp
- sbasis-poly.cpp
- sbasis-roots.cpp
- sbasis-to-bezier.cpp
- sbasis.cpp
- solve-bezier.cpp
- solve-bezier-one-d.cpp
- solve-bezier-parametric.cpp
- svg-elliptical-arc.cpp
- svg-path-parser.cpp
- sweep.cpp
- toposweep.cpp
- transforms.cpp
- utils.cpp
- viewbox.cpp
-
-
- # -------
- 2geom.h
- # Headers
- affine.h
- angle.h
- basic-intersection.h
- bezier-curve.h
- bezier-to-sbasis.h
- bezier-utils.h
- bezier.h
- choose.h
- circle.h
- concepts.h
- conic_section_clipper.h
- conic_section_clipper_cr.h
- conic_section_clipper_impl.h
- conicsec.h
- conjugate_gradient.h
- convex-cover.h
- coord.h
- crossing.h
- curve.h
- curves.h
- d2-sbasis.h
- d2.h
- ellipse.h
- elliptical-arc.h
- exception.h
- forward.h
- generic-interval.h
- generic-rect.h
- geom.h
- hvlinesegment.h
- int-interval.h
- int-point.h
- int-rect.h
- interval.h
- line.h
- linear.h
- math-utils.h
- nearest-point.h
- ord.h
- path-intersection.h
- path-sink.h
- path.h
- pathvector.h
- piecewise.h
- point-ops.h
- point.h
- poly.h
- quadtree.h
- ray.h
- rect.h
- region.h
- sbasis-2d.h
- sbasis-curve.h
- sbasis-geometric.h
- sbasis-math.h
- sbasis-poly.h
- sbasis-to-bezier.h
- sbasis.h
- shape.h
- solver.h
- svg-elliptical-arc.h
- svg-path-parser.h
- sweep.h
- toposweep.h
- transforms.h
- utils.h
-
- numeric/fitting-model.h
- numeric/fitting-tool.h
- numeric/linear_system.h
- numeric/matrix.h
- numeric/symmetric-matrix-fs-operation.h
- numeric/symmetric-matrix-fs-trace.h
- numeric/symmetric-matrix-fs.h
- numeric/vector.h
+ord.h
+
+path-intersection.cpp
+path-intersection.h
+path-sink.cpp
+path-sink.h
+path.cpp
+path.h
+pathvector.cpp
+pathvector.h
+piecewise.cpp
+piecewise.h
+point.cpp
+point.h
+poly.cpp
+poly.h
+
+quadtree.cpp
+quadtree.h
+
+ray.h
+rect.h
+rect.cpp
+recursive-bezier-intersection.cpp
+
+sbasis-2d.cpp
+sbasis-2d.h
+sbasis-curve.h
+sbasis-geometric.cpp
+sbasis-geometric.h
+sbasis-math.cpp
+sbasis-math.h
+sbasis-poly.cpp
+sbasis-poly.h
+sbasis-roots.cpp
+sbasis-to-bezier.cpp
+sbasis-to-bezier.h
+sbasis.cpp
+sbasis.h
+solve-bezier.cpp
+solve-bezier-one-d.cpp
+solve-bezier-parametric.cpp
+solver.h
+svg-elliptical-arc.cpp
+svg-elliptical-arc.h
+svg-path-parser.cpp
+svg-path-parser.h
+svg-path-writer.cpp
+svg-path-writer.h
+sweep.cpp
+sweep.h
+
+toposweep.cpp
+toposweep.h
+transforms.cpp
+transforms.h
+
+utils.cpp
+utils.h
+
+viewbox.cpp
+viewbox.h
)
-# make lib for 2geom_LIB
-add_inkscape_lib(2geom_LIB "${2geom_SRC}")
+# make lib for 2geom
+ADD_LIBRARY(2geom ${LIB_TYPE} ${2GEOM_SRC})
+TARGET_LINK_LIBRARIES(2geom "${LINK_GSL} ${GTK2_LINK_FLAGS}")
+SET_TARGET_PROPERTIES(2geom PROPERTIES SOVERSION "${2GEOM_ABI_VERSION}")
+INSTALL(TARGETS 2geom
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
+FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
+INSTALL(FILES ${files} DESTINATION include/2geom-${2GEOM_VERSION}/2geom)
+FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/numeric/*.h")
+INSTALL(FILES ${files} DESTINATION include/2geom-${2GEOM_VERSION}/2geom/numeric)
+
+CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/2geom.pc.in
+ ${CMAKE_BINARY_DIR}/2geom.pc @ONLY IMMEDIATE )
+INSTALL(FILES "${CMAKE_BINARY_DIR}/2geom.pc" DESTINATION lib/pkgconfig)
+ADD_SUBDIRECTORY (toys)
+ADD_SUBDIRECTORY (tests)
+ADD_SUBDIRECTORY (py2geom)
+ADD_SUBDIRECTORY (performance-tests)
+
+
+add_subdirectory(cython-bindings)
+
+
diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp
index 71b7b25bb..e38835776 100644
--- a/src/2geom/path.cpp
+++ b/src/2geom/path.cpp
@@ -215,6 +215,18 @@ PathInterval PathInterval::from_direction(PathTime const &from, PathTime const &
}
+Path::Path(Rect const &r)
+ : _curves(new Sequence())
+ , _closing_seg(new ClosingSegment(r.corner(3), r.corner(0)))
+ , _closed(true)
+ , _exception_on_stitch(true)
+{
+ for (unsigned i = 0; i < 3; ++i) {
+ _curves->push_back(new LineSegment(r.corner(i), r.corner(i+1)));
+ }
+ _curves->push_back(_closing_seg);
+}
+
Path::Path(ConvexHull const &ch)
: _curves(new Sequence())
, _closing_seg(new ClosingSegment(Point(), Point()))
@@ -678,12 +690,12 @@ Path Path::reversed() const
typedef std::reverse_iterator<Sequence::const_iterator> RIter;
Path ret;
- ret._curves->pop_back();
- RIter iter(_curves->end()), rend(_curves->begin());
+ ret._curves->pop_back(); // this also deletes the closing segment
+ RIter iter(_curves->end() - 1), rend(_curves->begin());
for (; iter != rend; ++iter) {
ret._curves->push_back(iter->reverse());
}
- ret._closing_seg = static_cast<ClosingSegment *>(ret._closing_seg->reverse());
+ ret._closing_seg = static_cast<ClosingSegment *>(_closing_seg->reverse());
ret._curves->push_back(ret._closing_seg);
return ret;
}
diff --git a/src/2geom/path.h b/src/2geom/path.h
index 58afcfd8d..5a172f598 100644
--- a/src/2geom/path.h
+++ b/src/2geom/path.h
@@ -371,6 +371,9 @@ public:
_curves->push_back(_closing_seg);
}
+ /// Construct a path from a rectangle.
+ Path(Rect const &r);
+
/// Construct a path from a convex hull.
Path(ConvexHull const &);
diff --git a/src/display/curve.cpp b/src/display/curve.cpp
index 6cc7121dc..d236d81cf 100644
--- a/src/display/curve.cpp
+++ b/src/display/curve.cpp
@@ -31,14 +31,12 @@
SPCurve::SPCurve()
: _refcount(1),
_pathv()
-{
-}
+{}
SPCurve::SPCurve(Geom::PathVector const& pathv)
: _refcount(1),
_pathv(pathv)
-{
-}
+{}
SPCurve *
SPCurve::new_from_rect(Geom::Rect const &rect, bool all_four_sides)
@@ -90,13 +88,7 @@ SPCurve::get_pathvector() const
size_t
SPCurve::get_segment_count() const
{
- size_t nr = 0;
- for(Geom::PathVector::const_iterator it = _pathv.begin(); it != _pathv.end(); ++it) {
- nr += (*it).size();
-
- if (it->closed()) nr += 1;
- }
- return nr;
+ return _pathv.curveCount();
}
/**
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index 10f8c8694..e416fd7ef 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -789,6 +789,8 @@ add_cap(SPCurve *curve,
}
void EraserTool::accumulate() {
+ // construct a crude outline of the eraser's path.
+ // this desperately needs to be rewritten to use the path outliner...
if ( !this->cal1->is_empty() && !this->cal2->is_empty() ) {
this->accumulated->reset(); /* Is this required ?? */
SPCurve *rev_cal2 = this->cal2->create_reverse();
@@ -798,10 +800,10 @@ void EraserTool::accumulate() {
g_assert( ! this->cal1->first_path()->closed() );
g_assert( ! rev_cal2->first_path()->closed() );
- Geom::CubicBezier const * dc_cal1_firstseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->first_segment() );
- Geom::CubicBezier const * rev_cal2_firstseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->first_segment() );
- Geom::CubicBezier const * dc_cal1_lastseg = dynamic_cast<Geom::CubicBezier const *>( this->cal1->last_segment() );
- Geom::CubicBezier const * rev_cal2_lastseg = dynamic_cast<Geom::CubicBezier const *>( rev_cal2->last_segment() );
+ Geom::BezierCurve const * dc_cal1_firstseg = dynamic_cast<Geom::BezierCurve const *>( this->cal1->first_segment() );
+ Geom::BezierCurve const * rev_cal2_firstseg = dynamic_cast<Geom::BezierCurve const *>( rev_cal2->first_segment() );
+ Geom::BezierCurve const * dc_cal1_lastseg = dynamic_cast<Geom::BezierCurve const *>( this->cal1->last_segment() );
+ Geom::BezierCurve const * rev_cal2_lastseg = dynamic_cast<Geom::BezierCurve const *>( rev_cal2->last_segment() );
g_assert( dc_cal1_firstseg );
g_assert( rev_cal2_firstseg );
@@ -810,11 +812,21 @@ void EraserTool::accumulate() {
this->accumulated->append(this->cal1, FALSE);
- add_cap(this->accumulated, (*dc_cal1_lastseg)[2], (*dc_cal1_lastseg)[3], (*rev_cal2_firstseg)[0], (*rev_cal2_firstseg)[1], this->cap_rounding);
+ add_cap(this->accumulated,
+ dc_cal1_lastseg->finalPoint() - dc_cal1_lastseg->unitTangentAt(1),
+ dc_cal1_lastseg->finalPoint(),
+ rev_cal2_firstseg->initialPoint(),
+ rev_cal2_firstseg->initialPoint() + rev_cal2_firstseg->unitTangentAt(0),
+ this->cap_rounding);
this->accumulated->append(rev_cal2, TRUE);
- add_cap(this->accumulated, (*rev_cal2_lastseg)[2], (*rev_cal2_lastseg)[3], (*dc_cal1_firstseg)[0], (*dc_cal1_firstseg)[1], this->cap_rounding);
+ add_cap(this->accumulated,
+ rev_cal2_lastseg->finalPoint() - rev_cal2_lastseg->unitTangentAt(1),
+ rev_cal2_lastseg->finalPoint(),
+ dc_cal1_firstseg->initialPoint(),
+ dc_cal1_firstseg->initialPoint() + dc_cal1_firstseg->unitTangentAt(0),
+ this->cap_rounding);
this->accumulated->closepath();