Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## lib2geom-devel

 [Lib2geom-devel] Bug in nearest-point? From: Diederik van Lierop - 2011-09-22 19:24:08 Attachments: Message as HTML     WontSnapToSomeCurveSegments.svg ```=== modified file 'src/2geom/bezier-curve.cpp' --- src/2geom/bezier-curve.cpp 2011-07-25 01:06:47 +0000 +++ src/2geom/bezier-curve.cpp 2011-09-21 21:10:45 +0000 @@ -166,6 +166,7 @@ template<> Coord BezierCurveN<1>::nearestPoint(Point const& p, Coord from, Coord to) const { + std::cout << "(entering nearestPoint in bezier-curve.cpp, line 169)" << std::endl; if ( from > to ) std::swap(from, to); Point ip = pointAt(from); Point fp = pointAt(to); @@ -173,9 +174,18 @@ Coord l2v = L2sq(v); if (l2v == 0) return 0; Coord t = dot( p - ip, v ) / l2v; - if ( t <= 0 ) return from; - else if ( t >= 1 ) return to; - else return from + t*(to-from); + if ( t <= 0 ) { + std::cout << " zero nr. 0 | t -> " << from << std::endl; + return from; + } + else if ( t >= 1 ) { + std::cout << " zero nr. 0 | t -> " << to << std::endl; + return to; + } + else { + std::cout << " zero nr. 0 | t -> " << from + t*(to-from) << std::endl; + return from + t*(to-from); + } } === modified file 'src/2geom/nearest-point.cpp' --- src/2geom/nearest-point.cpp 2008-11-21 05:24:08 +0000 +++ src/2geom/nearest-point.cpp 2011-09-21 19:42:11 +0000 @@ -54,6 +54,7 @@ D2 const& dc, double from, double to ) { + std::cout << "(entering nearest_point in nearest-point.cpp, line 57)" << std::endl; if ( from > to ) std::swap(from, to); if ( from < 0 || to > 1 ) { @@ -66,6 +67,9 @@ double closest = from; double min_dist_sq = L2sq(c(from) - p); double distsq; + if (zeros.size() == 0) { + std::cout << " No zeroes found; how can there possibly be NO nearest points for any segment?" << std::endl; + } for ( unsigned int i = 0; i < zeros.size(); ++i ) { distsq = L2sq(c(zeros[i]) - p); @@ -74,9 +78,12 @@ closest = zeros[i]; min_dist_sq = distsq; } + std::cout << " zero nr. " << i << " | t -> " << zeros[i] << std::endl; } if ( min_dist_sq > L2sq( c(to) - p ) ) closest = to; + + std::cout << "All zeros have been examined; closest t = " << closest; return closest; } === modified file 'src/2geom/nearest-point.h' --- src/2geom/nearest-point.h 2008-10-28 04:45:31 +0000 +++ src/2geom/nearest-point.h 2011-09-21 19:42:11 +0000 @@ -77,7 +77,7 @@ D2 const& c, double from = 0, double to = 1 ) { - return nearest_point(p, c, Geom::derivative(c), from, to); + return nearest_point(p, c, Geom::derivative(c), from, to); } /* @@ -110,7 +110,7 @@ inline double nearest_point( Point const& p, Piecewise< D2 > const& c ) { - return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]); + return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]); } === modified file 'src/2geom/path.cpp' --- src/2geom/path.cpp 2011-02-02 21:24:36 +0000 +++ src/2geom/path.cpp 2011-09-21 18:30:05 +0000 @@ -205,11 +205,18 @@ { //return a single nearest point for each curve in this path std::vector np; + int count = 0; + std::cout << "Mouse pointer is at " << _point << std::endl; for (const_iterator it = begin() ; it != end_default() ; ++it) //for (std::vector::const_iterator it = _path.begin(); it != _path.end(), ++it){ { - np.push_back(it->nearestPoint(_point)); + std::cout << "***** Start examining segment nr." << count << " *****" << std::endl; + double dummy = it->nearestPoint(_point); + std::cout << " | point = " << it->pointAt(dummy) << std::endl; + np.push_back(dummy); + count++; } + std::cout << "************** Done with this path*****************" << std::endl; return np; } === modified file 'src/2geom/path.h' --- src/2geom/path.h 2011-06-23 16:38:51 +0000 +++ src/2geom/path.h 2011-09-21 19:42:11 +0000 @@ -681,7 +681,7 @@ inline Coord nearest_point(Point const& p, Path const& c) { - return c.nearestPoint(p); + return c.nearestPoint(p); } } // end namespace Geom === modified file 'src/display/snap-indicator.cpp' --- src/display/snap-indicator.cpp 2011-09-18 17:09:29 +0000 +++ src/display/snap-indicator.cpp 2011-09-19 20:23:59 +0000 @@ -302,7 +302,7 @@ void SnapIndicator::set_new_snapsource(Inkscape::SnapCandidatePoint const &p) { - remove_snapsource(); + //remove_snapsource(); g_assert(_desktop != NULL); === modified file 'src/object-snapper.cpp' --- src/object-snapper.cpp 2011-09-17 12:08:49 +0000 +++ src/object-snapper.cpp 2011-09-21 18:16:30 +0000 @@ -516,12 +516,13 @@ // n curves will return n time values with 0 <= t <= 1 std::vector anp = (*it_pv).nearestPointPerCurve(p_doc); + std::cout << "#nearest points = " << anp.size() << " | p = " << p.getPoint() << std::endl; std::vector::const_iterator np = anp.begin(); unsigned int index = 0; for (; np != anp.end(); np++, index++) { Geom::Curve const *curve = &((*it_pv).at_index(index)); Geom::Point const sp_doc = curve->pointAt(*np); - + _snapmanager->getDesktop()->snapindicator->set_new_snapsource(Inkscape::SnapCandidatePoint(sp_doc*_snapmanager->getDesktop()->doc2dt(), SNAPSOURCE_UNDEFINED)); bool c1 = true; bool c2 = true; if (being_edited) { @@ -547,6 +548,7 @@ Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc); if (!being_edited || (c1 && c2)) { Geom::Coord const dist = Geom::distance(sp_doc, p_doc); + std::cout << " dist -> " << dist << std::endl; if (dist < getSnapperTolerance()) { isr.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); } ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Diederik van Lierop - 2011-09-23 18:50:00 Attachments: SingleSegmentPath.svg     patch2.diff ```Hi all, This is more illustrative: http://www.diedenrezi.nl/SingleSegmentPath.webm. Watch the green diamond, which indicates what 2geom believes to be the closest point. Now the problem is demonstrated using a path with only a single segment. I've also updated my patch to eliminate the trailing tail of the snap indicator, and have attached this very basic SVG file. Thanks, Diederik ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Nathan Hurst - 2011-09-23 19:05:56 ```Hi Diederik, I spent some time last night isolating the bug. I haven't succeeded, but I did find some interesting breakage: It is definitely wrong. I've looked at the example svgd using toys/point-curve-nearest-point (you can pass an svgd file as a parameter and using the 6 option.) What I've noticed is that if the path is < 0 in the y axis then the misbehaviour you've noticed happens, if it lies wholely above y = 0 then it behaves correctly. The X position seems unconnected. > Let me explain: I'm using nearestPoint() to find the closest > point > on a path segment, and snap to it. Now for some segments this > only > returns the desired time t for about half of the path, whereas > for > the other part it simply returns t = 0.
