X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flivarot%2FPathCutting.cpp;h=4a5aec0f5e8029c314cb537eb87813639a7efa33;hb=8a5980eb24d85fa8e2acc0b7743c94a5a0bcd737;hp=276c9b260f4796b6a0ec8e9642e6a3153fdb36e9;hpb=f37c2ba07ce3334d6bb92969761b7783ec131269;p=inkscape.git diff --git a/src/livarot/PathCutting.cpp b/src/livarot/PathCutting.cpp index 276c9b260..4a5aec0f5 100644 --- a/src/livarot/PathCutting.cpp +++ b/src/livarot/PathCutting.cpp @@ -13,11 +13,25 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include +#include +#include #include "Path.h" #include "style.h" #include "livarot/path-description.h" -#include "libnr/n-art-bpath.h" #include "libnr/nr-point-matrix-ops.h" +#include "libnr/nr-convert2geom.h" +#include <2geom/pathvector.h> +#include <2geom/point.h> +#include <2geom/matrix.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/curves.h> +#include "../display/canvas-bpath.h" +#include "helper/geom-curves.h" +#include "helper/geom.h" + +#include "svg/svg.h" void Path::DashPolyline(float head,float tail,float body,int nbD,float *dashs,bool stPlain,float stOffset) { @@ -25,11 +39,11 @@ void Path::DashPolyline(float head,float tail,float body,int nbD,float *dashs,b std::vector orig_pts = pts; pts.clear(); - + int lastMI=-1; int curP = 0; int lastMP = -1; - + for (int i = 0; i < int(orig_pts.size()); i++) { if ( orig_pts[curP].isMoveTo == polyline_moveto ) { if ( lastMI >= 0 && lastMI < i-1 ) { // au moins 2 points @@ -82,12 +96,12 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt if ( spL <= 0 || spP == -1 ) return; double totLength=0; - NR::Point lastP; + Geom::Point lastP; lastP = orig_pts[spP].p; for (int i=1;i 0.0001 ) { totLength+=nl; lastP=n; @@ -104,7 +118,7 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt int lastPiece=-1; lastP = orig_pts[spP].p; for (int i=1;i const &orig_pt } else { n = orig_pts[spP + i].p; } - NR::Point d=n-lastP; - double nl=NR::L2(d); + Geom::Point d=n-lastP; + double nl=Geom::L2(d); if ( nl > 0.0001 ) { double stLength=curLength; double enLength=curLength+nl; @@ -136,7 +150,7 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt } } if ( nPlain == true && dashPlain == false ) { - NR::Point p=(enLength-curLength)*lastP+(curLength-stLength)*n; + Geom::Point p=(enLength-curLength)*lastP+(curLength-stLength)*n; p/=(enLength-stLength); if ( back ) { double pT=0; @@ -174,7 +188,7 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt nPlain=dashPlain; } if ( nPlain == true && dashPlain == false ) { - NR::Point p=(enLength-curLength-leftInDash)*lastP+(curLength+leftInDash-stLength)*n; + Geom::Point p=(enLength-curLength-leftInDash)*lastP+(curLength+leftInDash-stLength)*n; p/=(enLength-stLength); if ( back ) { double pT=0; @@ -188,7 +202,7 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt AddPoint(p,true); } } else if ( nPlain == false && dashPlain == true ) { - NR::Point p=(enLength-curLength-leftInDash)*lastP+(curLength+leftInDash-stLength)*n; + Geom::Point p=(enLength-curLength-leftInDash)*lastP+(curLength+leftInDash-stLength)*n; p/=(enLength-stLength); if ( back ) { double pT=0; @@ -228,7 +242,7 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt bool nPlain=false; if ( nPlain == true && dashPlain == false ) { } else if ( nPlain == false && dashPlain == true ) { - NR::Point p=(enLength-curLength)*lastP+(curLength-stLength)*n; + Geom::Point p=(enLength-curLength)*lastP+(curLength-stLength)*n; p/=(enLength-stLength); if ( back ) { double pT=0; @@ -252,224 +266,211 @@ void Path::DashSubPath(int spL, int spP, std::vector const &orig_pt } } } -#include "../display/canvas-bpath.h" -void* Path::MakeArtBPath(void) +Geom::PathVector * +Path::MakePathVector() { - int nb_cmd=0,max_cmd=0; - NArtBpath* bpath=(NArtBpath*)g_malloc((max_cmd+1)*sizeof(NArtBpath)); - - NR::Point lastP,bezSt,bezEn,lastMP; - int lastM=-1,bezNb=0; - for (int i=0;igetType(); - switch ( typ ) { - case descr_close: - { - if ( lastM >= 0 ) { - bpath[lastM].code=NR_MOVETO; - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - bpath[nb_cmd].code=NR_LINETO; - bpath[nb_cmd].x3=lastMP[0]; - bpath[nb_cmd].y3=lastMP[1]; - nb_cmd++; - } - lastM=-1; - } - break; - case descr_lineto: - { - PathDescrLineTo *nData = dynamic_cast(descr_cmd[i]); - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - bpath[nb_cmd].code=NR_LINETO; - bpath[nb_cmd].x3=nData->p[0]; - bpath[nb_cmd].y3=nData->p[1]; - nb_cmd++; - lastP=nData->p; - } - break; - case descr_moveto: - { - PathDescrMoveTo *nData = dynamic_cast(descr_cmd[i]); - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - bpath[nb_cmd].code=NR_MOVETO_OPEN; - bpath[nb_cmd].x3=nData->p[0]; - bpath[nb_cmd].y3=nData->p[1]; - lastM=nb_cmd; - nb_cmd++; - lastP=lastMP=nData->p; - } - break; - case descr_arcto: - { - PathDescrArcTo *nData = dynamic_cast(descr_cmd[i]); - lastP=nData->p; - } - break; - case descr_cubicto: - { - PathDescrCubicTo *nData = dynamic_cast(descr_cmd[i]); - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - bpath[nb_cmd].code=NR_CURVETO; - bpath[nb_cmd].x1=lastP[0]+0.333333*nData->start[0]; - bpath[nb_cmd].y1=lastP[1]+0.333333*nData->start[1]; - bpath[nb_cmd].x2=nData->p[0]-0.333333*nData->end[0]; - bpath[nb_cmd].y2=nData->p[1]-0.333333*nData->end[1]; - bpath[nb_cmd].x3=nData->p[0]; - bpath[nb_cmd].y3=nData->p[1]; - nb_cmd++; - lastP=nData->p; - } - break; - case descr_bezierto: - { - PathDescrBezierTo *nData = dynamic_cast(descr_cmd[i]); - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - if ( nData->nb <= 0 ) { - bpath[nb_cmd].code=NR_LINETO; - bpath[nb_cmd].x3=nData->p[0]; - bpath[nb_cmd].y3=nData->p[1]; - nb_cmd++; - bezNb=0; - } else if ( nData->nb == 1 ){ - PathDescrIntermBezierTo *iData = dynamic_cast(descr_cmd[i+1]); - bpath[nb_cmd].code=NR_CURVETO; - bpath[nb_cmd].x1=0.333333*(lastP[0]+2*iData->p[0]); - bpath[nb_cmd].y1=0.333333*(lastP[1]+2*iData->p[1]); - bpath[nb_cmd].x2=0.333333*(nData->p[0]+2*iData->p[0]); - bpath[nb_cmd].y2=0.333333*(nData->p[1]+2*iData->p[1]); - bpath[nb_cmd].x3=nData->p[0]; - bpath[nb_cmd].y3=nData->p[1]; - nb_cmd++; - bezNb=0; - } else { - bezSt=2*lastP-nData->p; - bezEn=nData->p; - bezNb=nData->nb; - } - lastP=nData->p; - } - break; - case descr_interm_bezier: - { - if ( bezNb > 0 ) { - PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[i]); - NR::Point p_m=nData->p,p_s=0.5*(bezSt+p_m),p_e; - if ( bezNb > 1 ) { - PathDescrIntermBezierTo *iData = dynamic_cast(descr_cmd[i+1]); - p_e=0.5*(p_m+iData->p); - } else { - p_e=bezEn; - } - - if ( nb_cmd >= max_cmd ) { - max_cmd=2*nb_cmd+1; - bpath=(NArtBpath*)g_realloc(bpath,(max_cmd+1)*sizeof(NArtBpath)); - } - bpath[nb_cmd].code=NR_CURVETO; - NR::Point cp1=0.333333*(p_s+2*p_m),cp2=0.333333*(2*p_m+p_e); - bpath[nb_cmd].x1=cp1[0]; - bpath[nb_cmd].y1=cp1[1]; - bpath[nb_cmd].x2=cp2[0]; - bpath[nb_cmd].y2=cp2[1]; - bpath[nb_cmd].x3=p_e[0]; - bpath[nb_cmd].y3=p_e[1]; - nb_cmd++; - - bezNb--; - } - } - break; + Geom::PathVector *pv = new Geom::PathVector(); + Geom::Path * currentpath = NULL; + + Geom::Point lastP,bezSt,bezEn; + int bezNb=0; + for (int i=0;igetType(); + switch ( typ ) { + case descr_close: + { + currentpath->close(true); + } + break; + + case descr_lineto: + { + PathDescrLineTo *nData = dynamic_cast(descr_cmd[i]); + currentpath->appendNew(Geom::Point(nData->p[0], nData->p[1])); + lastP = nData->p; + } + break; + + case descr_moveto: + { + PathDescrMoveTo *nData = dynamic_cast(descr_cmd[i]); + pv->push_back(Geom::Path()); + currentpath = &pv->back(); + currentpath->start(Geom::Point(nData->p[0], nData->p[1])); + lastP = nData->p; + } + break; + + case descr_arcto: + { + /* TODO: add testcase for this descr_arcto case */ + PathDescrArcTo *nData = dynamic_cast(descr_cmd[i]); + currentpath->appendNew( nData->rx, nData->ry, nData->angle, nData->large, !nData->clockwise, nData->p ); + lastP = nData->p; + } + break; + + case descr_cubicto: + { + PathDescrCubicTo *nData = dynamic_cast(descr_cmd[i]); + gdouble x1=lastP[0]+0.333333*nData->start[0]; + gdouble y1=lastP[1]+0.333333*nData->start[1]; + gdouble x2=nData->p[0]-0.333333*nData->end[0]; + gdouble y2=nData->p[1]-0.333333*nData->end[1]; + gdouble x3=nData->p[0]; + gdouble y3=nData->p[1]; + currentpath->appendNew( Geom::Point(x1,y1) , Geom::Point(x2,y2) , Geom::Point(x3,y3) ); + lastP = nData->p; + } + break; + + case descr_bezierto: + { + PathDescrBezierTo *nData = dynamic_cast(descr_cmd[i]); + if ( nData->nb <= 0 ) { + currentpath->appendNew( Geom::Point(nData->p[0], nData->p[1]) ); + bezNb=0; + } else if ( nData->nb == 1 ){ + PathDescrIntermBezierTo *iData = dynamic_cast(descr_cmd[i+1]); + gdouble x1=0.333333*(lastP[0]+2*iData->p[0]); + gdouble y1=0.333333*(lastP[1]+2*iData->p[1]); + gdouble x2=0.333333*(nData->p[0]+2*iData->p[0]); + gdouble y2=0.333333*(nData->p[1]+2*iData->p[1]); + gdouble x3=nData->p[0]; + gdouble y3=nData->p[1]; + currentpath->appendNew( Geom::Point(x1,y1) , Geom::Point(x2,y2) , Geom::Point(x3,y3) ); + bezNb=0; + } else { + bezSt = 2*lastP-nData->p; + bezEn = nData->p; + bezNb = nData->nb; + } + lastP = nData->p; + } + break; + + case descr_interm_bezier: + { + if ( bezNb > 0 ) { + PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[i]); + Geom::Point p_m=nData->p,p_s=0.5*(bezSt+p_m),p_e; + if ( bezNb > 1 ) { + PathDescrIntermBezierTo *iData = dynamic_cast(descr_cmd[i+1]); + p_e=0.5*(p_m+iData->p); + } else { + p_e=bezEn; + } + + Geom::Point cp1=0.333333*(p_s+2*p_m),cp2=0.333333*(2*p_m+p_e); + gdouble x1=cp1[0]; + gdouble y1=cp1[1]; + gdouble x2=cp2[0]; + gdouble y2=cp2[1]; + gdouble x3=p_e[0]; + gdouble y3=p_e[1]; + currentpath->appendNew( Geom::Point(x1,y1) , Geom::Point(x2,y2) , Geom::Point(x3,y3) ); + + bezNb--; + } + } + break; + } } - } - bpath[nb_cmd].code=NR_END; - return bpath; + + return pv; } -void Path::LoadArtBPath(void *iV,NR::Matrix const &trans,bool doTransformation) +void Path::AddCurve(Geom::Curve const &c) { - if ( iV == NULL ) return; - NArtBpath *bpath = (NArtBpath*)iV; - - SetBackData (false); - Reset(); - { - int i; - bool closed = false; - NR::Point lastX(0,0); - - for (i = 0; bpath[i].code != NR_END; i++) + if( is_straight_curve(c) ) { - switch (bpath[i].code) - { - case NR_LINETO: - lastX[0] = bpath[i].x3; - lastX[1] = bpath[i].y3; - if ( doTransformation ) { - lastX*=trans; - } - LineTo (lastX); - break; - - case NR_CURVETO: - { - NR::Point tmp,tms(0,0),tme(0,0),tm1,tm2; - tmp[0]=bpath[i].x3; - tmp[1]=bpath[i].y3; - tm1[0]=bpath[i].x1; - tm1[1]=bpath[i].y1; - tm2[0]=bpath[i].x2; - tm2[1]=bpath[i].y2; - if ( doTransformation ) { - tmp*=trans; - tm1*=trans; - tm2*=trans; - } - tms=3 * (tm1 - lastX); - tme=3 * (tmp - tm2); - CubicTo (tmp,tms,tme); + LineTo( c.finalPoint() ); + } + /* + else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(c)) { + ... + } + */ + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { + Geom::Point tmp = (*cubic_bezier)[3]; + Geom::Point tms = 3 * ((*cubic_bezier)[1] - (*cubic_bezier)[0]); + Geom::Point tme = 3 * ((*cubic_bezier)[3] - (*cubic_bezier)[2]); + CubicTo (tmp, tms, tme); + } + else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast(&c)) { + ArcTo( svg_elliptical_arc->finalPoint(), + svg_elliptical_arc->ray(0), svg_elliptical_arc->ray(1), + svg_elliptical_arc->rotation_angle(), /// \todo check that this parameter is in radians (rotation_angle returns the angle in radians!) + svg_elliptical_arc->large_arc_flag(), !svg_elliptical_arc->sweep_flag() ); + } else { + //this case handles sbasis as well as all other curve types + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1); + + //recurse to convert the new path resulting from the sbasis to svgd + for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { + AddCurve(*iter); } - lastX[0] = bpath[i].x3; - lastX[1] = bpath[i].y3; - if ( doTransformation ) { - lastX*=trans; - } - break; - - case NR_MOVETO_OPEN: - case NR_MOVETO: - if (closed) Close (); - closed = (bpath[i].code == NR_MOVETO); - lastX[0] = bpath[i].x3; - lastX[1] = bpath[i].y3; - if ( doTransformation ) { - lastX*=trans; - } - MoveTo (lastX); - break; - default: - break; - } } - if (closed) Close (); - } } +/** append is false by default: it means that the path should be resetted. If it is true, the path is not resetted and Geom::Path will be appended as a new path + */ +void Path::LoadPath(Geom::Path const &path, Geom::Matrix const &tr, bool doTransformation, bool append) +{ + if (!append) { + SetBackData (false); + Reset(); + } + if (path.empty()) + return; + + // TODO: this can be optimized by not generating a new path here, but doing the transform in AddCurve + // directly on the curve parameters + + Geom::Path const pathtr = doTransformation ? path * tr : path; + + MoveTo( pathtr.initialPoint() ); + + for(Geom::Path::const_iterator cit = pathtr.begin(); cit != pathtr.end_open(); ++cit) { + AddCurve(*cit); + } + + if (pathtr.closed()) { + // check if closing segment is empty before adding it + Geom::Curve const &crv = pathtr.back_closed(); + if ( !crv.isDegenerate() ) { + AddCurve(crv); + } + + Close(); + } +} + +void Path::LoadPathVector(Geom::PathVector const &pv) +{ + LoadPathVector(pv, Geom::Matrix(), false); +} + +void Path::LoadPathVector(Geom::PathVector const &pv, Geom::Matrix const &tr, bool doTransformation) +{ + SetBackData (false); + Reset(); + + // FIXME: 2geom is currently unable to maintain SVGElliptical arcs through transformation, and + // sometimes it crashes on a continuity error during conversions, therefore convert to beziers here. + // (the fix is of course to fix 2geom and then remove this if-statement, and just execute the 'else'-clause) + if (doTransformation) { + Geom::PathVector pvbezier = pathv_to_linear_and_cubic_beziers(pv); + for(Geom::PathVector::const_iterator it = pvbezier.begin(); it != pvbezier.end(); ++it) { + LoadPath(*it, tr, doTransformation, true); + } + } else { + for(Geom::PathVector::const_iterator it = pv.begin(); it != pv.end(); ++it) { + LoadPath(*it, tr, doTransformation, true); + } + } +} /** * \return Length of the lines in the pts vector. @@ -481,13 +482,13 @@ double Path::Length() return 0; } - NR::Point lastP = pts[0].p; + Geom::Point lastP = pts[0].p; double len = 0; for (std::vector::const_iterator i = pts.begin(); i != pts.end(); i++) { if ( i->isMoveTo != polyline_moveto ) { - len += NR::L2(i->p - lastP); + len += Geom::L2(i->p - lastP); } lastP = i->p; @@ -503,8 +504,8 @@ double Path::Surface() return 0; } - NR::Point lastM = pts[0].p; - NR::Point lastP = lastM; + Geom::Point lastM = pts[0].p; + Geom::Point lastP = lastM; double surf = 0; for (std::vector::const_iterator i = pts.begin(); i != pts.end(); i++) { @@ -742,11 +743,11 @@ void Path::ConvertForcedToVoid() void Path::ConvertForcedToMoveTo() { - NR::Point lastSeen(0, 0); - NR::Point lastMove(0, 0); + Geom::Point lastSeen(0, 0); + Geom::Point lastMove(0, 0); { - NR::Point lastPos(0, 0); + Geom::Point lastPos(0, 0); for (int i = int(descr_cmd.size()) - 1; i >= 0; i--) { int const typ = descr_cmd[i]->getType(); switch ( typ ) { @@ -899,8 +900,8 @@ Path::cut_position* Path::CurvilignToPosition(int nbCv, double *cvAbs, int &nbCu double lastT = 0; int lastPiece = -1; - NR::Point lastM = pts[0].p; - NR::Point lastP = lastM; + Geom::Point lastM = pts[0].p; + Geom::Point lastP = lastM; for (std::vector::const_iterator i = pts.begin(); i != pts.end(); i++) { @@ -912,7 +913,7 @@ Path::cut_position* Path::CurvilignToPosition(int nbCv, double *cvAbs, int &nbCu } else { - double const add = NR::L2(i->p - lastP); + double const add = Geom::L2(i->p - lastP); double curPos = len; double curAdd = add; @@ -947,24 +948,27 @@ hence the Path-esque coding style" */ template inline static T square(T x) {return x*x;} -Path::cut_position Path::PointToCurvilignPosition(NR::Point const &pos) const +Path::cut_position Path::PointToCurvilignPosition(Geom::Point const &pos, unsigned seg) const { + // if the parameter "seg" == 0, then all segments will be considered + // In however e.g. "seg" == 6 , then only the 6th segment will be considered + unsigned bestSeg = 0; double bestRangeSquared = DBL_MAX; double bestT = 0.0; // you need a sentinel, or make sure that you prime with correct values. for (unsigned i = 1 ; i < pts.size() ; i++) { - if (pts[i].isMoveTo == polyline_moveto) continue; - NR::Point p1, p2, localPos; + if (pts[i].isMoveTo == polyline_moveto || (seg > 0 && i != seg)) continue; + Geom::Point p1, p2, localPos; double thisRangeSquared; double t; if (pts[i - 1].p == pts[i].p) { - thisRangeSquared = square(pts[i].p[NR::X] - pos[NR::X]) + square(pts[i].p[NR::Y] - pos[NR::Y]); + thisRangeSquared = square(pts[i].p[Geom::X] - pos[Geom::X]) + square(pts[i].p[Geom::Y] - pos[Geom::Y]); t = 0.0; } else { // we rotate all our coordinates so we're always looking at a mostly vertical line. - if (fabs(pts[i - 1].p[NR::X] - pts[i].p[NR::X]) < fabs(pts[i - 1].p[NR::Y] - pts[i].p[NR::Y])) { + if (fabs(pts[i - 1].p[Geom::X] - pts[i].p[Geom::X]) < fabs(pts[i - 1].p[Geom::Y] - pts[i].p[Geom::Y])) { p1 = pts[i - 1].p; p2 = pts[i].p; localPos = pos; @@ -973,32 +977,32 @@ Path::cut_position Path::PointToCurvilignPosition(NR::Point const &pos) const p2 = pts[i].p.cw(); localPos = pos.cw(); } - double gradient = (p2[NR::X] - p1[NR::X]) / (p2[NR::Y] - p1[NR::Y]); - double intersection = p1[NR::X] - gradient * p1[NR::Y]; + double gradient = (p2[Geom::X] - p1[Geom::X]) / (p2[Geom::Y] - p1[Geom::Y]); + double intersection = p1[Geom::X] - gradient * p1[Geom::Y]; /* orthogonalGradient = -1.0 / gradient; // you are going to have numerical problems here. - orthogonalIntersection = localPos[NR::X] - orthogonalGradient * localPos[NR::Y]; + orthogonalIntersection = localPos[Geom::X] - orthogonalGradient * localPos[Geom::Y]; nearestY = (orthogonalIntersection - intersection) / (gradient - orthogonalGradient); expand out nearestY fully : - nearestY = (localPos[NR::X] - (-1.0 / gradient) * localPos[NR::Y] - intersection) / (gradient - (-1.0 / gradient)); + nearestY = (localPos[Geom::X] - (-1.0 / gradient) * localPos[Geom::Y] - intersection) / (gradient - (-1.0 / gradient)); multiply top and bottom by gradient: - nearestY = (localPos[NR::X] * gradient - (-1.0) * localPos[NR::Y] - intersection * gradient) / (gradient * gradient - (-1.0)); + nearestY = (localPos[Geom::X] * gradient - (-1.0) * localPos[Geom::Y] - intersection * gradient) / (gradient * gradient - (-1.0)); and simplify to get: */ - double nearestY = (localPos[NR::X] * gradient + localPos[NR::Y] - intersection * gradient) + double nearestY = (localPos[Geom::X] * gradient + localPos[Geom::Y] - intersection * gradient) / (gradient * gradient + 1.0); - t = (nearestY - p1[NR::Y]) / (p2[NR::Y] - p1[NR::Y]); + t = (nearestY - p1[Geom::Y]) / (p2[Geom::Y] - p1[Geom::Y]); if (t <= 0.0) { - thisRangeSquared = square(p1[NR::X] - localPos[NR::X]) + square(p1[NR::Y] - localPos[NR::Y]); + thisRangeSquared = square(p1[Geom::X] - localPos[Geom::X]) + square(p1[Geom::Y] - localPos[Geom::Y]); t = 0.0; } else if (t >= 1.0) { - thisRangeSquared = square(p2[NR::X] - localPos[NR::X]) + square(p2[NR::Y] - localPos[NR::Y]); + thisRangeSquared = square(p2[Geom::X] - localPos[Geom::X]) + square(p2[Geom::Y] - localPos[Geom::Y]); t = 1.0; } else { - thisRangeSquared = square(nearestY * gradient + intersection - localPos[NR::X]) + square(nearestY - localPos[NR::Y]); + thisRangeSquared = square(nearestY * gradient + intersection - localPos[Geom::X]) + square(nearestY - localPos[Geom::Y]); } } @@ -1036,10 +1040,10 @@ double Path::PositionToLength(int piece, double t) for (unsigned i = 1 ; i < pts.size() ; i++) { if (pts[i].isMoveTo == polyline_moveto) continue; if (pts[i].piece == piece && t < pts[i].t) { - length += NR::L2((t - pts[i - 1].t) / (pts[i].t - pts[i - 1].t) * (pts[i].p - pts[i - 1].p)); + length += Geom::L2((t - pts[i - 1].t) / (pts[i].t - pts[i - 1].t) * (pts[i].p - pts[i - 1].p)); break; } - length += NR::L2(pts[i].p - pts[i - 1].p); + length += Geom::L2(pts[i].p - pts[i - 1].p); } return length; } @@ -1051,7 +1055,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) } { - NR::Point lastPos(0, 0); + Geom::Point lastPos(0, 0); for (int i = int(descr_cmd.size()) - 1; i >= 0; i--) { int const typ = descr_cmd[i]->getType(); switch ( typ ) { @@ -1066,7 +1070,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) case descr_close: { delete descr_cmd[i]; - descr_cmd[i] = new PathDescrLineTo(NR::Point(0, 0)); + descr_cmd[i] = new PathDescrLineTo(Geom::Point(0, 0)); int fp = i - 1; while ( fp >= 0 && (descr_cmd[fp]->getType()) != descr_moveto ) { @@ -1083,7 +1087,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) case descr_bezierto: { PathDescrBezierTo *nData = dynamic_cast(descr_cmd[i]); - NR::Point theP = nData->p; + Geom::Point theP = nData->p; if ( nData->nb == 0 ) { lastPos = theP; } @@ -1140,13 +1144,13 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) // ponctuel= rien a faire } else if ( typ == descr_lineto || typ == descr_arcto || typ == descr_cubicto ) { // facile: creation d'un morceau et d'un forced -> 2 commandes - NR::Point theP; - NR::Point theT; - NR::Point startP; + Geom::Point theP; + Geom::Point theT; + Geom::Point startP; startP=PrevPoint(cp-1); if ( typ == descr_cubicto ) { double len,rad; - NR::Point stD,enD,endP; + Geom::Point stD,enD,endP; { PathDescrCubicTo *oData = dynamic_cast(descr_cmd[cp]); stD=oData->start; @@ -1175,7 +1179,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) } } } else if ( typ == descr_lineto ) { - NR::Point endP; + Geom::Point endP; { PathDescrLineTo *oData = dynamic_cast(descr_cmd[cp]); endP=oData->p; @@ -1199,7 +1203,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) } } } else if ( typ == descr_arcto ) { - NR::Point endP; + Geom::Point endP; double rx,ry,angle; bool clockw,large; double delta=0; @@ -1261,17 +1265,17 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) PathDescrBezierTo theBD=*(dynamic_cast(descr_cmd[theBDI])); if ( cp >= theBDI && cp < theBDI+theBD.nb ) { if ( theBD.nb == 1 ) { - NR::Point endP=theBD.p; - NR::Point midP; - NR::Point startP; + Geom::Point endP=theBD.p; + Geom::Point midP; + Geom::Point startP; startP=PrevPoint(theBDI-1); { PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[theBDI+1]); midP=nData->p; } - NR::Point aP=ct*midP+(1-ct)*startP; - NR::Point bP=ct*endP+(1-ct)*midP; - NR::Point knotP=ct*bP+(1-ct)*aP; + Geom::Point aP=ct*midP+(1-ct)*startP; + Geom::Point bP=ct*endP+(1-ct)*midP; + Geom::Point knotP=ct*bP+(1-ct)*aP; InsertIntermBezierTo(bP,theBDI+2); InsertBezierTo(knotP,1,theBDI+2); @@ -1297,7 +1301,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) } else { // decouper puis repasser if ( cp > theBDI ) { - NR::Point pcP,ncP; + Geom::Point pcP,ncP; { PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[cp]); pcP=nData->p; @@ -1306,7 +1310,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[cp+1]); ncP=nData->p; } - NR::Point knotP=0.5*(pcP+ncP); + Geom::Point knotP=0.5*(pcP+ncP); InsertBezierTo(knotP,theBD.nb-(cp-theBDI),cp+1); { @@ -1324,7 +1328,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) } curP--; } else { - NR::Point pcP,ncP; + Geom::Point pcP,ncP; { PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[cp+1]); pcP=nData->p; @@ -1333,7 +1337,7 @@ void Path::ConvertPositionsToForced(int nbPos, cut_position *poss) PathDescrIntermBezierTo *nData = dynamic_cast(descr_cmd[cp+2]); ncP=nData->p; } - NR::Point knotP=0.5*(pcP+ncP); + Geom::Point knotP=0.5*(pcP+ncP); InsertBezierTo(knotP,theBD.nb-1,cp+2); { @@ -1370,16 +1374,16 @@ void Path::ConvertPositionsToMoveTo(int nbPos,cut_position* poss) Path* res=new Path; - NR::Point lastP(0,0); + Geom::Point lastP(0,0); for (int i=0;igetType(); if ( typ == descr_moveto ) { - NR::Point np; + Geom::Point np; { PathDescrMoveTo *nData = dynamic_cast(descr_cmd[i]); np=nData->p; } - NR::Point endP; + Geom::Point endP; bool hasClose=false; int hasForced=-1; bool doesClose=false; @@ -1409,15 +1413,15 @@ void Path::ConvertPositionsToMoveTo(int nbPos,cut_position* poss) } else { } } - if ( NR::LInfty(endP-np) < 0.00001 ) { + if ( Geom::LInfty(endP-np) < 0.00001 ) { doesClose=true; } if ( ( doesClose || hasClose ) && hasForced >= 0 ) { // printf("nasty i=%i j=%i frc=%i\n",i,j,hasForced); // aghhh. - NR::Point nMvtP=PrevPoint(hasForced); + Geom::Point nMvtP=PrevPoint(hasForced); res->MoveTo(nMvtP); - NR::Point nLastP=nMvtP; + Geom::Point nLastP=nMvtP; for (int k = hasForced + 1; k < j; k++) { int ntyp=descr_cmd[k]->getType(); if ( ntyp == descr_moveto ) {