From: Nathan H. <nj...@nj...> - 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. <br> 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<SBasis> 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<SBasis> 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<SBasis> > 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<double> 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<Path>::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<TemporaryItem *>::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<TemporaryItem *> _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<SnapCandidatePath >::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<double> anp = (*it_pv).nearestPointPerCurve(p_doc); > > + std::cout << "#nearest points = " << anp.size() << " | p = " << p.getPoint() << std::endl; > std::vector<double>::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 > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/lib2geom-devel |