I'm seeing it skip whole curves, it is coincidence that the nearest curve point is at the start point. I have a strong suspicion that the problem is in the Path::nearestPoint, rather than the curve nearestPoint code. I can't reproduce this behaviour in single curves^H^H^H^ Actually, I can.... njh On Fri, Sep 23, 2011 at 08:49:46PM +0200, Diederik van Lierop wrote: > Hi all, > > This is more illustrative: > http://www.diedenrezi.nl/SingleSegmentPath.webm. Watch the green > diamond, which indicates what 2geom believes to be the closest > point. > > Now the problem is demonstrated using a path with only a single > segment. I've also updated my patch to eliminate the trailing tail > of the snap indicator, and have attached this very basic SVG file. > > Thanks, > > Diederik > === modified file 'src/2geom/bezier-curve.cpp' > --- src/2geom/bezier-curve.cpp 2011-07-25 01:06:47 +0000 > +++ src/2geom/bezier-curve.cpp 2011-09-21 21:10:45 +0000 > @@ -166,6 +166,7 @@ > template<> > Coord BezierCurveN<1>::nearestPoint(Point const& p, Coord from, Coord to) const > { > + std::cout << "(entering nearestPoint in bezier-curve.cpp, line 169)" << std::endl; > if ( from > to ) std::swap(from, to); > Point ip = pointAt(from); > Point fp = pointAt(to); > @@ -173,9 +174,18 @@ > Coord l2v = L2sq(v); > if (l2v == 0) return 0; > Coord t = dot( p - ip, v ) / l2v; > - if ( t <= 0 ) return from; > - else if ( t >= 1 ) return to; > - else return from + t*(to-from); > + if ( t <= 0 ) { > + std::cout << " zero nr. 0 | t -> " << from << std::endl; > + return from; > + } > + else if ( t >= 1 ) { > + std::cout << " zero nr. 0 | t -> " << to << std::endl; > + return to; > + } > + else { > + std::cout << " zero nr. 0 | t -> " << from + t*(to-from) << std::endl; > + return from + t*(to-from); > + } > } > > > > === modified file 'src/2geom/nearest-point.cpp' > --- src/2geom/nearest-point.cpp 2008-11-21 05:24:08 +0000 > +++ src/2geom/nearest-point.cpp 2011-09-21 19:42:11 +0000 > @@ -54,6 +54,7 @@ > D2 const& dc, > double from, double to ) > { > + std::cout << "(entering nearest_point in nearest-point.cpp, line 57)" << std::endl; > if ( from > to ) std::swap(from, to); > if ( from < 0 || to > 1 ) > { > @@ -66,6 +67,9 @@ > double closest = from; > double min_dist_sq = L2sq(c(from) - p); > double distsq; > + if (zeros.size() == 0) { > + std::cout << " No zeroes found; how can there possibly be NO nearest points for any segment?" << std::endl; > + } > for ( unsigned int i = 0; i < zeros.size(); ++i ) > { > distsq = L2sq(c(zeros[i]) - p); > @@ -74,9 +78,12 @@ > closest = zeros[i]; > min_dist_sq = distsq; > } > + std::cout << " zero nr. " << i << " | t -> " << zeros[i] << std::endl; > } > if ( min_dist_sq > L2sq( c(to) - p ) ) > closest = to; > + > + std::cout << "All zeros have been examined; closest t = " << closest; > return closest; > > } > > === modified file 'src/2geom/nearest-point.h' > --- src/2geom/nearest-point.h 2008-10-28 04:45:31 +0000 > +++ src/2geom/nearest-point.h 2011-09-21 19:42:11 +0000 > @@ -77,7 +77,7 @@ > D2 const& c, > double from = 0, double to = 1 ) > { > - return nearest_point(p, c, Geom::derivative(c), from, to); > + return nearest_point(p, c, Geom::derivative(c), from, to); > } > > /* > @@ -110,7 +110,7 @@ > inline > double nearest_point( Point const& p, Piecewise< D2 > const& c ) > { > - return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]); > + return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]); > } > > > > === modified file 'src/2geom/path.cpp' > --- src/2geom/path.cpp 2011-02-02 21:24:36 +0000 > +++ src/2geom/path.cpp 2011-09-21 18:30:05 +0000 > @@ -205,11 +205,18 @@ > { > //return a single nearest point for each curve in this path > std::vector np; > + int count = 0; > + std::cout << "Mouse pointer is at " << _point << std::endl; > for (const_iterator it = begin() ; it != end_default() ; ++it) > //for (std::vector::const_iterator it = _path.begin(); it != _path.end(), ++it){ > { > - np.push_back(it->nearestPoint(_point)); > + std::cout << "***** Start examining segment nr." << count << " *****" << std::endl; > + double dummy = it->nearestPoint(_point); > + std::cout << " | point = " << it->pointAt(dummy) << std::endl; > + np.push_back(dummy); > + count++; > } > + std::cout << "************** Done with this path*****************" << std::endl; > return np; > } > > > === modified file 'src/2geom/path.h' > --- src/2geom/path.h 2011-06-23 16:38:51 +0000 > +++ src/2geom/path.h 2011-09-21 19:42:11 +0000 > @@ -681,7 +681,7 @@ > inline > Coord nearest_point(Point const& p, Path const& c) > { > - return c.nearestPoint(p); > + return c.nearestPoint(p); > } > > } // end namespace Geom > > === modified file 'src/display/snap-indicator.cpp' > --- src/display/snap-indicator.cpp 2011-09-18 17:09:29 +0000 > +++ src/display/snap-indicator.cpp 2011-09-23 18:32:57 +0000 > @@ -302,7 +302,7 @@ > void > SnapIndicator::set_new_snapsource(Inkscape::SnapCandidatePoint const &p) > { > - remove_snapsource(); > + //remove_snapsource(); > > g_assert(_desktop != NULL); > > @@ -326,6 +326,25 @@ > } > > void > +SnapIndicator::set_new_debugging_point(Geom::Point const &p) > +{ > + g_assert(_desktop != NULL); > + SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (_desktop), > + SP_TYPE_CTRL, > + "anchor", GTK_ANCHOR_CENTER, > + "size", 10.0, > + "fill_color", 0x00ff00ff, > + "stroked", FALSE, > + "mode", SP_KNOT_MODE_XOR, > + "shape", SP_KNOT_SHAPE_DIAMOND, > + NULL ); > + > + SP_CTRL(canvasitem)->moveto(p); > + _debugging_points.push_back(_desktop->add_temporary_canvasitem(canvasitem, 5000)); > + > +} > + > +void > SnapIndicator::remove_snapsource() > { > if (_snapsource) { > @@ -334,6 +353,16 @@ > } > } > > +void > +SnapIndicator::remove_debugging_points() > +{ > + for (std::list::const_iterator i = _debugging_points.begin(); i != _debugging_points.end(); i++) { > + _desktop->remove_temporary_canvasitem(*i); > + } > + _debugging_points.clear(); > +} > + > + > } //namespace Display > } /* namespace Inkscape */ > > > === modified file 'src/display/snap-indicator.h' > --- src/display/snap-indicator.h 2010-12-23 08:10:28 +0000 > +++ src/display/snap-indicator.h 2011-09-23 18:15:57 +0000 > @@ -33,11 +33,15 @@ > void set_new_snapsource(Inkscape::SnapCandidatePoint const &p); > void remove_snapsource(); > > + void set_new_debugging_point(Geom::Point const &p); > + void remove_debugging_points(); > + > protected: > TemporaryItem *_snaptarget; > TemporaryItem *_snaptarget_tooltip; > TemporaryItem *_snaptarget_bbox; > TemporaryItem *_snapsource; > + std::list _debugging_points; > bool _snaptarget_is_presnap; > SPDesktop *_desktop; > > > === modified file 'src/object-snapper.cpp' > --- src/object-snapper.cpp 2011-09-17 12:08:49 +0000 > +++ src/object-snapper.cpp 2011-09-23 18:23:54 +0000 > @@ -506,6 +506,7 @@ > > bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); > > + _snapmanager->getDesktop()->snapindicator->remove_debugging_points(); > for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { > if (_allowSourceToSnapToTarget(p.getSourceType(), (*it_p).target_type, strict_snapping)) { > bool const being_edited = node_tool_active && (*it_p).currently_being_edited; > @@ -516,12 +517,14 @@ > // n curves will return n time values with 0 <= t <= 1 > std::vector anp = (*it_pv).nearestPointPerCurve(p_doc); > > + std::cout << "#nearest points = " << anp.size() << " | p = " << p.getPoint() << std::endl; > std::vector::const_iterator np = anp.begin(); > unsigned int index = 0; > for (; np != anp.end(); np++, index++) { > Geom::Curve const *curve = &((*it_pv).at_index(index)); > Geom::Point const sp_doc = curve->pointAt(*np); > - > + //_snapmanager->getDesktop()->snapindicator->set_new_snapsource(Inkscape::SnapCandidatePoint(sp_doc*_snapmanager->getDesktop()->doc2dt(), SNAPSOURCE_UNDEFINED)); > + _snapmanager->getDesktop()->snapindicator->set_new_debugging_point(sp_doc*_snapmanager->getDesktop()->doc2dt()); > bool c1 = true; > bool c2 = true; > if (being_edited) { > @@ -547,6 +550,7 @@ > Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc); > if (!being_edited || (c1 && c2)) { > Geom::Coord const dist = Geom::distance(sp_doc, p_doc); > + std::cout << " dist -> " << dist << std::endl; > if (dist < getSnapperTolerance()) { > isr.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); > } > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2dcopy2 > _______________________________________________ > Lib2geom-devel mailing list > Lib2geom-devel@... > https://lists.sourceforge.net/lists/listinfo/lib2geom-devel ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Diederik van Lierop - 2011-09-23 19:17:24 ```Thanks Nathan for your help, that is much appreciated. ... and of course it's always good to hear that it isn't something trivial ;-) Diederik ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Nathan Hurst - 2011-09-23 20:59:06 ```On Fri, Sep 23, 2011 at 09:17:06PM +0200, Diederik van Lierop wrote: > Thanks Nathan for your help, that is much appreciated. > > ... and of course it's always good to hear that it isn't something > trivial ;-) roots is definitely misbehaving, I improved its behaviour dramatically by deflating out roots at 0 when they are detected. Now to generalise this approach to all roots. That is not to say that there aren't other edge cases in things like nearest point. njh ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Johan Engelen - 2011-12-19 21:58:20 ```On 23-9-2011 22:59, Nathan Hurst wrote: > On Fri, Sep 23, 2011 at 09:17:06PM +0200, Diederik van Lierop wrote: >> Thanks Nathan for your help, that is much appreciated. >> >> ... and of course it's always good to hear that it isn't something >> trivial ;-) > > roots is definitely misbehaving, I improved its behaviour dramatically > by deflating out roots at 0 when they are detected. Now to generalise > this approach to all roots. That is not to say that there aren't > other edge cases in things like nearest point. Nice that you fixed some issues in trunk Nathan! Is it safe for me to update Inkscape's copy? Thanks, Johan ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Johan Engelen - 2012-01-04 18:19:08 ```Inkscape's 2geom copy is now updated. Hope you can continue you snapping work Diederik! Ciao, Johan On 19-12-2011 22:58, Johan Engelen wrote: > On 23-9-2011 22:59, Nathan Hurst wrote: >> On Fri, Sep 23, 2011 at 09:17:06PM +0200, Diederik van Lierop wrote: >>> Thanks Nathan for your help, that is much appreciated. >>> >>> ... and of course it's always good to hear that it isn't something >>> trivial ;-) >> >> roots is definitely misbehaving, I improved its behaviour dramatically >> by deflating out roots at 0 when they are detected. Now to generalise >> this approach to all roots. That is not to say that there aren't >> other edge cases in things like nearest point. > > Nice that you fixed some issues in trunk Nathan! > Is it safe for me to update Inkscape's copy? ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Johan Engelen - 2011-12-29 20:16:55 ```Hi Nathan, Seems you have forgotten to commit "solve-bezier-convex-hull.cpp"! :) Ciao, Johan On 19-12-2011 22:58, Johan Engelen wrote: > On 23-9-2011 22:59, Nathan Hurst wrote: >> On Fri, Sep 23, 2011 at 09:17:06PM +0200, Diederik van Lierop wrote: >>> Thanks Nathan for your help, that is much appreciated. >>> >>> ... and of course it's always good to hear that it isn't something >>> trivial ;-) >> >> roots is definitely misbehaving, I improved its behaviour dramatically >> by deflating out roots at 0 when they are detected. Now to generalise >> this approach to all roots. That is not to say that there aren't >> other edge cases in things like nearest point. > > Nice that you fixed some issues in trunk Nathan! > Is it safe for me to update Inkscape's copy? > > Thanks, > Johan > > ------------------------------------------------------------------------------ > Write once. Port to many. > Get the SDK and tools to simplify cross-platform app development. Create > new or port existing apps to sell to consumers worldwide. Explore the > Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > http://p.sf.net/sfu/intel-appdev > _______________________________________________ > Lib2geom-devel mailing list > Lib2geom-devel@... > https://lists.sourceforge.net/lists/listinfo/lib2geom-devel > ```
 Re: [Lib2geom-devel] Bug in nearest-point? From: Nathan Hurst - 2011-12-29 22:13:03 ```On Thu, Dec 29, 2011 at 09:16:49PM +0100, Johan Engelen wrote: > Hi Nathan, > Seems you have forgotten to commit "solve-bezier-convex-hull.cpp"! I don't think it's actually used, but I've commited it. It was an implementation of the left bounded convex hull algorithm (which is claimed to be more robust with multiple roots, but I did not find this to be true, at least without using special fp rounding modes). I also added the far more important testing.h file which would allow you to build the newly added tests. I'm working on complete coverage with this testing stuff, but it's slow going given I have to modify the code on a machine in a different city over ssh. njh > :) > Ciao, > Johan > > > On 19-12-2011 22:58, Johan Engelen wrote: > >On 23-9-2011 22:59, Nathan Hurst wrote: > >>On Fri, Sep 23, 2011 at 09:17:06PM +0200, Diederik van Lierop wrote: > >>>Thanks Nathan for your help, that is much appreciated. > >>> > >>>... and of course it's always good to hear that it isn't something > >>>trivial ;-) > >> > >>roots is definitely misbehaving, I improved its behaviour dramatically > >>by deflating out roots at 0 when they are detected. Now to generalise > >>this approach to all roots. That is not to say that there aren't > >>other edge cases in things like nearest point. > > > >Nice that you fixed some issues in trunk Nathan! > >Is it safe for me to update Inkscape's copy? > > > >Thanks, > > Johan > > > >------------------------------------------------------------------------------ > >Write once. Port to many. > >Get the SDK and tools to simplify cross-platform app development. Create > >new or port existing apps to sell to consumers worldwide. Explore the > >Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > >http://p.sf.net/sfu/intel-appdev > >_______________________________________________ > >Lib2geom-devel mailing list > >Lib2geom-devel@... > >https://lists.sourceforge.net/lists/listinfo/lib2geom-devel > > ```