From a2377f88de39790b2324a846f9e619d78d399afc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 10 Nov 2014 22:35:13 +0100 Subject: adding blending support (bzr r13682.1.1) --- src/live_effects/effect.cpp | 2 +- src/live_effects/lpe-mirror_symmetry.cpp | 102 ++++++++++++++++++++++++++----- src/live_effects/lpe-mirror_symmetry.h | 5 +- 3 files changed, 93 insertions(+), 16 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index fbdc78f8a..9433dec7f 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -106,7 +106,6 @@ const Util::EnumData LPETypeData[] = { {EXTRUDE, N_("Extrude"), "extrude"}, {LATTICE, N_("Lattice Deformation"), "lattice"}, {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, - {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {OFFSET, N_("Offset"), "offset"}, {PARALLEL, N_("Parallel"), "parallel"}, {PATH_LENGTH, N_("Path length"), "path_length"}, @@ -153,6 +152,7 @@ const Util::EnumData LPETypeData[] = { {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, + {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 0bb67a4a2..8877ffd9c 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -21,6 +21,7 @@ #include #include <2geom/path.h> +#include <2geom/path-intersection.h> #include <2geom/transforms.h> #include <2geom/affine.h> @@ -30,11 +31,13 @@ namespace LivePathEffect { LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100") + joinPaths(_("Join the paths"), _("Join the resulting paths"), "joinPaths", &wr, this, true), + reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0") { show_orig_path = true; registerParameter( dynamic_cast(&discard_orig_path) ); + registerParameter( dynamic_cast(&joinPaths) ); registerParameter( dynamic_cast(&reflection_line) ); } @@ -55,15 +58,10 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { using namespace Geom; - // fixme: what happens if the bbox is empty? - // fixme: this is probably wrong - Geom::Affine t = lpeitem->i2dt_affine(); - Geom::Rect bbox = *lpeitem->desktopVisualBounds(); + original_bbox(lpeitem); - Point A(bbox.left(), bbox.bottom()); - Point B(bbox.left(), bbox.top()); - A *= t; - B *= t; + Point A(boundingbox_X.max(), boundingbox_Y.max()); + Point B(boundingbox_X.max(), boundingbox_Y.min()); Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); reflection_line.set_new_value(rline, true); } @@ -77,11 +75,12 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) } std::vector path_out; - if (!discard_orig_path) { + std::vector mline(reflection_line.get_pathvector()); + + if (!discard_orig_path && !joinPaths) { path_out = path_in; } - std::vector mline(reflection_line.get_pathvector()); Geom::Point A(mline.front().initialPoint()); Geom::Point B(mline.back().finalPoint()); @@ -97,9 +96,84 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) m = m * sca; m = m * m2.inverse(); m = m * m1; - - for (int i = 0; i < static_cast(path_in.size()); ++i) { - path_out.push_back(path_in[i] * m); + + if(joinPaths){ + for (Geom::PathVector::const_iterator path_it = path_in.begin(); + path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + Geom::Path original; + Geom::Path mlineExpanded; + Geom::Line lineSeparation; + lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); + mlineExpanded.start( lineSeparation.pointAt(-100000)); + mlineExpanded.appendNew( lineSeparation.pointAt(100000)); + Geom::Crossings cs = crossings(*path_it, mlineExpanded); + double timeStart = 0.0; + //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line + double pos = (lineSeparation.pointAt(100000)[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X])*(path_it->initialPoint()[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y]) - (lineSeparation.pointAt(100000)[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y])*(path_it->initialPoint()[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X]); + int position = (pos < 0) ? -1 : (pos > 0); + unsigned int counter = 0; + + for(unsigned int i = 0; i < cs.size(); i++) { + double timeEnd = cs[i].ta; + Geom::Path portion = path_it->portion(timeStart, timeEnd); + if(position == -1 && i==0){ + counter++; + } + if(counter%2!=0){ + if (!discard_orig_path){ + if(i==0){ + original = portion; + } else { + original.append(portion, (Geom::Path::Stitching)1); + } + original.append(portion.reverse() * m, (Geom::Path::Stitching)1); + if (!path_it->closed()){ + path_out.push_back(original); + original.clear(); + } + } else { + path_out.push_back(portion * m); + } + } + timeStart = timeEnd; + counter++; + } + if(cs.size()!=0 && ((cs.size()%2 == 0 && position == -1)||(cs.size()%2 != 0 && position == 1))){ + Geom::Path portion = path_it->portion(timeStart, nearest_point(path_it->finalPoint(), *path_it)); + if (!discard_orig_path){ + if(!path_it->closed()){ + original = portion; + } else { + original.append(portion, (Geom::Path::Stitching)1); + } + original.append(portion.reverse() * m, (Geom::Path::Stitching)1); + if (!path_it->closed()){ + path_out.push_back(original); + original.clear(); + } + } else { + path_out.push_back(portion * m); + } + + } + if (path_it->closed() && !original.empty() && !discard_orig_path) { + original.close(); + path_out.push_back(original); + } + if(cs.size() == 0){ + path_out.push_back(*path_it); + path_out.push_back(*path_it * m); + } + } + } + + if (!joinPaths) { + for (int i = 0; i < static_cast(path_in.size()); ++i) { + path_out.push_back(path_in[i] * m); + } } return path_out; diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index a4a2b86c0..2ea8161d4 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -20,10 +20,12 @@ #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" +#include "live_effects/lpegroupbbox.h" + namespace Inkscape { namespace LivePathEffect { -class LPEMirrorSymmetry : public Effect { +class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{ public: LPEMirrorSymmetry(LivePathEffectObject *lpeobject); virtual ~LPEMirrorSymmetry(); @@ -36,6 +38,7 @@ public: private: BoolParam discard_orig_path; + BoolParam joinPaths; PathParam reflection_line; LPEMirrorSymmetry(const LPEMirrorSymmetry&); -- cgit v1.2.3 From fc813d4f7b4adb8e681abdd429bc0d9c19312ea5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 11 Nov 2014 00:45:06 +0100 Subject: added join mode (bzr r13682.1.3) --- src/live_effects/lpe-mirror_symmetry.cpp | 47 ++++++++++---------------------- 1 file changed, 15 insertions(+), 32 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 8877ffd9c..67f4e3f16 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -97,7 +97,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) m = m * m2.inverse(); m = m * m1; - if(joinPaths){ + if(joinPaths && !discard_orig_path){ for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()){ @@ -123,47 +123,30 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) counter++; } if(counter%2!=0){ - if (!discard_orig_path){ - if(i==0){ - original = portion; - } else { - original.append(portion, (Geom::Path::Stitching)1); - } - original.append(portion.reverse() * m, (Geom::Path::Stitching)1); - if (!path_it->closed()){ - path_out.push_back(original); - original.clear(); - } - } else { - path_out.push_back(portion * m); + original = portion; + original.append(portion.reverse() * m, (Geom::Path::Stitching)1); + if(i!=0){ + original.close(); } + path_out.push_back(original); + original.clear(); } timeStart = timeEnd; counter++; } if(cs.size()!=0 && ((cs.size()%2 == 0 && position == -1)||(cs.size()%2 != 0 && position == 1))){ Geom::Path portion = path_it->portion(timeStart, nearest_point(path_it->finalPoint(), *path_it)); - if (!discard_orig_path){ - if(!path_it->closed()){ - original = portion; - } else { - original.append(portion, (Geom::Path::Stitching)1); - } - original.append(portion.reverse() * m, (Geom::Path::Stitching)1); - if (!path_it->closed()){ - path_out.push_back(original); - original.clear(); - } + original = portion.reverse(); + original.append(portion * m, (Geom::Path::Stitching)1); + if (!path_it->closed()){ + path_out.push_back(original); } else { - path_out.push_back(portion * m); + path_out[0].append(original.reverse(), (Geom::Path::Stitching)1); + path_out[0].close(); } - - } - if (path_it->closed() && !original.empty() && !discard_orig_path) { - original.close(); - path_out.push_back(original); + original.clear(); } - if(cs.size() == 0){ + if(cs.size() == 0 && position == -1){ path_out.push_back(*path_it); path_out.push_back(*path_it * m); } -- cgit v1.2.3 From ffad504bec2b31828f6fe10edfab5ec8ef6437fb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 11 Nov 2014 19:59:49 +0100 Subject: Code cleanup (bzr r13682.1.4) --- src/live_effects/lpe-mirror_symmetry.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 67f4e3f16..fa588fe96 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -107,12 +107,14 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) Geom::Path mlineExpanded; Geom::Line lineSeparation; lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); - mlineExpanded.start( lineSeparation.pointAt(-100000)); - mlineExpanded.appendNew( lineSeparation.pointAt(100000)); + Geom::Point lineStart = lineSeparation.pointAt(-100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(100000.0); + mlineExpanded.start( lineStart); + mlineExpanded.appendNew( lineEnd); Geom::Crossings cs = crossings(*path_it, mlineExpanded); double timeStart = 0.0; //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (lineSeparation.pointAt(100000)[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X])*(path_it->initialPoint()[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y]) - (lineSeparation.pointAt(100000)[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y])*(path_it->initialPoint()[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X]); + double pos = (lineEnd[Geom::X]-lineStart[Geom::X])*(path_it->initialPoint()[Geom::Y]-lineStart[Geom::Y]) - (lineEnd[Geom::Y]-lineStart[Geom::Y])*(path_it->initialPoint()[Geom::X]-lineStart[Geom::X]); int position = (pos < 0) ? -1 : (pos > 0); unsigned int counter = 0; -- cgit v1.2.3 From 165025d5aa43570d3905d312632199efddd45c9a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 13 Nov 2014 18:04:22 +0100 Subject: Fixed bugs pointed by su_v. Added inverse option to merges (bzr r13682.1.6) --- src/live_effects/lpe-mirror_symmetry.cpp | 125 +++++++++++++++++++------------ src/live_effects/lpe-mirror_symmetry.h | 6 +- 2 files changed, 84 insertions(+), 47 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index fa588fe96..c21c65a3e 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include "helper/geom.h" #include <2geom/path.h> #include <2geom/path-intersection.h> #include <2geom/transforms.h> @@ -31,13 +31,15 @@ namespace LivePathEffect { LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - joinPaths(_("Join the paths"), _("Join the resulting paths"), "joinPaths", &wr, this, true), + fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), + reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0") { show_orig_path = true; registerParameter( dynamic_cast(&discard_orig_path) ); - registerParameter( dynamic_cast(&joinPaths) ); + registerParameter( dynamic_cast(&fusionPaths) ); + registerParameter( dynamic_cast(&reverseFusion) ); registerParameter( dynamic_cast(&reflection_line) ); } @@ -49,6 +51,8 @@ void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { SPLPEItem * item = const_cast(lpeitem); + std::vector mline(reflection_line.get_pathvector()); + lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -66,6 +70,14 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) reflection_line.set_new_value(rline, true); } +int +LPEMirrorSymmetry::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) +{ + //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line + double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); + return (pos < 0) ? -1 : (pos > 0); +} + std::vector LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) { @@ -73,16 +85,20 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) if ( reflection_line.get_pathvector().empty() ) { return path_in; } - + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); std::vector path_out; - std::vector mline(reflection_line.get_pathvector()); + Geom::Path mlineExpanded; + Geom::Point lineStart = lineSeparation.pointAt(-100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(100000.0); + mlineExpanded.start( lineStart); + mlineExpanded.appendNew( lineEnd); - if (!discard_orig_path && !joinPaths) { + if (!discard_orig_path && !fusionPaths) { path_out = path_in; } - Geom::Point A(mline.front().initialPoint()); - Geom::Point B(mline.back().finalPoint()); + Geom::Point A(lineStart); + Geom::Point B(lineEnd); Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); double hyp = Geom::distance(A, B); @@ -97,65 +113,82 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) m = m * m2.inverse(); m = m * m1; - if(joinPaths && !discard_orig_path){ - for (Geom::PathVector::const_iterator path_it = path_in.begin(); - path_it != path_in.end(); ++path_it) { + if(fusionPaths && !discard_orig_path){ + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); + path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; } - Geom::Path original; - Geom::Path mlineExpanded; - Geom::Line lineSeparation; - lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( lineEnd); - Geom::Crossings cs = crossings(*path_it, mlineExpanded); double timeStart = 0.0; - //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (lineEnd[Geom::X]-lineStart[Geom::X])*(path_it->initialPoint()[Geom::Y]-lineStart[Geom::Y]) - (lineEnd[Geom::Y]-lineStart[Geom::Y])*(path_it->initialPoint()[Geom::X]-lineStart[Geom::X]); - int position = (pos < 0) ? -1 : (pos > 0); - unsigned int counter = 0; - + int position = 0; + bool end_open = false; + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { + end_open = true; + } + } + Geom::Path original = (Geom::Path)(*path_it); + if(end_open && path_it->closed()){ + original.close(false); + original.appendNew( original.initialPoint() ); + original.close(true); + } + Geom::Crossings cs = crossings(original, mlineExpanded); for(unsigned int i = 0; i < cs.size(); i++) { double timeEnd = cs[i].ta; - Geom::Path portion = path_it->portion(timeStart, timeEnd); - if(position == -1 && i==0){ - counter++; + Geom::Path portion = original.portion(timeStart, timeEnd); + Geom::Point middle = portion.pointAt((double)portion.size()/2.0); + position = pointSideOfLine(lineStart, lineEnd, middle); + if(reverseFusion){ + position *= -1; } - if(counter%2!=0){ - original = portion; - original.append(portion.reverse() * m, (Geom::Path::Stitching)1); + if(position == -1){ + Geom::Path mirror = portion.reverse() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); if(i!=0){ - original.close(); + portion.setFinal(portion.initialPoint()); + portion.close(); } - path_out.push_back(original); - original.clear(); + path_out.push_back(portion); } + portion.clear(); timeStart = timeEnd; - counter++; } - if(cs.size()!=0 && ((cs.size()%2 == 0 && position == -1)||(cs.size()%2 != 0 && position == 1))){ - Geom::Path portion = path_it->portion(timeStart, nearest_point(path_it->finalPoint(), *path_it)); - original = portion.reverse(); - original.append(portion * m, (Geom::Path::Stitching)1); - if (!path_it->closed()){ - path_out.push_back(original); + position = pointSideOfLine(lineStart, lineEnd, original.finalPoint()); + if(reverseFusion){ + position *= -1; + } + if(cs.size()!=0 && position == -1){ + Geom::Path portion = original.portion(timeStart, original.size()); + portion = portion.reverse(); + Geom::Path mirror = portion.reverse() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + portion = portion.reverse(); + if (!original.closed()){ + path_out.push_back(portion); } else { - path_out[0].append(original.reverse(), (Geom::Path::Stitching)1); + if(cs.size() >1 ){ + portion.setFinal(path_out[0].initialPoint()); + portion.setInitial(path_out[0].finalPoint()); + path_out[0].append(portion); + } else { + path_out.push_back(portion); + } path_out[0].close(); } - original.clear(); + portion.clear(); } if(cs.size() == 0 && position == -1){ - path_out.push_back(*path_it); - path_out.push_back(*path_it * m); + path_out.push_back(original); + path_out.push_back(original * m); } } } - if (!joinPaths) { + if (!fusionPaths || discard_orig_path) { for (int i = 0; i < static_cast(path_in.size()); ++i) { path_out.push_back(path_in[i] * m); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 2ea8161d4..c925f220f 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -34,12 +34,16 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); + virtual std::vector doEffect_path (std::vector const & path_in); private: BoolParam discard_orig_path; - BoolParam joinPaths; + BoolParam fusionPaths; + BoolParam reverseFusion; PathParam reflection_line; + Geom::Line lineSeparation; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 2a940cb92f484630523c7d859d7048f3df6e4f6e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 13 Nov 2014 20:32:40 +0100 Subject: Six a bug on subpaths pointed by suv (bzr r13682.1.8) --- src/live_effects/lpe-mirror_symmetry.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index c21c65a3e..6fb2bfc73 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -119,6 +119,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) if (path_it->empty()){ continue; } + std::vector temp_path; double timeStart = 0.0; int position = 0; bool end_open = false; @@ -151,7 +152,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) portion.setFinal(portion.initialPoint()); portion.close(); } - path_out.push_back(portion); + temp_path.push_back(portion); } portion.clear(); timeStart = timeEnd; @@ -168,23 +169,25 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) portion.append(mirror); portion = portion.reverse(); if (!original.closed()){ - path_out.push_back(portion); + temp_path.push_back(portion); } else { if(cs.size() >1 ){ - portion.setFinal(path_out[0].initialPoint()); - portion.setInitial(path_out[0].finalPoint()); - path_out[0].append(portion); + portion.setFinal(temp_path[0].initialPoint()); + portion.setInitial(temp_path[0].finalPoint()); + temp_path[0].append(portion); } else { - path_out.push_back(portion); + temp_path.push_back(portion); } - path_out[0].close(); + temp_path[0].close(); } portion.clear(); } if(cs.size() == 0 && position == -1){ - path_out.push_back(original); - path_out.push_back(original * m); + temp_path.push_back(original); + temp_path.push_back(original * m); } + path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); + temp_path.clear(); } } -- cgit v1.2.3 From 840daf70ff3f7c2c8e9cc0fae0037befcfa18edf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 14 Nov 2014 20:14:04 +0100 Subject: fix a crash bug applyed on groups (bzr r13708.1.1) --- src/live_effects/effect.cpp | 3 ++- src/live_effects/lpe-copy_rotate.cpp | 11 +++++++---- src/live_effects/lpe-copy_rotate.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index e49a15dd0..0f4bdfaaa 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -112,7 +112,6 @@ const Util::EnumData LPETypeData[] = { {PATH_LENGTH, N_("Path length"), "path_length"}, {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, - {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, {TEXT_LABEL, N_("Text label"), "text_label"}, @@ -153,6 +152,8 @@ const Util::EnumData LPETypeData[] = { {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, +/* 0.92 */ + {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index e466093d3..7e3f35f9d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -76,11 +76,12 @@ LPECopyRotate::~LPECopyRotate() void LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) { - SPCurve const *curve = SP_SHAPE(lpeitem)->_curve; + using namespace Geom; - A = *(curve->first_point()); - B = *(curve->last_point()); + original_bbox(lpeitem); + Point A(boundingbox_X.min(), boundingbox_Y.middle()); + Point B(boundingbox_X.max(), boundingbox_Y.middle()); origin.param_setValue(A); dir = unit_vector(B - A); @@ -123,12 +124,14 @@ LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector((Geom::Point) origin); path.appendNew(rot_pos); - + std::cout << rot_pos << "rot\n"; + std::cout << origin << "origin\n"; PathVector pathv; pathv.push_back(path); hp_vec.push_back(pathv); } + void LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { { KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index ca7aa269c..c84889f57 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -16,6 +16,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/point.h" +#include "live_effects/lpegroupbbox.h" namespace Inkscape { namespace LivePathEffect { @@ -26,7 +27,7 @@ namespace CR { class KnotHolderEntityRotationAngle; } -class LPECopyRotate : public Effect { +class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); virtual ~LPECopyRotate(); -- cgit v1.2.3 From a5333b6abc807176319c96d66cb7111e70f4896f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 15 Nov 2014 18:29:41 +0100 Subject: ignore this commit (bzr r13682.1.9) --- src/live_effects/effect.cpp | 8 ++- src/live_effects/effect.h | 2 + src/live_effects/lpe-bendpath.cpp | 4 +- src/live_effects/lpe-mirror_symmetry.cpp | 103 ++++++++++++++++++++++++++++++- src/live_effects/lpe-mirror_symmetry.h | 15 +++++ src/live_effects/lpegroupbbox.cpp | 12 ++++ 6 files changed, 140 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index eb649db62..9997b1662 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -613,7 +613,7 @@ Effect::registerParameter(Parameter * param) void Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { using namespace Inkscape::LivePathEffect; - + knot_holder = knotholder; // add handles provided by the effect itself addKnotHolderEntities(knotholder, desktop, item); @@ -623,6 +623,12 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { } } +void +Effect::removeHandles(){ + if(knot_holder){ + knot_holder = NULL; + } +} /** * Return a vector of PathVectors which contain all canvas indicators for this effect. * This is the function called by external code to get all canvas indicators (effect and its parameters) diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 7da76b267..5d715c7f2 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -101,6 +101,7 @@ public: // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void removeHandles(); std::vector getCanvasIndicators(SPLPEItem const* lpeitem); inline bool providesOwnFlashPaths() const { @@ -160,6 +161,7 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. Glib::ustring const * defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + KnotHolder *knot_holder; double current_zoom; std::vector selectedNodesPoints; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 33171b184..968e12518 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -137,7 +137,9 @@ LPEBendPath::resetDefaults(SPItem const* item) Geom::Point start(boundingbox_X.min(), (boundingbox_Y.max()+boundingbox_Y.min())/2); Geom::Point end(boundingbox_X.max(), (boundingbox_Y.max()+boundingbox_Y.min())/2); - + std::cout << start << "start\n"; + std::cout << start << "end\n"; + std::cout << boundingbox_X.min() << "boundingbox_X.min\n"; if ( Geom::are_near(start,end) ) { end += Geom::Point(1.,0.); } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 6fb2bfc73..dc9a94b1b 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -24,23 +24,43 @@ #include <2geom/path-intersection.h> #include <2geom/transforms.h> #include <2geom/affine.h> +#include "knot-holder-entity.h" +#include "knotholder.h" namespace Inkscape { namespace LivePathEffect { +namespace MS { + +class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { +public: + KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + +} // namespace MS + LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), - reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0") + forceX(_("Force horizontal"), _("Force horizontal"), "forceX", &wr, this, false), + forceY(_("Force vertical"), _("Force vertical"), "forceY", &wr, this, false), + reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), + center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") { show_orig_path = true; registerParameter( dynamic_cast(&discard_orig_path) ); registerParameter( dynamic_cast(&fusionPaths) ); registerParameter( dynamic_cast(&reverseFusion) ); + registerParameter( dynamic_cast(&forceX) ); + registerParameter( dynamic_cast(&forceY) ); registerParameter( dynamic_cast(&reflection_line) ); + registerParameter( dynamic_cast(¢er) ); + } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -50,9 +70,36 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { + using namespace Geom; + SPLPEItem * item = const_cast(lpeitem); std::vector mline(reflection_line.get_pathvector()); - lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); + double dist = distance(mline[0].initialPoint(),mline[0].finalPoint()); + if( !forceX && !forceY ){ + center.param_setValue(mline[0].pointAt(0.5)); + } + Point A(0,0); + Point B(0,0); + if(forceX){ + A = Geom::Point(center[X]+(dist/2.0),center[Y]); + B = Geom::Point(center[X]-(dist/2.0),center[Y]); + } + if(forceY){ + A = Geom::Point(center[X],center[Y]+(dist/2.0)); + B = Geom::Point(center[X],center[Y]-(dist/2.0)); + } + if( forceX || forceY ){ + lineSeparation.setPoints(A,B); + Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); + reflection_line.set_new_value(rline, true); + } else { + lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); + } + //Geom::Point const q = lineSeparation.pointAt(0.5)* lpeitem->i2dt_affine().inverse(); + if(knot_holder){ + knot_holder->update_knots(); + } + //e->knot_set(q, e->knot->drag_origin * lpeitem->i2dt_affine().inverse(), (guint)1); item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -200,6 +247,58 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) return path_out; } +void +LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + using namespace Geom; + + PathVector pathv; + Geom::Path mlineExpanded; + Geom::Point lineStart = lineSeparation.pointAt(-100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(100000.0); + mlineExpanded.start( lineStart); + mlineExpanded.appendNew( lineEnd); + pathv.push_back(mlineExpanded); + hp_vec.push_back(pathv); +} + +void +LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + { + KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); + e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the center") ); + knotholder->add(e); + } + +}; + +namespace MS { + +using namespace Geom; + +void +KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) +{ + LPEMirrorSymmetry* lpe = dynamic_cast(_effect); + + Geom::Point const s = snap_knot_position(p, state); + + lpe->center.param_setValue(s); + + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + +Geom::Point +KnotHolderEntityCenterMirrorSymmetry::knot_get() const +{ + LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); + return lpe->center; +} + +} // namespace CR + } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index c925f220f..4b2c9aea0 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -25,6 +25,11 @@ namespace Inkscape { namespace LivePathEffect { +namespace MS { + // we need a separate namespace to avoid clashes with LPEPerpBisector + class KnotHolderEntityCenterMirrorSymmetry; +} + class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{ public: LPEMirrorSymmetry(LivePathEffectObject *lpeobject); @@ -38,12 +43,22 @@ public: virtual std::vector doEffect_path (std::vector const & path_in); + /* the knotholder entity classes must be declared friends */ + friend class MS::KnotHolderEntityCenterMirrorSymmetry; + void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + +protected: + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); + private: BoolParam discard_orig_path; BoolParam fusionPaths; BoolParam reverseFusion; + BoolParam forceX; + BoolParam forceY; PathParam reflection_line; Geom::Line lineSeparation; + PointParam center; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 2a1b70a6a..78545e9c5 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -8,6 +8,7 @@ #include "live_effects/lpegroupbbox.h" #include "sp-item.h" +#include "sp-item-group.h" namespace Inkscape { namespace LivePathEffect { @@ -34,9 +35,20 @@ void GroupBBoxEffect::original_bbox(SPLPEItem const* lpeitem, bool absolute) } Geom::OptRect bbox = lpeitem->geometricBounds(transform); + std::cout << bbox->hasZeroArea() << "=AREA\n"; + if(bbox->hasZeroArea() && SP_IS_GROUP(lpeitem)){ + bbox = (Geom::OptRect)SP_GROUP(lpeitem)->bbox(transform, SPLPEItem::GEOMETRIC_BBOX); + //GSList const *items = sp_item_group_item_list(SPGroup * group); + //for ( GSList const *i = items ; i != NULL ; i = i->next ) { + // bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds()); + //} + } + std::cout << bbox->hasZeroArea() << "=AREA222\n"; if (bbox) { boundingbox_X = (*bbox)[Geom::X]; boundingbox_Y = (*bbox)[Geom::Y]; + std::cout << boundingbox_X << "=BBOXX\n"; + std::cout << boundingbox_Y << "=BBOXY\n"; } else { boundingbox_X = Geom::Interval(); boundingbox_Y = Geom::Interval(); -- cgit v1.2.3 From 69ef82447f23d5ebd3abc6a5903b10bbdb1b12f4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 15 Nov 2014 18:34:32 +0100 Subject: ignore this commit (bzr r13682.1.10) --- src/live_effects/effect.cpp | 10 +- src/live_effects/effect.h | 2 - src/live_effects/lpe-bendpath.cpp | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 76 +++++-- src/live_effects/lpe-fillet-chamfer.h | 4 +- src/live_effects/lpe-mirror_symmetry.cpp | 230 ++------------------- src/live_effects/lpe-mirror_symmetry.h | 24 +-- src/live_effects/lpegroupbbox.cpp | 12 -- .../parameter/filletchamferpointarray.cpp | 32 ++- 9 files changed, 108 insertions(+), 286 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 9997b1662..e49a15dd0 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -106,6 +106,7 @@ const Util::EnumData LPETypeData[] = { {EXTRUDE, N_("Extrude"), "extrude"}, {LATTICE, N_("Lattice Deformation"), "lattice"}, {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, + {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {OFFSET, N_("Offset"), "offset"}, {PARALLEL, N_("Parallel"), "parallel"}, {PATH_LENGTH, N_("Path length"), "path_length"}, @@ -152,7 +153,6 @@ const Util::EnumData LPETypeData[] = { {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, - {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -613,7 +613,7 @@ Effect::registerParameter(Parameter * param) void Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { using namespace Inkscape::LivePathEffect; - knot_holder = knotholder; + // add handles provided by the effect itself addKnotHolderEntities(knotholder, desktop, item); @@ -623,12 +623,6 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { } } -void -Effect::removeHandles(){ - if(knot_holder){ - knot_holder = NULL; - } -} /** * Return a vector of PathVectors which contain all canvas indicators for this effect. * This is the function called by external code to get all canvas indicators (effect and its parameters) diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 5d715c7f2..7da76b267 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -101,7 +101,6 @@ public: // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void removeHandles(); std::vector getCanvasIndicators(SPLPEItem const* lpeitem); inline bool providesOwnFlashPaths() const { @@ -161,7 +160,6 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. Glib::ustring const * defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - KnotHolder *knot_holder; double current_zoom; std::vector selectedNodesPoints; SPCurve * sp_curve; diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 968e12518..33171b184 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -137,9 +137,7 @@ LPEBendPath::resetDefaults(SPItem const* item) Geom::Point start(boundingbox_X.min(), (boundingbox_Y.max()+boundingbox_Y.min())/2); Geom::Point end(boundingbox_X.max(), (boundingbox_Y.max()+boundingbox_Y.min())/2); - std::cout << start << "start\n"; - std::cout << start << "end\n"; - std::cout << boundingbox_X.min() << "boundingbox_X.min\n"; + if ( Geom::are_near(start,end) ) { end += Geom::Point(1.,0.); } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index c89bfbd37..78e24f0b8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -79,7 +79,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : radius.param_set_range(0., infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); - chamfer_steps.param_set_range(0, infinity()); + chamfer_steps.param_set_range(0, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); helper_size.param_set_range(0, infinity()); @@ -116,7 +116,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } } else if (param->param_key == "chamfer_steps") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); widg = widgRegistered; if (widg) { Gtk::HBox *scalarParameter = dynamic_cast(widg); @@ -153,21 +153,26 @@ Gtk::Widget *LPEFilletChamfer::newWidget() ++it; } - - Gtk::VBox *buttonsContainer = Gtk::manage(new Gtk::VBox(true, 0)); + Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); - buttonsContainer->pack_start(*fillet, true, true, 2); - Gtk::Button *inverse = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); - inverse->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverse)); - buttonsContainer->pack_start(*inverse, true, true, 2); - + filletContainer->pack_start(*fillet, true, true, 2); + Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + filletContainer->pack_start(*inverseFillet, true, true, 2); + + Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); - buttonsContainer->pack_start(*chamfer, true, true, 2); - vbox->pack_start(*buttonsContainer, true, true, 2); + chamferContainer->pack_start(*chamfer, true, true, 2); + Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + chamferContainer->pack_start(*inverseChamfer, true, true, 2); + + vbox->pack_start(*filletContainer, true, true, 2); + vbox->pack_start(*chamferContainer, true, true, 2); return vbox; } @@ -232,17 +237,31 @@ void LPEFilletChamfer::fillet() doChangeType(path_from_piecewise(pwd2, tolerance), 1); } -void LPEFilletChamfer::inverse() +void LPEFilletChamfer::inverseFillet() { Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); doChangeType(path_from_piecewise(pwd2, tolerance), 2); } +void LPEFilletChamfer::chamferSubdivisions() +{ + fillet_chamfer_values.set_chamfer_steps(chamfer_steps); + Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); + doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 5000); +} + void LPEFilletChamfer::chamfer() { - fillet_chamfer_values.set_chamfer_steps(chamfer_steps + 3); + fillet_chamfer_values.set_chamfer_steps(chamfer_steps); Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 3); + doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 3000); +} + +void LPEFilletChamfer::inverseChamfer() +{ + fillet_chamfer_values.set_chamfer_steps(chamfer_steps); + Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); + doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 4000); } void LPEFilletChamfer::refreshKnots() @@ -333,6 +352,13 @@ void LPEFilletChamfer::doChangeType(std::vector const& original_path toggle = false; } if (toggle) { + if(type >= 5000){ + if(filletChamferData[counter][Y] >= 3000 && filletChamferData[counter][Y] < 4000){ + type = type - 2000; + } else if (filletChamferData[counter][Y] >= 4000 && filletChamferData[counter][Y] < 5000){ + type = type - 1000; + } + } result.push_back(Point(filletChamferData[counter][X], type)); } else { result.push_back(filletChamferData[counter]); @@ -552,8 +578,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { type = std::abs(filletChamferData[counter + 1][Y]); } - if (type >= 3) { - unsigned int chamferSubs = type-2; + if (type >= 3000 && type < 4000) { + unsigned int chamferSubs = type-2999; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ @@ -567,6 +593,22 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_out.appendNew(chamferStep); } path_out.appendNew(endArcPoint); + } else if (type >= 4000 && type < 5000) { + unsigned int chamferSubs = type-3999; + Geom::Path path_chamfer; + path_chamfer.start(path_out.finalPoint()); + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + ccwToggle = ccwToggle?0:1; + path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + }else{ + path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + } + double chamfer_stepsTime = 1.0/chamferSubs; + for(unsigned int i = 1; i < chamferSubs; i++){ + Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); + } + path_out.appendNew(endArcPoint); } else if (type == 2) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; @@ -574,7 +616,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) }else{ path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - } else { + } else if (type == 1){ if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index e3589197c..0d6a1ff17 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -56,8 +56,10 @@ public: void toggleHide(); void toggleFlexFixed(); void chamfer(); + void chamferSubdivisions(); + void inverseChamfer(); void fillet(); - void inverse(); + void inverseFillet(); void updateFillet(); void doUpdateFillet(std::vector const& original_pathv, double power); void doChangeType(std::vector const& original_pathv, int type); diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index dc9a94b1b..0bb67a4a2 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -19,48 +19,23 @@ #include #include #include -#include "helper/geom.h" + #include <2geom/path.h> -#include <2geom/path-intersection.h> #include <2geom/transforms.h> #include <2geom/affine.h> -#include "knot-holder-entity.h" -#include "knotholder.h" namespace Inkscape { namespace LivePathEffect { -namespace MS { - -class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { -public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; - -} // namespace MS - LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), - reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), - forceX(_("Force horizontal"), _("Force horizontal"), "forceX", &wr, this, false), - forceY(_("Force vertical"), _("Force vertical"), "forceY", &wr, this, false), - reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), - center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") + reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100") { show_orig_path = true; registerParameter( dynamic_cast(&discard_orig_path) ); - registerParameter( dynamic_cast(&fusionPaths) ); - registerParameter( dynamic_cast(&reverseFusion) ); - registerParameter( dynamic_cast(&forceX) ); - registerParameter( dynamic_cast(&forceY) ); registerParameter( dynamic_cast(&reflection_line) ); - registerParameter( dynamic_cast(¢er) ); - } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -70,36 +45,7 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { - using namespace Geom; - SPLPEItem * item = const_cast(lpeitem); - std::vector mline(reflection_line.get_pathvector()); - double dist = distance(mline[0].initialPoint(),mline[0].finalPoint()); - if( !forceX && !forceY ){ - center.param_setValue(mline[0].pointAt(0.5)); - } - Point A(0,0); - Point B(0,0); - if(forceX){ - A = Geom::Point(center[X]+(dist/2.0),center[Y]); - B = Geom::Point(center[X]-(dist/2.0),center[Y]); - } - if(forceY){ - A = Geom::Point(center[X],center[Y]+(dist/2.0)); - B = Geom::Point(center[X],center[Y]-(dist/2.0)); - } - if( forceX || forceY ){ - lineSeparation.setPoints(A,B); - Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - reflection_line.set_new_value(rline, true); - } else { - lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint()); - } - //Geom::Point const q = lineSeparation.pointAt(0.5)* lpeitem->i2dt_affine().inverse(); - if(knot_holder){ - knot_holder->update_knots(); - } - //e->knot_set(q, e->knot->drag_origin * lpeitem->i2dt_affine().inverse(), (guint)1); item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -109,22 +55,19 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { using namespace Geom; - original_bbox(lpeitem); + // fixme: what happens if the bbox is empty? + // fixme: this is probably wrong + Geom::Affine t = lpeitem->i2dt_affine(); + Geom::Rect bbox = *lpeitem->desktopVisualBounds(); - Point A(boundingbox_X.max(), boundingbox_Y.max()); - Point B(boundingbox_X.max(), boundingbox_Y.min()); + Point A(bbox.left(), bbox.bottom()); + Point B(bbox.left(), bbox.top()); + A *= t; + B *= t; Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); reflection_line.set_new_value(rline, true); } -int -LPEMirrorSymmetry::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) -{ - //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); - return (pos < 0) ? -1 : (pos > 0); -} - std::vector LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) { @@ -132,20 +75,15 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) if ( reflection_line.get_pathvector().empty() ) { return path_in; } - Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); - std::vector path_out; - Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( lineEnd); - if (!discard_orig_path && !fusionPaths) { + std::vector path_out; + if (!discard_orig_path) { path_out = path_in; } - Geom::Point A(lineStart); - Geom::Point B(lineEnd); + std::vector mline(reflection_line.get_pathvector()); + Geom::Point A(mline.front().initialPoint()); + Geom::Point B(mline.back().finalPoint()); Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); double hyp = Geom::distance(A, B); @@ -159,146 +97,14 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) m = m * sca; m = m * m2.inverse(); m = m * m1; - - if(fusionPaths && !discard_orig_path){ - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ - continue; - } - std::vector temp_path; - double timeStart = 0.0; - int position = 0; - bool end_open = false; - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { - end_open = true; - } - } - Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()){ - original.close(false); - original.appendNew( original.initialPoint() ); - original.close(true); - } - Geom::Crossings cs = crossings(original, mlineExpanded); - for(unsigned int i = 0; i < cs.size(); i++) { - double timeEnd = cs[i].ta; - Geom::Path portion = original.portion(timeStart, timeEnd); - Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine(lineStart, lineEnd, middle); - if(reverseFusion){ - position *= -1; - } - if(position == -1){ - Geom::Path mirror = portion.reverse() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - if(i!=0){ - portion.setFinal(portion.initialPoint()); - portion.close(); - } - temp_path.push_back(portion); - } - portion.clear(); - timeStart = timeEnd; - } - position = pointSideOfLine(lineStart, lineEnd, original.finalPoint()); - if(reverseFusion){ - position *= -1; - } - if(cs.size()!=0 && position == -1){ - Geom::Path portion = original.portion(timeStart, original.size()); - portion = portion.reverse(); - Geom::Path mirror = portion.reverse() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - portion = portion.reverse(); - if (!original.closed()){ - temp_path.push_back(portion); - } else { - if(cs.size() >1 ){ - portion.setFinal(temp_path[0].initialPoint()); - portion.setInitial(temp_path[0].finalPoint()); - temp_path[0].append(portion); - } else { - temp_path.push_back(portion); - } - temp_path[0].close(); - } - portion.clear(); - } - if(cs.size() == 0 && position == -1){ - temp_path.push_back(original); - temp_path.push_back(original * m); - } - path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); - temp_path.clear(); - } - } - - if (!fusionPaths || discard_orig_path) { - for (int i = 0; i < static_cast(path_in.size()); ++i) { - path_out.push_back(path_in[i] * m); - } - } - return path_out; -} - -void -LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - using namespace Geom; - - PathVector pathv; - Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( lineEnd); - pathv.push_back(mlineExpanded); - hp_vec.push_back(pathv); -} - -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - { - KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center") ); - knotholder->add(e); + for (int i = 0; i < static_cast(path_in.size()); ++i) { + path_out.push_back(path_in[i] * m); } -}; - -namespace MS { - -using namespace Geom; - -void -KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) -{ - LPEMirrorSymmetry* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - lpe->center.param_setValue(s); - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - -Geom::Point -KnotHolderEntityCenterMirrorSymmetry::knot_get() const -{ - LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); - return lpe->center; + return path_out; } -} // namespace CR - } //namespace LivePathEffect } /* namespace Inkscape */ diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 4b2c9aea0..a4a2b86c0 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -20,17 +20,10 @@ #include "live_effects/parameter/point.h" #include "live_effects/parameter/path.h" -#include "live_effects/lpegroupbbox.h" - namespace Inkscape { namespace LivePathEffect { -namespace MS { - // we need a separate namespace to avoid clashes with LPEPerpBisector - class KnotHolderEntityCenterMirrorSymmetry; -} - -class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{ +class LPEMirrorSymmetry : public Effect { public: LPEMirrorSymmetry(LivePathEffectObject *lpeobject); virtual ~LPEMirrorSymmetry(); @@ -39,26 +32,11 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); - virtual std::vector doEffect_path (std::vector const & path_in); - /* the knotholder entity classes must be declared friends */ - friend class MS::KnotHolderEntityCenterMirrorSymmetry; - void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - -protected: - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); - private: BoolParam discard_orig_path; - BoolParam fusionPaths; - BoolParam reverseFusion; - BoolParam forceX; - BoolParam forceY; PathParam reflection_line; - Geom::Line lineSeparation; - PointParam center; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 78545e9c5..2a1b70a6a 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -8,7 +8,6 @@ #include "live_effects/lpegroupbbox.h" #include "sp-item.h" -#include "sp-item-group.h" namespace Inkscape { namespace LivePathEffect { @@ -35,20 +34,9 @@ void GroupBBoxEffect::original_bbox(SPLPEItem const* lpeitem, bool absolute) } Geom::OptRect bbox = lpeitem->geometricBounds(transform); - std::cout << bbox->hasZeroArea() << "=AREA\n"; - if(bbox->hasZeroArea() && SP_IS_GROUP(lpeitem)){ - bbox = (Geom::OptRect)SP_GROUP(lpeitem)->bbox(transform, SPLPEItem::GEOMETRIC_BBOX); - //GSList const *items = sp_item_group_item_list(SPGroup * group); - //for ( GSList const *i = items ; i != NULL ; i = i->next ) { - // bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds()); - //} - } - std::cout << bbox->hasZeroArea() << "=AREA222\n"; if (bbox) { boundingbox_X = (*bbox)[Geom::X]; boundingbox_Y = (*bbox)[Geom::Y]; - std::cout << boundingbox_X << "=BBOXX\n"; - std::cout << boundingbox_Y << "=BBOXY\n"; } else { boundingbox_X = Geom::Interval(); boundingbox_Y = Geom::Interval(); diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index cf9ef3132..4e2be6e88 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -723,7 +723,7 @@ FilletChamferPointArrayParamKnotHolderEntity( void FilletChamferPointArrayParamKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, - guint /*state*/) + guint state) { using namespace Geom; @@ -733,7 +733,7 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_set(Point const &p, /// @todo how about item transforms??? Piecewise > const &pwd2 = _pparam->get_pwd2(); //todo: add snapping - //Geom::Point const s = snap_knot_position(p, state); + Geom::Point const s = snap_knot_position(p, state); double t = nearest_point(p, pwd2[_index]); if (t == 1) { t = 0.9999; @@ -777,13 +777,21 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_click(guint state) }else{ using namespace Geom; int type = (int)_pparam->_vector.at(_index)[Y]; - + if (type >=3000 && type < 4000){ + type = 3; + } + if (type >=4000 && type < 5000){ + type = 4; + } switch(type){ case 1: type = 2; break; case 2: - type = _pparam->chamfer_steps; + type = _pparam->chamfer_steps + 3000; + break; + case 3: + type = _pparam->chamfer_steps + 4000; break; default: type = 1; @@ -793,8 +801,12 @@ void FilletChamferPointArrayParamKnotHolderEntity::knot_click(guint state) _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; - if (type >= 3) { - tip = _("Chamfer: Ctrl+Click toogle type, " + if (type >=3000 && type < 4000){ + tip = _("Chamfer: Ctrl+Click toogle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type >=4000 && type < 5000) { + tip = _("Inverse Chamfer: Ctrl+Click toogle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == 2) { @@ -850,8 +862,12 @@ void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, continue; } const gchar *tip; - if (_vector[i][Y] >= 3) { - tip = _("Chamfer: Ctrl+Click toogle type, " + if (_vector[i][Y] >=3000 && _vector[i][Y] < 4000){ + tip = _("Chamfer: Ctrl+Click toogle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (_vector[i][Y] >=4000 && _vector[i][Y] < 5000) { + tip = _("Inverse Chamfer: Ctrl+Click toogle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (_vector[i][Y] == 2) { -- cgit v1.2.3 From 015ec174f96c7e0aa96f4bab17a2895b62f4c24c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 16 Nov 2014 20:47:41 +0100 Subject: 360 auto degree calculation check (bzr r13708.1.2) --- src/live_effects/lpe-copy_rotate.cpp | 52 +++++++----------------------------- src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 10 insertions(+), 44 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 7e3f35f9d..51787e292 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -38,12 +38,6 @@ public: virtual Geom::Point knot_get() const; }; -class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity { -public: - KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; -}; } // namespace CR @@ -52,6 +46,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), + copiesTo360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copiesTo360", &wr, this, true), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), dist_angle_handle(100) { @@ -59,6 +54,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : _provides_knotholder_entities = true; // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast(&copiesTo360) ); registerParameter( dynamic_cast(&starting_angle) ); registerParameter( dynamic_cast(&rotation_angle) ); registerParameter( dynamic_cast(&num_copies) ); @@ -82,6 +78,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) Point A(boundingbox_X.min(), boundingbox_Y.middle()); Point B(boundingbox_X.max(), boundingbox_Y.middle()); + Point C(boundingbox_X.middle(), boundingbox_Y.middle()); origin.param_setValue(A); dir = unit_vector(B - A); @@ -96,7 +93,11 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; - rot_pos = origin + dir * Rotate(-deg_to_rad(starting_angle + rotation_angle)) * dist_angle_handle; + double rotation_angle_end = rotation_angle; + if(copiesTo360){ + rotation_angle_end = 360.0/(double)num_copies; + } + rot_pos = origin + dir * Rotate(-deg_to_rad(starting_angle + rotation_angle_end)) * dist_angle_handle; A = pwd2_in.firstValue(); B = pwd2_in.lastValue(); @@ -108,7 +109,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p for (int i = 0; i < num_copies; ++i) { // I first suspected the minus sign to be a bug in 2geom but it is // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle * i)); + Rotate rot(-deg_to_rad(rotation_angle_end * i)); Affine t = pre * rot * Translate(origin); output.concat(pwd2_in * t); } @@ -124,8 +125,6 @@ LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector((Geom::Point) origin); path.appendNew(rot_pos); - std::cout << rot_pos << "rot\n"; - std::cout << origin << "origin\n"; PathVector pathv; pathv.push_back(path); hp_vec.push_back(pathv); @@ -139,12 +138,6 @@ void LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *des _("Adjust the starting angle") ); knotholder->add(e); } - { - KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the rotation angle") ); - knotholder->add(e); - } }; namespace CR { @@ -171,26 +164,6 @@ KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } -void -KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) -{ - LPECopyRotate* lpe = dynamic_cast(_effect); - - Geom::Point const s = snap_knot_position(p, state); - - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - lpe->rotation_angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle); - if (state & GDK_SHIFT_MASK) { - lpe->dist_angle_handle = L2(lpe->B - lpe->A); - } else { - lpe->dist_angle_handle = L2(p - lpe->origin); - } - - // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. - sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); -} - Geom::Point KnotHolderEntityStartingAngle::knot_get() const { @@ -198,13 +171,6 @@ KnotHolderEntityStartingAngle::knot_get() const return lpe->start_pos; } -Geom::Point -KnotHolderEntityRotationAngle::knot_get() const -{ - LPECopyRotate const *lpe = dynamic_cast(_effect); - return lpe->rot_pos; -} - } // namespace CR diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index c84889f57..123c92cdd 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,6 @@ public: /* the knotholder entity classes must be declared friends */ friend class CR::KnotHolderEntityStartingAngle; - friend class CR::KnotHolderEntityRotationAngle; void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: @@ -48,6 +47,7 @@ private: ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; + BoolParam copiesTo360; PointParam origin; -- cgit v1.2.3 From e7bb1921ce0a29a94fe03c321ad409e7d407611d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 17 Nov 2014 23:27:28 +0100 Subject: adding knot improvements pointed by su_v (bzr r13682.1.13) --- src/live_effects/lpe-mirror_symmetry.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 4024ff83e..1205476a4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -80,10 +80,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPLPEItem * item = const_cast(lpeitem); std::vector mline(reflection_line.get_pathvector()); - Point A = mline[0].initialPoint(); - Point B = mline[0].finalPoint(); - Point C = mline[0].pointAt(0.5); + Point A(boundingbox_X.max(), boundingbox_Y.max()); + Point B(boundingbox_X.max(), boundingbox_Y.min()); double dist = distance(A,B); + Point C = mline[0].pointAt(0.5); if(mode == MT_X){ A = Geom::Point(center[X]+(dist/2.0),center[Y]); B = Geom::Point(center[X]-(dist/2.0),center[Y]); @@ -96,7 +96,19 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); reflection_line.set_new_value(rline, true); } else { - center.param_setValue(C); + A = mline[0].initialPoint(); + B = mline[0].finalPoint(); + lineSeparation.setPoints(A,B); + Geom::Rotate rot = Geom::Rotate(lineSeparation.angle()); + Geom::Translate trans = Geom::Translate(center); + A = Geom::Point(center[X],center[Y]+(dist/2.0)); + B = Geom::Point(center[X],center[Y]-(dist/2.0)); + Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); + rline *= rot; + rline *= trans; + reflection_line.set_new_value(rline, true); + A = mline[0].initialPoint(); + B = mline[0].finalPoint(); } lineSeparation.setPoints(A,B); if(knot_holder){ -- cgit v1.2.3 From b619510d9fc49fdfa636f50487acc5fea773afc9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 18 Nov 2014 00:08:09 +0100 Subject: adding knot improvements pointed by su_v (bzr r13682.1.15) --- src/live_effects/lpe-mirror_symmetry.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 1205476a4..bc5dc747d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -83,7 +83,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Point A(boundingbox_X.max(), boundingbox_Y.max()); Point B(boundingbox_X.max(), boundingbox_Y.min()); double dist = distance(A,B); - Point C = mline[0].pointAt(0.5); if(mode == MT_X){ A = Geom::Point(center[X]+(dist/2.0),center[Y]); B = Geom::Point(center[X]-(dist/2.0),center[Y]); @@ -93,27 +92,29 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) B = Geom::Point(center[X],center[Y]-(dist/2.0)); } if( mode == MT_X || mode == MT_Y ){ - Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - reflection_line.set_new_value(rline, true); + Geom::Path path; + path.start( A ); + path.appendNew( B ); + reflection_line.set_new_value(path.toPwSb(), true); } else { A = mline[0].initialPoint(); B = mline[0].finalPoint(); + Point C = mline[0].pointAt(0.5); lineSeparation.setPoints(A,B); Geom::Rotate rot = Geom::Rotate(lineSeparation.angle()); Geom::Translate trans = Geom::Translate(center); A = Geom::Point(center[X],center[Y]+(dist/2.0)); B = Geom::Point(center[X],center[Y]-(dist/2.0)); - Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - rline *= rot; - rline *= trans; - reflection_line.set_new_value(rline, true); + Geom::Path path; + path.start( B ); + path.appendNew( A ); + path *= Geom::Affine(rot); + path *= Geom::Affine(trans); + reflection_line.set_new_value(path.toPwSb(), true); A = mline[0].initialPoint(); B = mline[0].finalPoint(); } lineSeparation.setPoints(A,B); - if(knot_holder){ - knot_holder->update_knots(); - } item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -129,6 +130,8 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Point B(boundingbox_X.max(), boundingbox_Y.min()); Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); reflection_line.set_new_value(rline, true); + Point C = rline[0].pointAt(0.5); + center.param_setValue(C); } int -- cgit v1.2.3 From 806baa5e2a2a7f7720e7fc32fa66e5055a66f765 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 18 Nov 2014 20:00:50 +0100 Subject: adding knot improvements pointed by su_v (bzr r13682.1.17) --- src/live_effects/lpe-mirror_symmetry.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index bc5dc747d..2e34f2f6b 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -79,7 +79,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; SPLPEItem * item = const_cast(lpeitem); - std::vector mline(reflection_line.get_pathvector()); Point A(boundingbox_X.max(), boundingbox_Y.max()); Point B(boundingbox_X.max(), boundingbox_Y.min()); double dist = distance(A,B); @@ -97,22 +96,23 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) path.appendNew( B ); reflection_line.set_new_value(path.toPwSb(), true); } else { + std::vector mline(reflection_line.get_pathvector()); A = mline[0].initialPoint(); B = mline[0].finalPoint(); - Point C = mline[0].pointAt(0.5); lineSeparation.setPoints(A,B); + //Point C(boundingbox_X.max(), boundingbox_Y.middle()); Geom::Rotate rot = Geom::Rotate(lineSeparation.angle()); - Geom::Translate trans = Geom::Translate(center); + //Geom::Translate trans = Geom::Translate(center - C); A = Geom::Point(center[X],center[Y]+(dist/2.0)); B = Geom::Point(center[X],center[Y]-(dist/2.0)); Geom::Path path; - path.start( B ); - path.appendNew( A ); + path.start( A ); + path.appendNew( B ); path *= Geom::Affine(rot); - path *= Geom::Affine(trans); + //path *= Geom::Affine(trans); reflection_line.set_new_value(path.toPwSb(), true); - A = mline[0].initialPoint(); - B = mline[0].finalPoint(); + A = path.initialPoint(); + B = path.finalPoint(); } lineSeparation.setPoints(A,B); item->apply_to_clippath(item); @@ -128,9 +128,11 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Point A(boundingbox_X.max(), boundingbox_Y.max()); Point B(boundingbox_X.max(), boundingbox_Y.min()); - Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - reflection_line.set_new_value(rline, true); - Point C = rline[0].pointAt(0.5); + Point C(boundingbox_X.max(), boundingbox_Y.middle()); + Geom::Path path; + path.start( A ); + path.appendNew( B ); + reflection_line.set_new_value(path.toPwSb(), true); center.param_setValue(C); } @@ -152,8 +154,8 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); std::vector path_out; Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); + Geom::Point lineStart = lineSeparation.pointAt(100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(-100000.0); mlineExpanded.start( lineStart); mlineExpanded.appendNew( lineEnd); @@ -271,8 +273,8 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector PathVector pathv; Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); + Geom::Point lineStart = lineSeparation.pointAt(100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(-100000.0); mlineExpanded.start( lineStart); mlineExpanded.appendNew( lineEnd); pathv.push_back(mlineExpanded); -- cgit v1.2.3 From c287e23597d25cd743b44b48388a09151b18cdfc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 21 Nov 2014 11:49:26 +0100 Subject: added knot improvements pointed by su_v (bzr r13682.1.19) --- src/live_effects/lpe-mirror_symmetry.cpp | 81 +++++++++++++++++--------------- src/live_effects/lpe-mirror_symmetry.h | 1 + 2 files changed, 44 insertions(+), 38 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 2e34f2f6b..b0a4831f5 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -79,42 +79,48 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; SPLPEItem * item = const_cast(lpeitem); - Point A(boundingbox_X.max(), boundingbox_Y.max()); - Point B(boundingbox_X.max(), boundingbox_Y.min()); - double dist = distance(A,B); - if(mode == MT_X){ - A = Geom::Point(center[X]+(dist/2.0),center[Y]); - B = Geom::Point(center[X]-(dist/2.0),center[Y]); - } + Point A(boundingbox_X.max(), boundingbox_Y.min()); + Point B(boundingbox_X.max(), boundingbox_Y.max()); + Point C(boundingbox_X.max(), boundingbox_Y.middle()); if(mode == MT_Y){ - A = Geom::Point(center[X],center[Y]+(dist/2.0)); - B = Geom::Point(center[X],center[Y]-(dist/2.0)); + A = Geom::Point(boundingbox_X.min(),center[Y]); + B = Geom::Point(boundingbox_X.max(),center[Y]); + } + if(mode == MT_X){ + A = Geom::Point(center[X],boundingbox_Y.min()); + B = Geom::Point(center[X],boundingbox_Y.max()); } if( mode == MT_X || mode == MT_Y ){ Geom::Path path; path.start( A ); path.appendNew( B ); reflection_line.set_new_value(path.toPwSb(), true); - } else { - std::vector mline(reflection_line.get_pathvector()); - A = mline[0].initialPoint(); - B = mline[0].finalPoint(); lineSeparation.setPoints(A,B); - //Point C(boundingbox_X.max(), boundingbox_Y.middle()); - Geom::Rotate rot = Geom::Rotate(lineSeparation.angle()); - //Geom::Translate trans = Geom::Translate(center - C); - A = Geom::Point(center[X],center[Y]+(dist/2.0)); - B = Geom::Point(center[X],center[Y]-(dist/2.0)); - Geom::Path path; - path.start( A ); - path.appendNew( B ); - path *= Geom::Affine(rot); - //path *= Geom::Affine(trans); - reflection_line.set_new_value(path.toPwSb(), true); - A = path.initialPoint(); - B = path.finalPoint(); + center.param_setValue(path.pointAt(0.5)); + if(knot_holder){ + knot_holder->update_knots(); + } + } else if( mode == MT_FREE) { + std::vector mline(reflection_line.get_pathvector()); + if(!are_near(previousCenter,center, 0.01)){ + Geom::Point trans = center - mline[0].pointAt(0.5); + mline[0] *= Geom::Affine(1,0,0,1,trans[X],trans[Y]); + A = mline[0].initialPoint(); + B = mline[0].finalPoint(); + reflection_line.set_new_value(mline[0].toPwSb(), true); + lineSeparation.setPoints(A,B); + } else { + center.param_setValue(mline[0].pointAt(0.5)); + A = mline[0].initialPoint(); + B = mline[0].finalPoint(); + lineSeparation.setPoints(A,B); + if(knot_holder){ + knot_holder->update_knots(); + } + } + previousCenter = center; } - lineSeparation.setPoints(A,B); + item->apply_to_clippath(item); item->apply_to_mask(item); } @@ -126,14 +132,15 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) original_bbox(lpeitem); - Point A(boundingbox_X.max(), boundingbox_Y.max()); - Point B(boundingbox_X.max(), boundingbox_Y.min()); + Point A(boundingbox_X.max(), boundingbox_Y.min()); + Point B(boundingbox_X.max(), boundingbox_Y.max()); Point C(boundingbox_X.max(), boundingbox_Y.middle()); Geom::Path path; path.start( A ); path.appendNew( B ); reflection_line.set_new_value(path.toPwSb(), true); center.param_setValue(C); + previousCenter = center; } int @@ -154,8 +161,8 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); std::vector path_out; Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(-100000.0); + Geom::Point lineStart = lineSeparation.pointAt(-100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(100000.0); mlineExpanded.start( lineStart); mlineExpanded.appendNew( lineEnd); @@ -210,7 +217,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) if(reverseFusion){ position *= -1; } - if(position == -1){ + if(position == 1){ Geom::Path mirror = portion.reverse() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); @@ -227,7 +234,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) if(reverseFusion){ position *= -1; } - if(cs.size()!=0 && position == -1){ + if(cs.size()!=0 && position == 1){ Geom::Path portion = original.portion(timeStart, original.size()); portion = portion.reverse(); Geom::Path mirror = portion.reverse() * m; @@ -248,7 +255,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) } portion.clear(); } - if(cs.size() == 0 && position == -1){ + if(cs.size() == 0 && position == 1){ temp_path.push_back(original); temp_path.push_back(original * m); } @@ -273,8 +280,8 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector PathVector pathv; Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(-100000.0); + Geom::Point lineStart = lineSeparation.pointAt(-100000.0); + Geom::Point lineEnd = lineSeparation.pointAt(100000.0); mlineExpanded.start( lineStart); mlineExpanded.appendNew( lineEnd); pathv.push_back(mlineExpanded); @@ -300,9 +307,7 @@ void KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) { LPEMirrorSymmetry* lpe = dynamic_cast(_effect); - Geom::Point const s = snap_knot_position(p, state); - lpe->center.param_setValue(s); // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 4a5ea4755..8c6c49c7d 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -64,6 +64,7 @@ private: BoolParam reverseFusion; PathParam reflection_line; Geom::Line lineSeparation; + Geom::Point previousCenter; PointParam center; LPEMirrorSymmetry(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 04abdf45fdd7a96b13c09a2a7aabbca95ba9ebb9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Dec 2014 19:36:49 +0100 Subject: adding fussion improvements (bzr r13708.1.3) --- src/live_effects/lpe-copy_rotate.cpp | 122 +++++++++++++++++++++++++++++++++-- src/live_effects/lpe-copy_rotate.h | 1 + 2 files changed, 116 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 51787e292..e0855d452 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -47,6 +47,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copiesTo360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copiesTo360", &wr, this, true), + fusionPaths(_("Fusioned paths"), _("Fusion paths"), "fusionPaths", &wr, this, true), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), dist_angle_handle(100) { @@ -55,6 +56,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter( dynamic_cast(&copiesTo360) ); + registerParameter( dynamic_cast(&fusionPaths) ); registerParameter( dynamic_cast(&starting_angle) ); registerParameter( dynamic_cast(&rotation_angle) ); registerParameter( dynamic_cast(&num_copies) ); @@ -106,14 +108,120 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); - for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); - Affine t = pre * rot * Translate(origin); - output.concat(pwd2_in * t); + if(fusionPaths){ + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(-starting_angle)); + Rotate rot2(-deg_to_rad(rotation_angle_end-starting_angle)); + //Affine t = pre * rot * Translate(origin); + Geom::Path mlineExpanded; + Geom::Point lineStart(0,0); + Geom::Point lineStart[Geom::X] = cos(rot) * 100000.0; + Geom::Point lineStart[Geom::Y] = sin(rot) * 100000.0; + Geom::Point lineEnd(0,0); + Geom::Point lineEnd[Geom::X] = cos(rot2) * 100000.0; + Geom::Point lineEnd[Geom::Y] = sin(rot2) * 100000.0; + mlineExpanded.start( lineStart); + mlineExpanded.appendNew( origin); + mlineExpanded.appendNew( lineEnd); + PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + std::vector temp_path; + double timeStart = 0.0; + int position = 0; + bool end_open = false; + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { + end_open = true; + } + } + Geom::Path original = (Geom::Path)(*path_it); + if(end_open && path_it->closed()){ + original.close(false); + original.appendNew( original.initialPoint() ); + original.close(true); + } + Geom::Crossings cs = crossings(original, mlineExpanded); + for(unsigned int i = 0; i < cs.size(); i++) { + double timeEnd = cs[i].ta; + Geom::Path portion = original.portion(timeStart, timeEnd); + Geom::Point middle = portion.pointAt((double)portion.size()/2.0); + position = pointSideOfLine(lineStart, lineEnd, middle); + Geom::line middleLine; + middleLine->setPoints(origin,middle); + if(middleLine.angle > rot && middleLine < rot2){ + Geom::Path kaleidoscope; + for (int j = 0; j < num_copies; ++j) { + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * j)); + Affine t = pre * rot * Translate(origin); + kaleidoscope = portion.reverse() * t); + kaleidoscope.setInitial(portion.finalPoint()); + portion.append(kaleidoscope); + } + if(i!=0){ + portion.setFinal(portion.initialPoint()); + portion.close(); + } + temp_path.push_back(portion); + } + portion.clear(); + timeStart = timeEnd; + } + Geom::line middleLine; + middleLine->setPoints(origin,original.finalPoint()); + if(cs.size()!=0 && middleLine.angle > rot && middleLine < rot2){ + Geom::Path portion = original.portion(timeStart, original.size()); + portion = portion.reverse(); + + Geom::Path kaleidoscope; + for (int i = 0; i < num_copies; ++i) { + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * i)); + Affine t = pre * rot * Translate(origin); + kaleidoscope = portion.reverse() * t); + kaleidoscope.setInitial(portion.finalPoint()); + portion.append(kaleidoscope); + } + portion = portion.reverse(); + if (!original.closed()){ + temp_path.push_back(portion); + } else { + if(cs.size() >1 ){ + portion.setFinal(temp_path[0].initialPoint()); + portion.setInitial(temp_path[0].finalPoint()); + temp_path[0].append(portion); + } else { + temp_path.push_back(portion); + } + temp_path[0].close(); + } + portion.clear(); + } + if(cs.size() == 0 && position == 1){ + temp_path.push_back(original); + temp_path.push_back(original * m); + } + path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); + temp_path.clear(); + } + output = path_out.toPwSb(); + } else { + for (int i = 0; i < num_copies; ++i) { + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * i)); + Affine t = pre * rot * Translate(origin); + output.concat(pwd2_in * t); + } + } } - return output; } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 123c92cdd..735de2300 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -48,6 +48,7 @@ private: ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copiesTo360; + BoolParam fusionPaths; PointParam origin; -- cgit v1.2.3 From 9a944b9317cbe94fb7c3c9f976da9ceffedeadf7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 5 Dec 2014 21:20:55 +0100 Subject: adding fussion improvements (bzr r13708.1.5) --- src/live_effects/lpe-copy_rotate.cpp | 153 ++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 75 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 553f273fe..7e3e65f23 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -17,11 +17,14 @@ #include "live_effects/lpe-copy_rotate.h" #include "sp-shape.h" #include "display/curve.h" - +#include <2geom/path.h> +#include <2geom/path-intersection.h> +#include <2geom/sbasis-to-bezier.h> #include <2geom/path.h> #include <2geom/transforms.h> #include <2geom/d2-sbasis.h> #include <2geom/angle.h> +#include #include "knot-holder-entity.h" #include "knotholder.h" @@ -110,60 +113,57 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(fusionPaths){ - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(-starting_angle)); - Rotate rot2(-deg_to_rad(rotation_angle_end-starting_angle)); - //Affine t = pre * rot * Translate(origin); - Geom::Path mlineExpanded; - Geom::Point lineStart(0,0); - Geom::Point lineStart[Geom::X] = cos(rot) * 100000.0; - Geom::Point lineStart[Geom::Y] = sin(rot) * 100000.0; - Geom::Point lineEnd(0,0); - Geom::Point lineEnd[Geom::X] = cos(rot2) * 100000.0; - Geom::Point lineEnd[Geom::Y] = sin(rot2) * 100000.0; - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( origin); - mlineExpanded.appendNew( lineEnd); - PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ - continue; - } - std::vector temp_path; - double timeStart = 0.0; - int position = 0; - bool end_open = false; - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { - end_open = true; - } - } - Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()){ - original.close(false); - original.appendNew( original.initialPoint() ); - original.close(true); + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + std::vector path_out; + PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in * t, 0.1), 0.001); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + bool end_open = false; + std::vector temp_path; + double timeStart = 0.0; + int position = 0; + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { + end_open = true; } - Geom::Crossings cs = crossings(original, mlineExpanded); + } + Geom::Path original = (Geom::Path)(*path_it); + if(end_open && path_it2->closed()){ + original.close(false); + original.appendNew( original.initialPoint() ); + original.close(true); + } + //for (int i = 0; i < num_copies; ++i) { + double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); + Rotate rot(rotAngle * i); + Affine t = pre * rot * Translate(origin); + Geom::Point lineEnd(0,0); + lineEnd[Geom::X] = cos((rotAngle * i) - rotAngle/2.0) * 100000.0; + lineEnd[Geom::Y] = sin((rotAngle * i) - rotAngle/2.0) * 100000.0; + Geom::Path kline; + kline.start((Geom::Point)origin); + kline.appendNew(lineEnd); + Geom::Crossings cs = crossings(original, kline); for(unsigned int i = 0; i < cs.size(); i++) { double timeEnd = cs[i].ta; Geom::Path portion = original.portion(timeStart, timeEnd); Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine(lineStart, lineEnd, middle); - Geom::line middleLine; - middleLine->setPoints(origin,middle); - if(middleLine.angle > rot && middleLine < rot2){ - Geom::Path kaleidoscope; - for (int j = 0; j < num_copies; ++j) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * j)); + position = pointSideOfLine((Geom::Point)origin, lineEnd, middle); + if(reverseFusion){ + position *= -1; + } + if(position == 1){ + for (int i = 0; i < num_copies; ++i) { + double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); + Rotate rot(rotAngle * i); Affine t = pre * rot * Translate(origin); - kaleidoscope = portion.reverse() * t); - kaleidoscope.setInitial(portion.finalPoint()); - portion.append(kaleidoscope); + Geom::Path kaleidoscope = portion * t; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); } if(i!=0){ portion.setFinal(portion.initialPoint()); @@ -174,23 +174,20 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p portion.clear(); timeStart = timeEnd; } - Geom::line middleLine; - middleLine->setPoints(origin,original.finalPoint()); - if(cs.size()!=0 && middleLine.angle > rot && middleLine < rot2){ - Geom::Path portion = original.portion(timeStart, original.size()); - portion = portion.reverse(); - - Geom::Path kaleidoscope; + position = pointSideOfLine((Geom::Point)origin, lineEnd, original.finalPoint()); + if(reverseFusion){ + position *= -1; + } + if(cs.size()!=0 && position == 1){ for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); + double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); + Rotate rot(rotAngle * i); Affine t = pre * rot * Translate(origin); - kaleidoscope = portion.reverse() * t); + Geom::Path portion = original.portion(timeStart, original.size()); + Geom::Path kaleidoscope = portion * t; kaleidoscope.setInitial(portion.finalPoint()); portion.append(kaleidoscope); } - portion = portion.reverse(); if (!original.closed()){ temp_path.push_back(portion); } else { @@ -205,22 +202,28 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } portion.clear(); } - if(cs.size() == 0 && position == 1){ - temp_path.push_back(original); - temp_path.push_back(original * m); - } - path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); - temp_path.clear(); } - output = path_out.toPwSb(); - } else { - for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); - Affine t = pre * rot * Translate(origin); - output.concat(pwd2_in * t); + if(cs.size() == 0 && position == 1){ + for (int i = 0; i < num_copies; ++i) { + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * i)); + Affine t = pre * rot * Translate(origin); + temp_path.push_back((Geom::Path)(*path_it) * t); + } } + path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); + temp_path.clear(); + if(path_out.size() > 0){ + output.concat(paths_to_pw(path_out)); + } + } else { + for (int i = 0; i < num_copies; ++i) { + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * i)); + Affine t = pre * rot * Translate(origin); + output.concat(pwd2_in * t); } } return output; -- cgit v1.2.3 From 6c067ce093126cf23d9b038011b2effa1390fd07 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 Dec 2014 23:57:43 +0100 Subject: warping into a layer (bzr r13682.1.21) --- src/live_effects/lpe-mirror_symmetry.cpp | 17 +++++++++++++++++ src/live_effects/lpe-mirror_symmetry.h | 3 +++ 2 files changed, 20 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index b0a4831f5..8df2eb176 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -55,6 +55,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), + reflectionFromPage(_("Use page as relecion base"), _("Use page as relecion base"), "reflectionFromPage", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") { @@ -64,6 +65,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter( &discard_orig_path); registerParameter( &fusionPaths); registerParameter( &reverseFusion); + registerParameter( &reflectionFromPage); registerParameter( &reflection_line); registerParameter( ¢er); @@ -73,6 +75,21 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() { } +void LPEMirrorSymmetry::doOnApply(SPLPEItem const* lpeitem) +{ + SPDocument *doc = lpeitem->document(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + sp_selection_group_impl(GSList *p, group, xml_doc, doc); + Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); + group->setAttribute("inkscape:groupmode", "layer"); + sp_selection_group_impl(p, group, xml_doc, doc); + gchar *href = g_strdup_printf("#%s", this->lpeobject_href); + SP_LPE_ITEM(group)->addPathEffect(href, true); + lpeitem->removeCurrentPathEffect(false) + g_free(href); + Inkscape::GC::release(group); +} + void LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 8c6c49c7d..6e9e7dd1a 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -44,6 +44,8 @@ public: virtual void doOnApply (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); @@ -62,6 +64,7 @@ private: BoolParam discard_orig_path; BoolParam fusionPaths; BoolParam reverseFusion; + BoolParam reflectionFromPage; PathParam reflection_line; Geom::Line lineSeparation; Geom::Point previousCenter; -- cgit v1.2.3 From 1d1ec291d89846be2dbd5ce1466b58baeb743994 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 17 Jan 2015 18:14:04 +0100 Subject: adding Kaleidoscope (bzr r13708.1.8) --- src/live_effects/lpe-copy_rotate.cpp | 164 +++++++++++++++-------------------- src/live_effects/lpe-copy_rotate.h | 6 +- 2 files changed, 73 insertions(+), 97 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 7e3e65f23..1eb1f22f2 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -50,7 +50,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copiesTo360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copiesTo360", &wr, this, true), - fusionPaths(_("Fusioned paths"), _("Fusion paths"), "fusionPaths", &wr, this, true), + kaleidoscope(_("kaleidoscope"), _("kaleidoscope"), "kaleidoscope", &wr, this, true), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), dist_angle_handle(100) @@ -60,7 +60,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter( dynamic_cast(&copiesTo360) ); - registerParameter( dynamic_cast(&fusionPaths) ); + registerParameter( dynamic_cast(&kaleidoscope) ); registerParameter( dynamic_cast(&starting_angle) ); registerParameter( dynamic_cast(&rotation_angle) ); registerParameter( dynamic_cast(&num_copies) ); @@ -91,6 +91,58 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) dist_angle_handle = L2(B - A); } +void +LPECopyRotate::split(std::vector &path_in,Geom:Path divider,bool start){ + double timeStart = 0.0; + for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + Geom::Path original = path_it; + std::vector temp_path; + Geom::Crossings cs = crossings(original, divider); + for(unsigned int i = 0; i < cs.size(); i++) { + double timeEnd = cs[i].ta; + Geom::Path portion = original.portion(timeStart, timeEnd); + Geom::Point middle = portion.pointAt((double)portion.size()/2.0); + position = pointSideOfLine(divider.initialPoint(), divider.finalPoint(), middle); + if(position == 1 || (!start && position== -1)){ + temp_path.push_back(portion); + } + portion.clear(); + timeStart = timeEnd; + } + position = pointSideOfLine(divider.initialPoint(), divider.finalPoint(), original.finalPoint()); + if(cs.size()!=0 && (position == 1 || (!start && position== -1))){ + Geom::Path portion = original.portion(timeStart, original.size()); + temp_path.push_back(portion); + portion.clear(); + } + } + path_in = temp_path; +} + +void +LPECopyRotate::setKaleidoscope(std::vector &path_in){ + Geom::Point lineStart(0,0); + lineStart[Geom::X] = cos(starting_angle) * 100000.0; + lineStart[Geom::Y] = sin(starting_angle) * 100000.0; + Geom::Point lineEnd(0,0); + lineEnd[Geom::X] = cos(starting_angle + rotAngle) * 100000.0; + lineEnd[Geom::Y] = sin(starting_angle + rotAngle) * 100000.0; + Geom::Path klineA; + klineA.start(origin); + klineA.appendNew(lineStart); + path_in = split(path_in,klineA,true); + Geom::Path klineB; + klineB.start(origin); + klineB.appendNew(lineEnd); + path_in = split(path_in,klineB,false); + for (int i = 0; i < num_copies; ++i) { + + } +} + Geom::Piecewise > LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { @@ -100,7 +152,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; double rotation_angle_end = rotation_angle; - if(copiesTo360){ + if(copiesTo360 || kaleidoscope){ rotation_angle_end = 360.0/(double)num_copies; } rot_pos = origin + dir * Rotate(-deg_to_rad(starting_angle + rotation_angle_end)) * dist_angle_handle; @@ -112,19 +164,14 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); - if(fusionPaths){ - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) + if(kaleidoscope){ std::vector path_out; + std::vector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in * t, 0.1), 0.001); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; } - bool end_open = false; - std::vector temp_path; - double timeStart = 0.0; - int position = 0; if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -137,94 +184,19 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.appendNew( original.initialPoint() ); original.close(true); } - //for (int i = 0; i < num_copies; ++i) { - double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); - Rotate rot(rotAngle * i); - Affine t = pre * rot * Translate(origin); - Geom::Point lineEnd(0,0); - lineEnd[Geom::X] = cos((rotAngle * i) - rotAngle/2.0) * 100000.0; - lineEnd[Geom::Y] = sin((rotAngle * i) - rotAngle/2.0) * 100000.0; - Geom::Path kline; - kline.start((Geom::Point)origin); - kline.appendNew(lineEnd); - Geom::Crossings cs = crossings(original, kline); - for(unsigned int i = 0; i < cs.size(); i++) { - double timeEnd = cs[i].ta; - Geom::Path portion = original.portion(timeStart, timeEnd); - Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine((Geom::Point)origin, lineEnd, middle); - if(reverseFusion){ - position *= -1; - } - if(position == 1){ - for (int i = 0; i < num_copies; ++i) { - double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); - Rotate rot(rotAngle * i); - Affine t = pre * rot * Translate(origin); - Geom::Path kaleidoscope = portion * t; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - } - if(i!=0){ - portion.setFinal(portion.initialPoint()); - portion.close(); - } - temp_path.push_back(portion); - } - portion.clear(); - timeStart = timeEnd; - } - position = pointSideOfLine((Geom::Point)origin, lineEnd, original.finalPoint()); - if(reverseFusion){ - position *= -1; - } - if(cs.size()!=0 && position == 1){ - for (int i = 0; i < num_copies; ++i) { - double rotAngle = -deg_to_rad(rotation_angle_end-starting_angle); - Rotate rot(rotAngle * i); - Affine t = pre * rot * Translate(origin); - Geom::Path portion = original.portion(timeStart, original.size()); - Geom::Path kaleidoscope = portion * t; - kaleidoscope.setInitial(portion.finalPoint()); - portion.append(kaleidoscope); - } - if (!original.closed()){ - temp_path.push_back(portion); - } else { - if(cs.size() >1 ){ - portion.setFinal(temp_path[0].initialPoint()); - portion.setInitial(temp_path[0].finalPoint()); - temp_path[0].append(portion); - } else { - temp_path.push_back(portion); - } - temp_path[0].close(); - } - portion.clear(); - } - } - if(cs.size() == 0 && position == 1){ - for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); - Affine t = pre * rot * Translate(origin); - temp_path.push_back((Geom::Path)(*path_it) * t); - } - } - path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); - temp_path.clear(); - if(path_out.size() > 0){ - output.concat(paths_to_pw(path_out)); - } + tmp_path.push_back(original); + setKaleidoscope(tmp_path); + path_out.push_back(tmp_path); + tmp_path.clear(); + } + output = path_out.toPwSb(); } else { for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); - Affine t = pre * rot * Translate(origin); - output.concat(pwd2_in * t); - } + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + Rotate rot(-deg_to_rad(rotation_angle_end * i)); + Affine t = pre * rot * Translate(origin); + output.concat(pwd2_in * t); } return output; } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 735de2300..d0ad2d6ec 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -36,6 +36,10 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + virtual void kaleidoscope(std::vector &path_in); + + virtual void split(std::vector &path_in,Geom:Path divider,bool start); + /* the knotholder entity classes must be declared friends */ friend class CR::KnotHolderEntityStartingAngle; void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); @@ -48,7 +52,7 @@ private: ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copiesTo360; - BoolParam fusionPaths; + BoolParam setKaleidoscope; PointParam origin; -- cgit v1.2.3 From 8deff8fb8acbbfa8c56db9d6e34b93523872a25b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 21 Jan 2015 00:13:00 +0100 Subject: fixing knots (bzr r13708.1.10) --- src/live_effects/lpe-copy_rotate.cpp | 236 ++++++++++++++++++++++++----------- src/live_effects/lpe-copy_rotate.h | 19 ++- 2 files changed, 179 insertions(+), 76 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 1eb1f22f2..20e08a7d8 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -24,7 +24,8 @@ #include <2geom/transforms.h> #include <2geom/d2-sbasis.h> #include <2geom/angle.h> -#include +#include <2geom/line.h> +#include #include "knot-holder-entity.h" #include "knotholder.h" @@ -41,30 +42,35 @@ public: virtual Geom::Point knot_get() const; }; +class KnotHolderEntityRotationAngle : public LPEKnotHolderEntity { +public: + KnotHolderEntityRotationAngle(LPECopyRotate *effect) : LPEKnotHolderEntity(effect) {}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; } // namespace CR LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), + origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copiesTo360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copiesTo360", &wr, this, true), - kaleidoscope(_("kaleidoscope"), _("kaleidoscope"), "kaleidoscope", &wr, this, true), - - origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), - dist_angle_handle(100) + kaleidoscope(_("kaleidoscope"), _("kaleidoscope"), "kaleidoscope", &wr, this, false), + dist_angle_handle(100.0) { show_orig_path = true; _provides_knotholder_entities = true; // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&copiesTo360) ); - registerParameter( dynamic_cast(&kaleidoscope) ); - registerParameter( dynamic_cast(&starting_angle) ); - registerParameter( dynamic_cast(&rotation_angle) ); - registerParameter( dynamic_cast(&num_copies) ); - registerParameter( dynamic_cast(&origin) ); + registerParameter(&copiesTo360); + registerParameter(&kaleidoscope); + registerParameter(&starting_angle); + registerParameter(&rotation_angle); + registerParameter(&num_copies); + registerParameter(&origin); num_copies.param_make_integer(true); num_copies.param_set_range(0, 1000); @@ -79,65 +85,117 @@ void LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) { using namespace Geom; - original_bbox(lpeitem); - Point A(boundingbox_X.min(), boundingbox_Y.middle()); - Point B(boundingbox_X.max(), boundingbox_Y.middle()); - Point C(boundingbox_X.middle(), boundingbox_Y.middle()); - origin.param_setValue(A); + A = Point(boundingbox_X.min(), boundingbox_Y.middle()); + B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); + origin.param_set_value(A); + dist_angle_handle = L2(B - A); + dir = unit_vector(B - A); +} + +void +LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) +{ + using namespace Geom; + original_bbox(lpeitem); + if( kaleidoscope || copiesTo360 ){ + rotation_angle.param_set_value(360.0/(double)num_copies); + } + A = Point(boundingbox_X.min(), boundingbox_Y.middle()); + B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); dir = unit_vector(B - A); - dist_angle_handle = L2(B - A); + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; + rot_pos = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * dist_angle_handle; + if( kaleidoscope || copiesTo360 ){ + rot_pos = origin; + } + SPLPEItem * item = const_cast(lpeitem); + item->apply_to_clippath(item); + item->apply_to_mask(item); +} + +bool +LPECopyRotate::side(Geom::Point p1, Geom::Point p2, Geom::Point p) +{ + using Geom::X; + using Geom::Y; + return (p2[Y] - p1[Y])*(p[X] - p1[X]) + (-p2[X] + p1[X])*(p[Y] - p1[Y]) >= 0; +} + +bool +LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Geom::Point p3) +{ + using Geom::X; + using Geom::Y; + double denominator = (p1[X]*(p2[Y] - p3[Y]) + p1[Y]*(p3[X] - p2[X]) + p2[X]*p3[Y] - p2[Y]*p3[X]); + double t1 = (p[X]*(p3[Y] - p1[Y]) + p[Y]*(p1[X] - p3[X]) - p1[X]*p3[Y] + p1[Y]*p3[X]) / denominator; + double t2 = (p[X]*(p2[Y] - p1[Y]) + p[Y]*(p1[X] - p2[X]) - p1[X]*p2[Y] + p1[Y]*p2[X]) / -denominator; + double s = t1 + t2; + + return 0 <= t1 && t1 <= 1 && 0 <= t2 && t2 <= 1 && s <= 1; } void -LPECopyRotate::split(std::vector &path_in,Geom:Path divider,bool start){ +LPECopyRotate::split(std::vector &path_in,Geom::Path divider){ double timeStart = 0.0; + std::vector temp_path; for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { if (path_it->empty()){ continue; } - Geom::Path original = path_it; - std::vector temp_path; + Geom::Path original = *path_it; + int position = 0; Geom::Crossings cs = crossings(original, divider); for(unsigned int i = 0; i < cs.size(); i++) { double timeEnd = cs[i].ta; Geom::Path portion = original.portion(timeStart, timeEnd); - Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine(divider.initialPoint(), divider.finalPoint(), middle); - if(position == 1 || (!start && position== -1)){ + Geom::Point sideChecker = portion.pointAt(portion.size()-0.001); + position = side(divider.initialPoint(), divider.finalPoint(), sideChecker); + if(num_copies > 2){ + position = pointInTriangle(sideChecker, divider.initialPoint(), divider[0].finalPoint(), divider.finalPoint()); + } + std::cout << position << "\n"; + if(position == true){ temp_path.push_back(portion); } portion.clear(); timeStart = timeEnd; } - position = pointSideOfLine(divider.initialPoint(), divider.finalPoint(), original.finalPoint()); - if(cs.size()!=0 && (position == 1 || (!start && position== -1))){ + position = side(divider.initialPoint(), divider.finalPoint(), original.finalPoint()); + if(num_copies > 2){ + position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider.finalPoint()); + } + if(cs.size()!=0 && position == true){ Geom::Path portion = original.portion(timeStart, original.size()); - temp_path.push_back(portion); + if (!original.closed()){ + temp_path.push_back(portion); + } else { + if(cs.size() > 1 && temp_path[0].size() > 0 ){ + portion.setFinal(temp_path[0].initialPoint()); + portion.append(temp_path[0]); + temp_path[0]=portion; + } else { + temp_path.push_back(portion); + } + //temp_path[0].close(); + } portion.clear(); } + if(cs.size()==0){ + temp_path.push_back(original); + } } path_in = temp_path; } void LPECopyRotate::setKaleidoscope(std::vector &path_in){ - Geom::Point lineStart(0,0); - lineStart[Geom::X] = cos(starting_angle) * 100000.0; - lineStart[Geom::Y] = sin(starting_angle) * 100000.0; - Geom::Point lineEnd(0,0); - lineEnd[Geom::X] = cos(starting_angle + rotAngle) * 100000.0; - lineEnd[Geom::Y] = sin(starting_angle + rotAngle) * 100000.0; - Geom::Path klineA; - klineA.start(origin); - klineA.appendNew(lineStart); - path_in = split(path_in,klineA,true); - Geom::Path klineB; - klineB.start(origin); - klineB.appendNew(lineEnd); - path_in = split(path_in,klineB,false); + + split(path_in,hp); for (int i = 0; i < num_copies; ++i) { } @@ -148,30 +206,21 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; - double rotation_angle_end = rotation_angle; - if(copiesTo360 || kaleidoscope){ - rotation_angle_end = 360.0/(double)num_copies; + if(num_copies == 1){ + return pwd2_in; } - rot_pos = origin + dir * Rotate(-deg_to_rad(starting_angle + rotation_angle_end)) * dist_angle_handle; - - A = pwd2_in.firstValue(); - B = pwd2_in.lastValue(); - dir = unit_vector(B - A); Piecewise > output; - Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(kaleidoscope){ std::vector path_out; std::vector tmp_path; - PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in * t, 0.1), 0.001); + PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; } + bool end_open = false; if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -179,24 +228,25 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } } Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it2->closed()){ + if(end_open && path_it->closed()){ original.close(false); original.appendNew( original.initialPoint() ); original.close(true); } tmp_path.push_back(original); setKaleidoscope(tmp_path); - path_out.push_back(tmp_path); + path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } - output = path_out.toPwSb(); + if(path_out.size()>0){ + output = paths_to_pw(path_out); + } } else { for (int i = 0; i < num_copies; ++i) { - // I first suspected the minus sign to be a bug in 2geom but it is - // likely due to SVG's choice of coordinate system orientation (max) - Rotate rot(-deg_to_rad(rotation_angle_end * i)); - Affine t = pre * rot * Translate(origin); - output.concat(pwd2_in * t); + Rotate rot(-deg_to_rad(rotation_angle * i)); + Affine t = pre * rot * Translate(origin); + output.concat(pwd2_in * t); + } } return output; } @@ -205,21 +255,40 @@ void LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { using namespace Geom; - - Path path(start_pos); - path.appendNew((Geom::Point) origin); - path.appendNew(rot_pos); - PathVector pathv; - pathv.push_back(path); + hp_vec.clear(); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double sizeDivider = Geom::distance(origin,bbox) + diagonal + 20; + Geom::Point lineStart = origin + dir * Rotate(-deg_to_rad(starting_angle)) * sizeDivider; + Geom::Point lineEnd = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * sizeDivider; + hp.start(lineStart); + hp.appendNew((Geom::Point)origin); + hp.appendNew(lineEnd); + Geom::PathVector pathv; + pathv.push_back(hp); hp_vec.push_back(pathv); } +void +LPECopyRotate::resetDefaults(SPItem const* item) +{ + Effect::resetDefaults(item); + original_bbox(SP_LPE_ITEM(item)); + hp.clear(); +} -void LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +void +LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { { KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the starting angle") ); + _("Adjust the starting angle")); + knotholder->add(e); + } + { + KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this); + e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the rotation angle")); knotholder->add(e); } }; @@ -248,6 +317,26 @@ KnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); } +void +KnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) +{ + LPECopyRotate* lpe = dynamic_cast(_effect); + + Geom::Point const s = snap_knot_position(p, state); + + // I first suspected the minus sign to be a bug in 2geom but it is + // likely due to SVG's choice of coordinate system orientation (max) + lpe->rotation_angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle); + if (state & GDK_SHIFT_MASK) { + lpe->dist_angle_handle = L2(lpe->B - lpe->A); + } else { + lpe->dist_angle_handle = L2(p - lpe->origin); + } + + // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); +} + Geom::Point KnotHolderEntityStartingAngle::knot_get() const { @@ -255,9 +344,14 @@ KnotHolderEntityStartingAngle::knot_get() const return lpe->start_pos; } -} // namespace CR - +Geom::Point +KnotHolderEntityRotationAngle::knot_get() const +{ + LPECopyRotate const *lpe = dynamic_cast(_effect); + return lpe->rot_pos; +} +} // namespace CR /* ######################## */ diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index d0ad2d6ec..209118925 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -36,29 +36,38 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); - virtual void kaleidoscope(std::vector &path_in); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void split(std::vector &path_in,Geom:Path divider,bool start); + virtual void setKaleidoscope(std::vector &path_in); + + virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); + + virtual bool side(Geom::Point p1, Geom::Point p2, Geom::Point p); + + virtual void split(std::vector &path_in,Geom::Path divider); + + virtual void resetDefaults(SPItem const* item); /* the knotholder entity classes must be declared friends */ friend class CR::KnotHolderEntityStartingAngle; + friend class CR::KnotHolderEntityRotationAngle; void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); protected: virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); private: + PointParam origin; ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copiesTo360; - BoolParam setKaleidoscope; - - PointParam origin; + BoolParam kaleidoscope; Geom::Point A; Geom::Point B; Geom::Point dir; + Geom::Path hp; Geom::Point start_pos; Geom::Point rot_pos; -- cgit v1.2.3 From 41368054b3da78b13a049d0020d0eeb4d8a6798d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Jan 2015 10:58:06 +0100 Subject: Added the remove for outer staff to kaleidoscope (bzr r13708.1.12) --- src/live_effects/lpe-copy_rotate.cpp | 131 ++++++++++++++++++----------------- src/live_effects/lpe-copy_rotate.h | 5 +- 2 files changed, 71 insertions(+), 65 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 20e08a7d8..1c01e2aaf 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -89,7 +89,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); - origin.param_set_value(A); + origin.param_setValue(A); dist_angle_handle = L2(B - A); dir = unit_vector(B - A); } @@ -102,7 +102,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) original_bbox(lpeitem); if( kaleidoscope || copiesTo360 ){ rotation_angle.param_set_value(360.0/(double)num_copies); - } + } + if(dist_angle_handle < 1.0){ + dist_angle_handle = 1.0; + } A = Point(boundingbox_X.min(), boundingbox_Y.middle()); B = Point(boundingbox_X.middle(), boundingbox_Y.middle()); dir = unit_vector(B - A); @@ -118,17 +121,18 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) item->apply_to_mask(item); } -bool -LPECopyRotate::side(Geom::Point p1, Geom::Point p2, Geom::Point p) +int +LPECopyRotate::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) { - using Geom::X; - using Geom::Y; - return (p2[Y] - p1[Y])*(p[X] - p1[X]) + (-p2[X] + p1[X])*(p[Y] - p1[Y]) >= 0; + //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line + double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); + return (pos < 0) ? -1 : (pos > 0); } bool LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Geom::Point p3) { + //http://totologic.blogspot.com.es/2014/01/accurate-point-in-triangle-test.html using Geom::X; using Geom::Y; double denominator = (p1[X]*(p2[Y] - p3[Y]) + p1[Y]*(p3[X] - p2[X]) + p2[X]*p3[Y] - p2[Y]*p3[X]); @@ -140,62 +144,60 @@ LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Ge } void -LPECopyRotate::split(std::vector &path_in,Geom::Path divider){ +LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ + std::vector tmp_path; double timeStart = 0.0; - std::vector temp_path; - for (Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()){ - continue; - } - Geom::Path original = *path_it; - int position = 0; - Geom::Crossings cs = crossings(original, divider); - for(unsigned int i = 0; i < cs.size(); i++) { - double timeEnd = cs[i].ta; - Geom::Path portion = original.portion(timeStart, timeEnd); - Geom::Point sideChecker = portion.pointAt(portion.size()-0.001); - position = side(divider.initialPoint(), divider.finalPoint(), sideChecker); - if(num_copies > 2){ - position = pointInTriangle(sideChecker, divider.initialPoint(), divider[0].finalPoint(), divider.finalPoint()); - } - std::cout << position << "\n"; - if(position == true){ - temp_path.push_back(portion); - } - portion.clear(); - timeStart = timeEnd; - } - position = side(divider.initialPoint(), divider.finalPoint(), original.finalPoint()); + Geom::Path original = path_on[0]; + int position = 0; + Geom::Crossings cs = crossings(original,divider); + std::vector crossed; + for(unsigned int i = 0; i < cs.size(); i++) { + crossed.push_back(cs[i].ta); + } + std::sort (crossed.begin(), crossed.end()); + for(unsigned int i = 0; i < crossed.size(); i++) { + double timeEnd = crossed[i]; + Geom::Path portionOriginal = original.portion(timeStart,timeEnd); + Geom::Point sideChecker = portionOriginal.pointAt(0.001); + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), sideChecker); if(num_copies > 2){ - position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider.finalPoint()); + position = pointInTriangle(sideChecker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } - if(cs.size()!=0 && position == true){ - Geom::Path portion = original.portion(timeStart, original.size()); - if (!original.closed()){ - temp_path.push_back(portion); + if(position == 1){ + tmp_path.push_back(portionOriginal); + } + portionOriginal.clear(); + timeStart = timeEnd; + } + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); + if(num_copies > 2){ + position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); + } + if(cs.size() > 0 && position == 1){ + Geom::Path portionOriginal = original.portion(timeStart, original.size()); + if (!original.closed()){ + tmp_path.push_back(portionOriginal); + } else { + if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ){ + portionOriginal.setFinal(tmp_path[0].initialPoint()); + portionOriginal.append(tmp_path[0]); + tmp_path[0] = portionOriginal; } else { - if(cs.size() > 1 && temp_path[0].size() > 0 ){ - portion.setFinal(temp_path[0].initialPoint()); - portion.append(temp_path[0]); - temp_path[0]=portion; - } else { - temp_path.push_back(portion); - } - //temp_path[0].close(); + tmp_path.push_back(portionOriginal); } - portion.clear(); - } - if(cs.size()==0){ - temp_path.push_back(original); + //temp_path[0].close(); } + portionOriginal.clear(); + } + if(cs.size()==0 && position == 1){ + tmp_path.push_back(original); } - path_in = temp_path; + path_on = tmp_path; } void -LPECopyRotate::setKaleidoscope(std::vector &path_in){ - - split(path_in,hp); +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider){ + split(path_on,divider); for (int i = 0; i < num_copies; ++i) { } @@ -210,6 +212,16 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p return pwd2_in; } + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double sizeDivider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point lineStart = origin + dir * Rotate(-deg_to_rad(starting_angle)) * sizeDivider; + Geom::Point lineEnd = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * sizeDivider; + //Note:: beter way to do this + //Whith AppendNew have problems whith the crossing order + Geom::Path divider = Geom::Path(lineStart); + divider.appendNew((Geom::Point)origin); + divider.appendNew(lineEnd); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(kaleidoscope){ @@ -234,7 +246,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path); + setKaleidoscope(tmp_path,divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } @@ -256,14 +268,10 @@ LPECopyRotate::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector((Geom::Point)origin); - hp.appendNew(lineEnd); + hp.appendNew(origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * dist_angle_handle); Geom::PathVector pathv; pathv.push_back(hp); hp_vec.push_back(pathv); @@ -274,7 +282,6 @@ LPECopyRotate::resetDefaults(SPItem const* item) { Effect::resetDefaults(item); original_bbox(SP_LPE_ITEM(item)); - hp.clear(); } void diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 209118925..78e3b1950 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,11 +38,11 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in); + virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); - virtual bool side(Geom::Point p1, Geom::Point p2, Geom::Point p); + virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); virtual void split(std::vector &path_in,Geom::Path divider); @@ -67,7 +67,6 @@ private: Geom::Point A; Geom::Point B; Geom::Point dir; - Geom::Path hp; Geom::Point start_pos; Geom::Point rot_pos; -- cgit v1.2.3 From d1a09f4fd642b79542401c6e4eb83e79369c0f9b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Jan 2015 11:08:58 +0100 Subject: added missing header from a merge (bzr r13708.1.14) --- src/live_effects/lpe-copy_rotate.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 35b5c1eb2..d1022dbc2 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -13,7 +13,8 @@ #include #include - +#include <2geom/path-intersection.h> +#include <2geom/sbasis-to-bezier.h> #include "live_effects/lpe-copy_rotate.h" #include <2geom/path.h> #include <2geom/transforms.h> @@ -191,8 +192,13 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ void LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider){ split(path_on,divider); - for (int i = 0; i < num_copies; ++i) { - + for (Geom::PathVector::const_iterator path_it = path_on.begin(); path_it != path_on.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + for (int i = 0; i < num_copies; ++i) { + + } } } -- cgit v1.2.3 From 8d82767ca9ff65622eac487afd6aeba78713add5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Jan 2015 12:40:19 +0100 Subject: reverting to non wroken branch (bzr r13708.1.15) --- src/live_effects/lpe-copy_rotate.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index d1022dbc2..3103d8293 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -192,12 +192,17 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ void LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider){ split(path_on,divider); + Geom::Affine pre = Geom::Translate(-origin) * Geom::Rotate(-Geom::deg_to_rad(starting_angle)); for (Geom::PathVector::const_iterator path_it = path_on.begin(); path_it != path_on.end(); ++path_it) { if (path_it->empty()){ continue; } for (int i = 0; i < num_copies; ++i) { - + Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * i)); + Geom::Affine t = pre * rot * Geom::Translate(origin); + Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + Geom::Path append = *path_it * sca * t; + path_on.push_back(append); } } } -- cgit v1.2.3 From 2218eee67d0032e118cb711b7c612f7b580a6294 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 24 Jan 2015 18:11:22 +0100 Subject: Kaleidoscope check (bzr r13708.1.16) --- src/live_effects/lpe-copy_rotate.cpp | 70 +++++++++++++++++++++++++++++------- src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 59 insertions(+), 13 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3103d8293..6c16c6194 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -94,9 +94,18 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if( kaleidoscope || copiesTo360 ){ + if(kaleidoscope || copiesTo360 ){ rotation_angle.param_set_value(360.0/(double)num_copies); } + if(kaleidoscope){ + num_copies.param_set_increments(2,2); + if((int)num_copies%2 !=0){ + num_copies.param_set_value(num_copies+1); + } + } else { + num_copies.param_set_increments(1,1); + } + if(dist_angle_handle < 1.0){ dist_angle_handle = 1.0; } @@ -190,21 +199,58 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider){ +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double sizeDivider){ split(path_on,divider); - Geom::Affine pre = Geom::Translate(-origin) * Geom::Rotate(-Geom::deg_to_rad(starting_angle)); + std::vector tmp_path; + Geom::Affine pre = Geom::Translate(-origin); for (Geom::PathVector::const_iterator path_it = path_on.begin(); path_it != path_on.end(); ++path_it) { - if (path_it->empty()){ - continue; - } - for (int i = 0; i < num_copies; ++i) { - Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * i)); - Geom::Affine t = pre * rot * Geom::Translate(origin); + Geom::Path original = *path_it; + if (path_it->empty()){ + continue; + } + std::vector tmp_path2; + Geom::Path appendPath = original; + for (int i = 0; i < num_copies; ++i) { + Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * (i))); + Geom::Affine m = pre * rot * Geom::Translate(origin); + if(i%2 != 0){ + Geom::Point A = (Geom::Point)origin; + Geom::Point B = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle*i)+starting_angle)) * sizeDivider; + Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); + double hyp = Geom::distance(A, B); + double c = (B[0] - A[0]) / hyp; // cos(alpha) + double s = (B[1] - A[1]) / hyp; // sin(alpha) + + Geom::Affine m2(c, -s, s, c, 0.0, 0.0); Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); - Geom::Path append = *path_it * sca * t; - path_on.push_back(append); + + Geom::Affine tmpM = m1.inverse() * m2; + m = tmpM; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + } else { + appendPath = original; } + appendPath *= m; + if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.finalPoint())){ + tmp_path2[tmp_path2.size()-1].append(appendPath.reverse()); + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.initialPoint())){ + tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); + tmp_path2[tmp_path2.size()-1].append(appendPath); + tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); + } else { + tmp_path2.push_back(appendPath); + } + if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),tmp_path2[tmp_path2.size()-1].initialPoint())){ + tmp_path2[tmp_path2.size()-1].close(); + } + } + tmp_path.insert(tmp_path.end(), tmp_path2.begin(), tmp_path2.end()); + tmp_path2.clear(); } + path_on = tmp_path; + tmp_path.clear(); } Geom::Piecewise > @@ -250,7 +296,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider); + setKaleidoscope(tmp_path,divider,sizeDivider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 78e3b1950..bdbc61d07 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider); + virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); -- cgit v1.2.3 From bccbad7c2400905a823f9241294fa62e90c9a6a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 18 Mar 2015 21:41:04 +0100 Subject: fix to trunk (bzr r13682.1.24) --- src/live_effects/effect.cpp | 9 +----- src/live_effects/effect.h | 1 - src/live_effects/lpe-mirror_symmetry.cpp | 47 ++++++++++---------------------- src/live_effects/lpe-mirror_symmetry.h | 2 +- 4 files changed, 16 insertions(+), 43 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 5cff0f352..042bac523 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -373,7 +373,6 @@ Effect::Effect(LivePathEffectObject *lpeobject) registerParameter( dynamic_cast(&is_visible) ); is_visible.widget_is_visible = false; current_zoom = 0.0; - knot_holder = NULL; } Effect::~Effect() @@ -620,7 +619,7 @@ Effect::registerParameter(Parameter * param) void Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { using namespace Inkscape::LivePathEffect; - knot_holder = knotholder; + // add handles provided by the effect itself addKnotHolderEntities(knotholder, desktop, item); @@ -630,12 +629,6 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { } } -void -Effect::removeHandles(){ - if(knot_holder){ - knot_holder = NULL; - } -} /** * Return a vector of PathVectors which contain all canvas indicators for this effect. * This is the function called by external code to get all canvas indicators (effect and its parameters) diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index bfce7b7dd..ac1f0b8dc 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -101,7 +101,6 @@ public: // (but spiro lpe still needs it!) virtual LPEPathFlashType pathFlashType() const { return DEFAULT; } void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void removeHandles(); std::vector getCanvasIndicators(SPLPEItem const* lpeitem); inline bool providesOwnFlashPaths() const { diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f39b92e58..e549ad697 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -27,7 +27,6 @@ #include "knot-holder-entity.h" #include "knotholder.h" - namespace Inkscape { namespace LivePathEffect { @@ -43,9 +42,12 @@ namespace MS { class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {}; + KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {this->knoth = effect->knoth;}; + virtual ~KnotHolderEntityCenterMirrorSymmetry() { this->knoth = NULL;} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; +private: + KnotHolder *knoth; }; } // namespace MS @@ -56,19 +58,19 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), - fixedReflectionLine(_("Fixed reflection line"), _("Fixed reflection line"), "fixedReflectionLine", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), - center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") + center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring"), + knoth(NULL) { show_orig_path = true; + registerParameter(&mode); registerParameter( &discard_orig_path); registerParameter( &fusionPaths); registerParameter( &reverseFusion); - registerParameter( &distanceToX); - registerParameter( &distanceToY); registerParameter( &reflection_line); registerParameter( ¢er); + } LPEMirrorSymmetry::~LPEMirrorSymmetry() @@ -81,7 +83,6 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; SPLPEItem * item = const_cast(lpeitem); - SPObject *subitem = static_cast(item); Point A(boundingbox_X.max(), boundingbox_Y.min()); Point B(boundingbox_X.max(), boundingbox_Y.max()); Point C(boundingbox_X.max(), boundingbox_Y.middle()); @@ -93,15 +94,15 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) A = Geom::Point(center[X],boundingbox_Y.min()); B = Geom::Point(center[X],boundingbox_Y.max()); } - if( mode == MT_X || mode == MT_Y || mode == MT_FIXED_X || mode == MT_FIXED_Y ){ + if( mode == MT_X || mode == MT_Y ){ Geom::Path path; path.start( A ); path.appendNew( B ); reflection_line.set_new_value(path.toPwSb(), true); lineSeparation.setPoints(A,B); center.param_setValue(path.pointAt(0.5)); - if(knot_holder){ - knot_holder->update_knots(); + if(knoth){ + knoth->update_knots(); } } else if( mode == MT_FREE) { std::vector mline(reflection_line.get_pathvector()); @@ -117,8 +118,8 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) A = mline[0].initialPoint(); B = mline[0].finalPoint(); lineSeparation.setPoints(A,B); - if(knot_holder){ - knot_holder->update_knots(); + if(knoth){ + knoth->update_knots(); } } previousCenter = center; @@ -133,27 +134,6 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { using namespace Geom; - /* - SPDocument *doc = lpeitem->document; - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); - Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); - group->setAttribute("inkscape:groupmode", "layer"); - SPLPEItem* item = const_cast(lpeitem); - Inkscape::XML::Node *current = item->getRepr(); - gint topmost = current->position(); - Inkscape::XML::Node *top_current = current->parent(); - Inkscape::XML::Node *spnew = current->duplicate(xml_doc); - sp_repr_unparent(current); - group->appendChild(spnew); - Inkscape::GC::release(spnew); - top_current->appendChild(group); - group->setPosition(topmost + 1); - gchar *href = g_strdup_printf("#%s", item->getCurrentLPE()->getRepr()->attribute("id")); - SP_LPE_ITEM(group)->addPathEffect(href, true); - item->removeCurrentPathEffect(false); - g_free(href); - Inkscape::GC::release(group); - */ original_bbox(lpeitem); Point A(boundingbox_X.max(), boundingbox_Y.min()); @@ -315,6 +295,7 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector void LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { { + knoth = knotholder; KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the center") ); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index c18fb265d..97d641bcc 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -62,11 +62,11 @@ private: BoolParam discard_orig_path; BoolParam fusionPaths; BoolParam reverseFusion; - BoolParam fixedReflectionLine; PathParam reflection_line; Geom::Line lineSeparation; Geom::Point previousCenter; PointParam center; + KnotHolder *knoth; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From b21958f914e82435e935bb732b64cdf3f685c3f1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Mar 2015 14:57:06 +0100 Subject: adding rotation transform (bzr r13708.1.20) --- src/live_effects/lpe-copy_rotate.cpp | 18 ++++++++++++++++++ src/live_effects/lpe-copy_rotate.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 63d6b8bfa..5474bfb70 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -89,6 +89,24 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) dir = unit_vector(B - A); } +void +LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) +{ + if(postmul->isRotation()){ + Geom::Point rot = (Geom::Rotate)postmul::vector(); + coord angle = rad_to_deg(atan2(rot)); + starting_angle.param_setValue(starting_angle + angle); + starting_angle.param_update_default(starting_angle + angle); + rotation_angle.param_setValue(rotation_angle + angle); + rotation_angle.param_update_default(rotation_angle + angle); + } + // cycle through all parameters. Most parameters will not need transformation, but path and point params do. + + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { + Parameter * param = *it; + param->param_transform_multiply(postmul, set); + } +} void LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index bdbc61d07..d0a5b004b 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -48,6 +48,8 @@ public: virtual void resetDefaults(SPItem const* item); + virtual void transform_multiply(Geom::Affine const& postmul, bool set); + /* the knotholder entity classes must be declared friends */ friend class CR::KnotHolderEntityStartingAngle; friend class CR::KnotHolderEntityRotationAngle; -- cgit v1.2.3 From 2763fbcc2619a390e5f81c2887b1f8f312eb5e65 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Mar 2015 22:04:40 +0100 Subject: Allow rotate copies whithout distorsion in kaleidoscope shapes (bzr r13708.1.22) --- src/live_effects/lpe-copy_rotate.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 5474bfb70..2e87133b3 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -92,13 +92,10 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(postmul->isRotation()){ - Geom::Point rot = (Geom::Rotate)postmul::vector(); - coord angle = rad_to_deg(atan2(rot)); - starting_angle.param_setValue(starting_angle + angle); - starting_angle.param_update_default(starting_angle + angle); - rotation_angle.param_setValue(rotation_angle + angle); - rotation_angle.param_update_default(rotation_angle + angle); + if(kaleidoscope){ + Geom::Coord angle = Geom::rad_to_deg(atan(-postmul[1]/postmul[0])); + angle += starting_angle; + starting_angle.param_set_value(angle); } // cycle through all parameters. Most parameters will not need transformation, but path and point params do. -- cgit v1.2.3 From 1973e31feb91e5a2bbdd1c3e36b20d1681123447 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 9 Apr 2015 21:01:46 +0200 Subject: astyle copy-rotate LPE (bzr r13708.1.25) --- src/live_effects/lpe-copy_rotate.cpp | 77 +++++++++++++++++++----------------- src/live_effects/lpe-copy_rotate.h | 6 +-- 2 files changed, 43 insertions(+), 40 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 2e87133b3..bb331b37a 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -65,7 +65,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : registerParameter(&rotation_angle); registerParameter(&num_copies); registerParameter(&origin); - + num_copies.param_make_integer(true); num_copies.param_set_range(0, 1000); } @@ -92,13 +92,13 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(kaleidoscope){ + if(kaleidoscope) { Geom::Coord angle = Geom::rad_to_deg(atan(-postmul[1]/postmul[0])); angle += starting_angle; starting_angle.param_set_value(angle); } // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - + for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); @@ -110,19 +110,19 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if(kaleidoscope || copiesTo360 ){ + if(kaleidoscope || copiesTo360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if(kaleidoscope){ + if(kaleidoscope) { num_copies.param_set_increments(2,2); - if((int)num_copies%2 !=0){ + if((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); } } else { num_copies.param_set_increments(1,1); } - if(dist_angle_handle < 1.0){ + if(dist_angle_handle < 1.0) { dist_angle_handle = 1.0; } A = Point(boundingbox_X.min(), boundingbox_Y.middle()); @@ -132,7 +132,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * dist_angle_handle; - if( kaleidoscope || copiesTo360 ){ + if( kaleidoscope || copiesTo360 ) { rot_pos = origin; } SPLPEItem * item = const_cast(lpeitem); @@ -140,7 +140,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) item->apply_to_mask(item); } -int +int LPECopyRotate::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) { //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line @@ -163,7 +163,8 @@ LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Ge } void -LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ +LPECopyRotate::split(std::vector &path_on,Geom::Path divider) +{ std::vector tmp_path; double timeStart = 0.0; Geom::Path original = path_on[0]; @@ -179,25 +180,25 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ Geom::Path portionOriginal = original.portion(timeStart,timeEnd); Geom::Point sideChecker = portionOriginal.pointAt(0.001); position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), sideChecker); - if(num_copies > 2){ + if(num_copies > 2) { position = pointInTriangle(sideChecker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } - if(position == 1){ + if(position == 1) { tmp_path.push_back(portionOriginal); } portionOriginal.clear(); timeStart = timeEnd; } position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); - if(num_copies > 2){ + if(num_copies > 2) { position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } - if(cs.size() > 0 && position == 1){ + if(cs.size() > 0 && position == 1) { Geom::Path portionOriginal = original.portion(timeStart, original.size()); - if (!original.closed()){ + if (!original.closed()) { tmp_path.push_back(portionOriginal); } else { - if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ){ + if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { portionOriginal.setFinal(tmp_path[0].initialPoint()); portionOriginal.append(tmp_path[0]); tmp_path[0] = portionOriginal; @@ -208,20 +209,21 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider){ } portionOriginal.clear(); } - if(cs.size()==0 && position == 1){ + if(cs.size()==0 && position == 1) { tmp_path.push_back(original); } path_on = tmp_path; } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double sizeDivider){ +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double sizeDivider) +{ split(path_on,divider); std::vector tmp_path; Geom::Affine pre = Geom::Translate(-origin); for (Geom::PathVector::const_iterator path_it = path_on.begin(); path_it != path_on.end(); ++path_it) { Geom::Path original = *path_it; - if (path_it->empty()){ + if (path_it->empty()) { continue; } std::vector tmp_path2; @@ -229,7 +231,7 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi for (int i = 0; i < num_copies; ++i) { Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); - if(i%2 != 0){ + if(i%2 != 0) { Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle*i)+starting_angle)) * sizeDivider; Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); @@ -249,44 +251,44 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi appendPath = original; } appendPath *= m; - if(i != 0 && tmp_path2.size() > 0 &&( Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.finalPoint()))){ + if(i != 0 && tmp_path2.size() > 0 &&( Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.finalPoint()))) { Geom::Path tmpAppend = appendPath.reverse(); tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); tmp_path2[tmp_path2.size()-1].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.initialPoint())){ + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.initialPoint())) { Geom::Path tmpAppend = appendPath; tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); tmp_path2[tmp_path2.size()-1].append(tmpAppend); tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.initialPoint())){ + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.initialPoint())) { Geom::Path tmpAppend = appendPath; tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); tmp_path2[tmp_path2.size()-1].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.finalPoint())){ + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.finalPoint())) { Geom::Path tmpAppend = appendPath.reverse(); tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); tmp_path2[tmp_path2.size()-1].append(tmpAppend); tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),appendPath.finalPoint())){ + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),appendPath.finalPoint())) { Geom::Path tmpAppend = appendPath.reverse(); tmpAppend.setInitial(tmp_path2[0].finalPoint()); tmp_path2[0].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].initialPoint(),appendPath.initialPoint())){ + } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].initialPoint(),appendPath.initialPoint())) { Geom::Path tmpAppend = appendPath; tmp_path2[0] = tmp_path2[0].reverse(); tmpAppend.setInitial(tmp_path2[0].finalPoint()); tmp_path2[0].append(tmpAppend); tmp_path2[0] = tmp_path2[0].reverse(); - } else { + } else { tmp_path2.push_back(appendPath); } - if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),tmp_path2[tmp_path2.size()-1].initialPoint())){ + if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),tmp_path2[tmp_path2.size()-1].initialPoint())) { tmp_path2[tmp_path2.size()-1].close(); } } - if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),tmp_path2[0].initialPoint())){ + if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),tmp_path2[0].initialPoint())) { tmp_path2[0].close(); } tmp_path.insert(tmp_path.end(), tmp_path2.begin(), tmp_path2.end()); @@ -301,12 +303,12 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if(num_copies == 1){ + if(num_copies == 1) { return pwd2_in; } double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double sizeDivider = Geom::distance(origin,bbox) + (diagonal * 2); Geom::Point lineStart = origin + dir * Rotate(-deg_to_rad(starting_angle)) * sizeDivider; Geom::Point lineEnd = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * sizeDivider; @@ -317,12 +319,12 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p divider.appendNew(lineEnd); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); - if(kaleidoscope){ + if(kaleidoscope) { std::vector path_out; std::vector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ + if (path_it->empty()) { continue; } bool end_open = false; @@ -333,7 +335,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } } Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()){ + if(end_open && path_it->closed()) { original.close(false); original.appendNew( original.initialPoint() ); original.close(true); @@ -343,7 +345,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } - if(path_out.size()>0){ + if(path_out.size()>0) { output = paths_to_pw(path_out); } } else { @@ -377,8 +379,9 @@ LPECopyRotate::resetDefaults(SPItem const* item) original_bbox(SP_LPE_ITEM(item)); } -void -LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +void +LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ { KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this); e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index d0a5b004b..de00226a4 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -22,9 +22,9 @@ namespace Inkscape { namespace LivePathEffect { namespace CR { - // we need a separate namespace to avoid clashes with LPEPerpBisector - class KnotHolderEntityStartingAngle; - class KnotHolderEntityRotationAngle; +// we need a separate namespace to avoid clashes with LPEPerpBisector +class KnotHolderEntityStartingAngle; +class KnotHolderEntityRotationAngle; } class LPECopyRotate : public Effect, GroupBBoxEffect { -- cgit v1.2.3 From d163d3b01c24671f3124c16455d8654d7a1523f7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 9 Apr 2015 21:13:54 +0200 Subject: Rename some variables to fit coding style (bzr r13708.1.26) --- src/live_effects/lpe-copy_rotate.cpp | 136 +++++++++++++++++------------------ src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 69 insertions(+), 69 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index bb331b37a..4fd605b6d 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -51,7 +51,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), - copiesTo360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copiesTo360", &wr, this, true), + copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), kaleidoscope(_("kaleidoscope"), _("kaleidoscope"), "kaleidoscope", &wr, this, false), dist_angle_handle(100.0) { @@ -59,7 +59,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : _provides_knotholder_entities = true; // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter(&copiesTo360); + registerParameter(&copies_to_360); registerParameter(&kaleidoscope); registerParameter(&starting_angle); registerParameter(&rotation_angle); @@ -110,7 +110,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if(kaleidoscope || copiesTo360 ) { + if(kaleidoscope || copies_to_360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } if(kaleidoscope) { @@ -132,7 +132,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * dist_angle_handle; - if( kaleidoscope || copiesTo360 ) { + if( kaleidoscope || copies_to_360 ) { rot_pos = origin; } SPLPEItem * item = const_cast(lpeitem); @@ -166,7 +166,7 @@ void LPECopyRotate::split(std::vector &path_on,Geom::Path divider) { std::vector tmp_path; - double timeStart = 0.0; + double time_start = 0.0; Geom::Path original = path_on[0]; int position = 0; Geom::Crossings cs = crossings(original,divider); @@ -177,37 +177,37 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) std::sort (crossed.begin(), crossed.end()); for(unsigned int i = 0; i < crossed.size(); i++) { double timeEnd = crossed[i]; - Geom::Path portionOriginal = original.portion(timeStart,timeEnd); - Geom::Point sideChecker = portionOriginal.pointAt(0.001); - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), sideChecker); + Geom::Path portion_original = original.portion(time_start,timeEnd); + Geom::Point side_checker = portion_original.pointAt(0.001); + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); if(num_copies > 2) { - position = pointInTriangle(sideChecker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); + position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if(position == 1) { - tmp_path.push_back(portionOriginal); + tmp_path.push_back(portion_original); } - portionOriginal.clear(); - timeStart = timeEnd; + portion_original.clear(); + time_start = timeEnd; } position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); if(num_copies > 2) { position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if(cs.size() > 0 && position == 1) { - Geom::Path portionOriginal = original.portion(timeStart, original.size()); + Geom::Path portion_original = original.portion(time_start, original.size()); if (!original.closed()) { - tmp_path.push_back(portionOriginal); + tmp_path.push_back(portion_original); } else { if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { - portionOriginal.setFinal(tmp_path[0].initialPoint()); - portionOriginal.append(tmp_path[0]); - tmp_path[0] = portionOriginal; + portion_original.setFinal(tmp_path[0].initialPoint()); + portion_original.append(tmp_path[0]); + tmp_path[0] = portion_original; } else { - tmp_path.push_back(portionOriginal); + tmp_path.push_back(portion_original); } //temp_path[0].close(); } - portionOriginal.clear(); + portion_original.clear(); } if(cs.size()==0 && position == 1) { tmp_path.push_back(original); @@ -216,7 +216,7 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double sizeDivider) +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double size_divider) { split(path_on,divider); std::vector tmp_path; @@ -226,14 +226,14 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi if (path_it->empty()) { continue; } - std::vector tmp_path2; - Geom::Path appendPath = original; + std::vector tmp_path_helper; + Geom::Path append_path = original; for (int i = 0; i < num_copies; ++i) { Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); if(i%2 != 0) { Geom::Point A = (Geom::Point)origin; - Geom::Point B = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle*i)+starting_angle)) * sizeDivider; + Geom::Point B = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle*i)+starting_angle)) * size_divider; Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); double hyp = Geom::distance(A, B); double c = (B[0] - A[0]) / hyp; // cos(alpha) @@ -248,51 +248,51 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi m = m * m2.inverse(); m = m * m1; } else { - appendPath = original; + append_path = original; } - appendPath *= m; - if(i != 0 && tmp_path2.size() > 0 &&( Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.finalPoint()))) { - Geom::Path tmpAppend = appendPath.reverse(); - tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); - tmp_path2[tmp_path2.size()-1].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.initialPoint())) { - Geom::Path tmpAppend = appendPath; - tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); - tmp_path2[tmp_path2.size()-1].append(tmpAppend); - tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),appendPath.initialPoint())) { - Geom::Path tmpAppend = appendPath; - tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); - tmp_path2[tmp_path2.size()-1].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].initialPoint(),appendPath.finalPoint())) { - Geom::Path tmpAppend = appendPath.reverse(); - tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - tmpAppend.setInitial(tmp_path2[tmp_path2.size()-1].finalPoint()); - tmp_path2[tmp_path2.size()-1].append(tmpAppend); - tmp_path2[tmp_path2.size()-1] = tmp_path2[tmp_path2.size()-1].reverse(); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),appendPath.finalPoint())) { - Geom::Path tmpAppend = appendPath.reverse(); - tmpAppend.setInitial(tmp_path2[0].finalPoint()); - tmp_path2[0].append(tmpAppend); - } else if(i != 0 && tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].initialPoint(),appendPath.initialPoint())) { - Geom::Path tmpAppend = appendPath; - tmp_path2[0] = tmp_path2[0].reverse(); - tmpAppend.setInitial(tmp_path2[0].finalPoint()); - tmp_path2[0].append(tmpAppend); - tmp_path2[0] = tmp_path2[0].reverse(); + append_path *= m; + if(i != 0 && tmp_path_helper.size() > 0 &&( Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.finalPoint()))) { + Geom::Path tmp_append = append_path.reverse(); + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.finalPoint())) { + Geom::Path tmp_append = append_path.reverse(); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),append_path.finalPoint())) { + Geom::Path tmp_append = append_path.reverse(); + tmp_append.setInitial(tmp_path_helper[0].finalPoint()); + tmp_path_helper[0].append(tmp_append); + } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].initialPoint(),append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + tmp_path_helper[0] = tmp_path_helper[0].reverse(); + tmp_append.setInitial(tmp_path_helper[0].finalPoint()); + tmp_path_helper[0].append(tmp_append); + tmp_path_helper[0] = tmp_path_helper[0].reverse(); } else { - tmp_path2.push_back(appendPath); + tmp_path_helper.push_back(append_path); } - if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[tmp_path2.size()-1].finalPoint(),tmp_path2[tmp_path2.size()-1].initialPoint())) { - tmp_path2[tmp_path2.size()-1].close(); + if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),tmp_path_helper[tmp_path_helper.size()-1].initialPoint())) { + tmp_path_helper[tmp_path_helper.size()-1].close(); } } - if(tmp_path2.size() > 0 && Geom::are_near(tmp_path2[0].finalPoint(),tmp_path2[0].initialPoint())) { - tmp_path2[0].close(); + if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),tmp_path_helper[0].initialPoint())) { + tmp_path_helper[0].close(); } - tmp_path.insert(tmp_path.end(), tmp_path2.begin(), tmp_path2.end()); - tmp_path2.clear(); + tmp_path.insert(tmp_path.end(), tmp_path_helper.begin(), tmp_path_helper.end()); + tmp_path_helper.clear(); } path_on = tmp_path; tmp_path.clear(); @@ -309,14 +309,14 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - double sizeDivider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point lineStart = origin + dir * Rotate(-deg_to_rad(starting_angle)) * sizeDivider; - Geom::Point lineEnd = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * sizeDivider; + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point line_start = origin + dir * Rotate(-deg_to_rad(starting_angle)) * size_divider; + Geom::Point line_end = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * size_divider; //Note:: beter way to do this //Whith AppendNew have problems whith the crossing order - Geom::Path divider = Geom::Path(lineStart); + Geom::Path divider = Geom::Path(line_start); divider.appendNew((Geom::Point)origin); - divider.appendNew(lineEnd); + divider.appendNew(line_end); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(kaleidoscope) { @@ -341,7 +341,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider,sizeDivider); + setKaleidoscope(tmp_path,divider,size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index de00226a4..83f4a6984 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -63,7 +63,7 @@ private: ScalarParam starting_angle; ScalarParam rotation_angle; ScalarParam num_copies; - BoolParam copiesTo360; + BoolParam copies_to_360; BoolParam kaleidoscope; Geom::Point A; -- cgit v1.2.3 From a34915d4a9af00a7bf4fe7fdc20dcadbaf619edd Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 10 Apr 2015 22:11:17 +0200 Subject: Fix coding style issues in mirror symmetry code (bzr r13682.1.25) --- src/live_effects/lpe-mirror_symmetry.cpp | 179 ++++++++++++++++--------------- src/live_effects/lpe-mirror_symmetry.h | 14 +-- 2 files changed, 100 insertions(+), 93 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index e549ad697..5bae6738b 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -42,8 +42,14 @@ namespace MS { class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {this->knoth = effect->knoth;}; - virtual ~KnotHolderEntityCenterMirrorSymmetry() { this->knoth = NULL;} + KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) + { + this->knoth = effect->knoth; + }; + virtual ~KnotHolderEntityCenterMirrorSymmetry() + { + this->knoth = NULL; + } virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; private: @@ -56,8 +62,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true), - reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false), + fusion_paths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusion_paths", &wr, this, true), + reverse_fusion(_("Reverse fusion"), _("Reverse fusion"), "reverse_fusion", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring"), knoth(NULL) @@ -66,8 +72,8 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : registerParameter(&mode); registerParameter( &discard_orig_path); - registerParameter( &fusionPaths); - registerParameter( &reverseFusion); + registerParameter( &fusion_paths); + registerParameter( &reverse_fusion); registerParameter( &reflection_line); registerParameter( ¢er); @@ -83,46 +89,46 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) using namespace Geom; SPLPEItem * item = const_cast(lpeitem); - Point A(boundingbox_X.max(), boundingbox_Y.min()); - Point B(boundingbox_X.max(), boundingbox_Y.max()); - Point C(boundingbox_X.max(), boundingbox_Y.middle()); - if(mode == MT_Y){ - A = Geom::Point(boundingbox_X.min(),center[Y]); - B = Geom::Point(boundingbox_X.max(),center[Y]); + Point point_a(boundingbox_X.max(), boundingbox_Y.min()); + Point point_b(boundingbox_X.max(), boundingbox_Y.max()); + Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); + if(mode == MT_Y) { + point_a = Geom::Point(boundingbox_X.min(),center[Y]); + point_b = Geom::Point(boundingbox_X.max(),center[Y]); } - if(mode == MT_X){ - A = Geom::Point(center[X],boundingbox_Y.min()); - B = Geom::Point(center[X],boundingbox_Y.max()); + if(mode == MT_X) { + point_a = Geom::Point(center[X],boundingbox_Y.min()); + point_b = Geom::Point(center[X],boundingbox_Y.max()); } - if( mode == MT_X || mode == MT_Y ){ + if( mode == MT_X || mode == MT_Y ) { Geom::Path path; - path.start( A ); - path.appendNew( B ); + path.start( point_a ); + path.appendNew( point_b ); reflection_line.set_new_value(path.toPwSb(), true); - lineSeparation.setPoints(A,B); + line_separation.setPoints(point_a, point_b); center.param_setValue(path.pointAt(0.5)); - if(knoth){ + if(knoth) { knoth->update_knots(); } } else if( mode == MT_FREE) { - std::vector mline(reflection_line.get_pathvector()); - if(!are_near(previousCenter,center, 0.01)){ - Geom::Point trans = center - mline[0].pointAt(0.5); - mline[0] *= Geom::Affine(1,0,0,1,trans[X],trans[Y]); - A = mline[0].initialPoint(); - B = mline[0].finalPoint(); - reflection_line.set_new_value(mline[0].toPwSb(), true); - lineSeparation.setPoints(A,B); + std::vector line_m(reflection_line.get_pathvector()); + if(!are_near(previous_center,center, 0.01)) { + Geom::Point trans = center - line_m[0].pointAt(0.5); + line_m[0] *= Geom::Affine(1,0,0,1,trans[X],trans[Y]); + point_a = line_m[0].initialPoint(); + point_b = line_m[0].finalPoint(); + reflection_line.set_new_value(line_m[0].toPwSb(), true); + line_separation.setPoints(point_a, point_b); } else { - center.param_setValue(mline[0].pointAt(0.5)); - A = mline[0].initialPoint(); - B = mline[0].finalPoint(); - lineSeparation.setPoints(A,B); - if(knoth){ + center.param_setValue(line_m[0].pointAt(0.5)); + point_a = line_m[0].initialPoint(); + point_b = line_m[0].finalPoint(); + line_separation.setPoints(point_a, point_b); + if(knoth) { knoth->update_knots(); } } - previousCenter = center; + previous_center = center; } item->apply_to_clippath(item); @@ -136,22 +142,22 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) original_bbox(lpeitem); - Point A(boundingbox_X.max(), boundingbox_Y.min()); - Point B(boundingbox_X.max(), boundingbox_Y.max()); - Point C(boundingbox_X.max(), boundingbox_Y.middle()); + Point point_a(boundingbox_X.max(), boundingbox_Y.min()); + Point point_b(boundingbox_X.max(), boundingbox_Y.max()); + Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); Geom::Path path; - path.start( A ); - path.appendNew( B ); + path.start( point_a ); + path.appendNew( point_b ); reflection_line.set_new_value(path.toPwSb(), true); - center.param_setValue(C); - previousCenter = center; + center.param_setValue(point_c); + previous_center = center; } -int -LPEMirrorSymmetry::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) +int +LPEMirrorSymmetry::pointSideOfLine(Geom::Point point_a, Geom::Point point_b, Geom::Point point_x) { //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); + double pos = (point_b[Geom::X]-point_a[Geom::X])*(point_x[Geom::Y]-point_a[Geom::Y]) - (point_b[Geom::Y]-point_a[Geom::Y])*(point_x[Geom::X]-point_a[Geom::X]); return (pos < 0) ? -1 : (pos > 0); } @@ -164,23 +170,23 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); std::vector path_out; - Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( lineEnd); + Geom::Path line_m_expanded; + Geom::Point line_start = line_separation.pointAt(-100000.0); + Geom::Point line_end = line_separation.pointAt(100000.0); + line_m_expanded.start( line_start); + line_m_expanded.appendNew( line_end); - if (!discard_orig_path && !fusionPaths) { + if (!discard_orig_path && !fusion_paths) { path_out = path_in; } - Geom::Point A(lineStart); - Geom::Point B(lineEnd); + Geom::Point point_a(line_start); + Geom::Point point_b(line_end); - Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); - double hyp = Geom::distance(A, B); - double c = (B[0] - A[0]) / hyp; // cos(alpha) - double s = (B[1] - A[1]) / hyp; // sin(alpha) + Geom::Affine m1(1.0, 0.0, 0.0, 1.0, point_a[0], point_a[1]); + double hyp = Geom::distance(point_a, point_b); + double c = (point_b[0] - point_a[0]) / hyp; // cos(alpha) + double s = (point_b[1] - point_a[1]) / hyp; // sin(alpha) Geom::Affine m2(c, -s, s, c, 0.0, 0.0); Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); @@ -189,15 +195,15 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) m = m * sca; m = m * m2.inverse(); m = m * m1; - - if(fusionPaths && !discard_orig_path){ + + if(fusion_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ + path_it != original_pathv.end(); ++path_it) { + if (path_it->empty()) { continue; } std::vector temp_path; - double timeStart = 0.0; + double time_start = 0.0; int position = 0; bool end_open = false; if (path_it->closed()) { @@ -207,48 +213,48 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) } } Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()){ + if(end_open && path_it->closed()) { original.close(false); original.appendNew( original.initialPoint() ); original.close(true); } - Geom::Crossings cs = crossings(original, mlineExpanded); + Geom::Crossings cs = crossings(original, line_m_expanded); for(unsigned int i = 0; i < cs.size(); i++) { double timeEnd = cs[i].ta; - Geom::Path portion = original.portion(timeStart, timeEnd); + Geom::Path portion = original.portion(time_start, timeEnd); Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine(lineStart, lineEnd, middle); - if(reverseFusion){ + position = pointSideOfLine(line_start, line_end, middle); + if(reverse_fusion) { position *= -1; } - if(position == 1){ + if(position == 1) { Geom::Path mirror = portion.reverse() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); - if(i!=0){ + if(i!=0) { portion.setFinal(portion.initialPoint()); portion.close(); } temp_path.push_back(portion); } portion.clear(); - timeStart = timeEnd; + time_start = timeEnd; } - position = pointSideOfLine(lineStart, lineEnd, original.finalPoint()); - if(reverseFusion){ + position = pointSideOfLine(line_start, line_end, original.finalPoint()); + if(reverse_fusion) { position *= -1; } - if(cs.size()!=0 && position == 1){ - Geom::Path portion = original.portion(timeStart, original.size()); + if(cs.size()!=0 && position == 1) { + Geom::Path portion = original.portion(time_start, original.size()); portion = portion.reverse(); Geom::Path mirror = portion.reverse() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); portion = portion.reverse(); - if (!original.closed()){ + if (!original.closed()) { temp_path.push_back(portion); } else { - if(cs.size() >1 ){ + if(cs.size() >1 ) { portion.setFinal(temp_path[0].initialPoint()); portion.setInitial(temp_path[0].finalPoint()); temp_path[0].append(portion); @@ -259,7 +265,7 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) } portion.clear(); } - if(cs.size() == 0 && position == 1){ + if(cs.size() == 0 && position == 1) { temp_path.push_back(original); temp_path.push_back(original * m); } @@ -267,8 +273,8 @@ LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) temp_path.clear(); } } - - if (!fusionPaths || discard_orig_path) { + + if (!fusion_paths || discard_orig_path) { for (int i = 0; i < static_cast(path_in.size()); ++i) { path_out.push_back(path_in[i] * m); } @@ -283,17 +289,18 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector using namespace Geom; PathVector pathv; - Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew( lineEnd); - pathv.push_back(mlineExpanded); + Geom::Path line_m_expanded; + Geom::Point line_start = line_separation.pointAt(-100000.0); + Geom::Point line_end = line_separation.pointAt(100000.0); + line_m_expanded.start( line_start); + line_m_expanded.appendNew( line_end); + pathv.push_back(line_m_expanded); hp_vec.push_back(pathv); } -void -LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { +void +LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ { knoth = knotholder; KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 97d641bcc..43535650d 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -26,8 +26,8 @@ namespace Inkscape { namespace LivePathEffect { namespace MS { - // we need a separate namespace to avoid clashes with LPEPerpBisector - class KnotHolderEntityCenterMirrorSymmetry; +// we need a separate namespace to avoid clashes with LPEPerpBisector +class KnotHolderEntityCenterMirrorSymmetry; } enum ModeType { @@ -37,7 +37,7 @@ enum ModeType { MT_END }; -class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{ +class LPEMirrorSymmetry : public Effect, GroupBBoxEffect { public: LPEMirrorSymmetry(LivePathEffectObject *lpeobject); virtual ~LPEMirrorSymmetry(); @@ -60,11 +60,11 @@ protected: private: EnumParam mode; BoolParam discard_orig_path; - BoolParam fusionPaths; - BoolParam reverseFusion; + BoolParam fusion_paths; + BoolParam reverse_fusion; PathParam reflection_line; - Geom::Line lineSeparation; - Geom::Point previousCenter; + Geom::Line line_separation; + Geom::Point previous_center; PointParam center; KnotHolder *knoth; -- cgit v1.2.3 From 78f080901f40a7390559f88ab14465131bb02717 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 1 Jun 2015 23:46:40 +0200 Subject: opening kaleidscope (bzr r13708.1.28) --- src/live_effects/lpe-copy_rotate.cpp | 95 ++++++++++++++++++++++++++++++++++-- src/live_effects/lpe-copy_rotate.h | 4 +- 2 files changed, 94 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 4fd605b6d..c119ca02e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -110,10 +110,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if(kaleidoscope || copies_to_360 ) { + if(copies_to_360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if(kaleidoscope) { + if(kaleidoscope && copies_to_360) { num_copies.param_set_increments(2,2); if((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -216,8 +216,72 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, double size_divider) +LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider_extreme) { + std::vector tmp_path; + double time_start = 0.0; + Geom::Path original = path_on[0]; + int position = 0; + Geom::Crossings cs = crossings(original,divider_extreme); + std::vector crossed; + for(unsigned int i = 0; i < cs.size(); i++) { + crossed.push_back(cs[i].ta); + } + std::sort (crossed.begin(), crossed.end()); + for(unsigned int i = 0; i < crossed.size(); i++) { + double timeEnd = crossed[i]; + Geom::Path portion_original = original.portion(time_start,timeEnd); + Geom::Point side_checker = portion_original.pointAt(0.001); + position = pointSideOfLine(divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint(), side_checker); + if(num_copies > 2) { + position = pointInTriangle(side_checker, divider_extreme.initialPoint(), divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint()); + } + if(position == 1) { + Geom::Path start = Geom::Path(divider_extreme.at(0)); + start.appendNew(divider_extreme.at(1)); + if(!are_near(nearest_point(portion_original.initialPoint(),start),portion_original.initialPoint())){ + portion_original.reverse(); + } + tmp_path.push_back(portion_original); + } + portion_original.clear(); + time_start = timeEnd; + } + position = pointSideOfLine(divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint(), original.finalPoint()); + if(num_copies > 2) { + position = pointInTriangle(original.finalPoint(), divider_extreme.initialPoint(), divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint()); + } + if(cs.size() > 0 && position == 1) { + Geom::Path portion_original = original.portion(time_start, original.size()); + Geom::Path start = Geom::Path(divider_extreme.at(0)); + start.appendNew(divider_extreme.at(1)); + if(!are_near(nearest_point(portion_original.initialPoint(),start),portion_original.initialPoint())){ + portion_original.reverse(); + } + if (!original.closed()) { + tmp_path.push_back(portion_original); + } else { + if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { + portion_original.setFinal(tmp_path[0].initialPoint()); + portion_original.append(tmp_path[0]); + tmp_path[0] = portion_original; + } else { + tmp_path.push_back(portion_original); + } + //temp_path[0].close(); + } + portion_original.clear(); + } + if(cs.size()==0 && position == 1) { + tmp_path.push_back(original); + } + path_on = tmp_path; +} + +void +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_extreme, double size_divider) +{ + std::vector path_on_start = path_on; split(path_on,divider); std::vector tmp_path; Geom::Affine pre = Geom::Translate(-origin); @@ -282,6 +346,21 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi tmp_path_helper[0].append(tmp_append); tmp_path_helper[0] = tmp_path_helper[0].reverse(); } else { + if(rotation_angle * num_copies != 360){ + split_start(path_on_start,divider_extreme); + for (Geom::PathVector::const_iterator path_it_start = path_on_start.begin(); path_it_start != path_on_start.end(); ++path_it_start) { + Geom::Path original_start = *path_it_start; + if (path_it->empty()) { + continue; + } + std::vector tmp_path_helper; + if(tmp_path_helper.size() > 0 && Geom::are_near(append_path.initialPoint(),path_it_start[0].initialPoint())) { + path_it_start.reverse(); + path_it_start.append(append_path); + append_path = path_it_start; + } + } + } tmp_path_helper.push_back(append_path); } if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),tmp_path_helper[tmp_path_helper.size()-1].initialPoint())) { @@ -317,6 +396,14 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Geom::Path divider = Geom::Path(line_start); divider.appendNew((Geom::Point)origin); divider.appendNew(line_end); + Geom::Point line_oposite = origin + dir * Rotate(-deg_to_rad((rotation_angle/2)+starting_angle)) * size_divider; + Geom::Path divider_start = Geom::Path(line_start); + divider_start.appendNew((Geom::Point)origin); + divider_start.appendNew(line_oposite); + Geom::Path divider_end = Geom::Path(line_end); + divider_end.appendNew((Geom::Point)origin); + divider_end.appendNew(line_oposite); + Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(kaleidoscope) { @@ -341,7 +428,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider,size_divider); + setKaleidoscope(tmp_path,divider, divider_extreme, size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 83f4a6984..638f8a413 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, double sizeDivider); + virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path extreme, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); @@ -46,6 +46,8 @@ public: virtual void split(std::vector &path_in,Geom::Path divider); + virtual void split_extreme(std::vector &path_on,Geom::Path divider_extreme); + virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); -- cgit v1.2.3 From 53ff3799d1f7c05cfa7f1384eb39b5105c29f9ab Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 2 Jun 2015 19:29:54 +0200 Subject: opening kaleidscope (bzr r13708.1.30) --- src/live_effects/lpe-copy_rotate.cpp | 27 +++++++++++++-------------- src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index c119ca02e..f9d1bffee 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -237,9 +237,9 @@ LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider position = pointInTriangle(side_checker, divider_extreme.initialPoint(), divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint()); } if(position == 1) { - Geom::Path start = Geom::Path(divider_extreme.at(0)); - start.appendNew(divider_extreme.at(1)); - if(!are_near(nearest_point(portion_original.initialPoint(),start),portion_original.initialPoint())){ + Geom::Path start = Geom::Path(divider_extreme.pointAt(0)); + start.appendNew(divider_extreme.pointAt(1)); + if(!are_near(start.pointAt(nearest_point(portion_original.initialPoint(),start)),portion_original.initialPoint())){ portion_original.reverse(); } tmp_path.push_back(portion_original); @@ -253,9 +253,9 @@ LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider } if(cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); - Geom::Path start = Geom::Path(divider_extreme.at(0)); - start.appendNew(divider_extreme.at(1)); - if(!are_near(nearest_point(portion_original.initialPoint(),start),portion_original.initialPoint())){ + Geom::Path start = Geom::Path(divider_extreme.pointAt(0)); + start.appendNew(divider_extreme.pointAt(1)); + if(!are_near(start.pointAt(nearest_point(portion_original.initialPoint(),start)),portion_original.initialPoint())){ portion_original.reverse(); } if (!original.closed()) { @@ -279,7 +279,7 @@ LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_extreme, double size_divider) +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, Geom::Path divider_end, double size_divider) { std::vector path_on_start = path_on; split(path_on,divider); @@ -347,18 +347,17 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi tmp_path_helper[0] = tmp_path_helper[0].reverse(); } else { if(rotation_angle * num_copies != 360){ - split_start(path_on_start,divider_extreme); + split_extreme(path_on_start,divider_start); for (Geom::PathVector::const_iterator path_it_start = path_on_start.begin(); path_it_start != path_on_start.end(); ++path_it_start) { Geom::Path original_start = *path_it_start; if (path_it->empty()) { continue; } - std::vector tmp_path_helper; - if(tmp_path_helper.size() > 0 && Geom::are_near(append_path.initialPoint(),path_it_start[0].initialPoint())) { - path_it_start.reverse(); - path_it_start.append(append_path); - append_path = path_it_start; + if(Geom::are_near(append_path.initialPoint(),original_start.initialPoint())) { + original_start.reverse(); } + original_start.append(append_path); + append_path = original_start; } } tmp_path_helper.push_back(append_path); @@ -428,7 +427,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider, divider_extreme, size_divider); + setKaleidoscope(tmp_path,divider, divider_start, divider_end, size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 638f8a413..e16d3ceee 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path extreme, double sizeDivider); + virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, Geom::Path divider_end, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); -- cgit v1.2.3 From 22ca2d7d903022da13a50ac2517e1ff2e3b5257d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 4 Jun 2015 00:54:55 +0200 Subject: opening kaleidscope (bzr r13708.1.32) --- src/live_effects/lpe-copy_rotate.cpp | 134 +++++++++++++---------------------- src/live_effects/lpe-copy_rotate.h | 4 +- 2 files changed, 51 insertions(+), 87 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f9d1bffee..990bc1192 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -113,7 +113,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if(copies_to_360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if(kaleidoscope && copies_to_360) { + if(kaleidoscope && rotation_angle * num_copies > 360 && rotation_angle > 0){ + num_copies.param_set_value(floor(360/rotation_angle)); + } + if(kaleidoscope || copies_to_360) { num_copies.param_set_increments(2,2); if((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -169,6 +172,7 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) double time_start = 0.0; Geom::Path original = path_on[0]; int position = 0; + Geom::Line divider_line(divider.pointAt(0),divider.pointAt(1)); Geom::Crossings cs = crossings(original,divider); std::vector crossed; for(unsigned int i = 0; i < cs.size(); i++) { @@ -184,6 +188,9 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if(position == 1) { + if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ + portion_original = portion_original.reverse(); + } tmp_path.push_back(portion_original); } portion_original.clear(); @@ -195,68 +202,8 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } if(cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); - if (!original.closed()) { - tmp_path.push_back(portion_original); - } else { - if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { - portion_original.setFinal(tmp_path[0].initialPoint()); - portion_original.append(tmp_path[0]); - tmp_path[0] = portion_original; - } else { - tmp_path.push_back(portion_original); - } - //temp_path[0].close(); - } - portion_original.clear(); - } - if(cs.size()==0 && position == 1) { - tmp_path.push_back(original); - } - path_on = tmp_path; -} - -void -LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider_extreme) -{ - std::vector tmp_path; - double time_start = 0.0; - Geom::Path original = path_on[0]; - int position = 0; - Geom::Crossings cs = crossings(original,divider_extreme); - std::vector crossed; - for(unsigned int i = 0; i < cs.size(); i++) { - crossed.push_back(cs[i].ta); - } - std::sort (crossed.begin(), crossed.end()); - for(unsigned int i = 0; i < crossed.size(); i++) { - double timeEnd = crossed[i]; - Geom::Path portion_original = original.portion(time_start,timeEnd); - Geom::Point side_checker = portion_original.pointAt(0.001); - position = pointSideOfLine(divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint(), side_checker); - if(num_copies > 2) { - position = pointInTriangle(side_checker, divider_extreme.initialPoint(), divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint()); - } - if(position == 1) { - Geom::Path start = Geom::Path(divider_extreme.pointAt(0)); - start.appendNew(divider_extreme.pointAt(1)); - if(!are_near(start.pointAt(nearest_point(portion_original.initialPoint(),start)),portion_original.initialPoint())){ - portion_original.reverse(); - } - tmp_path.push_back(portion_original); - } - portion_original.clear(); - time_start = timeEnd; - } - position = pointSideOfLine(divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint(), original.finalPoint()); - if(num_copies > 2) { - position = pointInTriangle(original.finalPoint(), divider_extreme.initialPoint(), divider_extreme[0].finalPoint(), divider_extreme[1].finalPoint()); - } - if(cs.size() > 0 && position == 1) { - Geom::Path portion_original = original.portion(time_start, original.size()); - Geom::Path start = Geom::Path(divider_extreme.pointAt(0)); - start.appendNew(divider_extreme.pointAt(1)); - if(!are_near(start.pointAt(nearest_point(portion_original.initialPoint(),start)),portion_original.initialPoint())){ - portion_original.reverse(); + if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ + portion_original = portion_original.reverse(); } if (!original.closed()) { tmp_path.push_back(portion_original); @@ -279,7 +226,7 @@ LPECopyRotate::split_extreme(std::vector &path_on,Geom::Path divider } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, Geom::Path divider_end, double size_divider) +LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, double size_divider) { std::vector path_on_start = path_on; split(path_on,divider); @@ -346,26 +293,49 @@ LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divi tmp_path_helper[0].append(tmp_append); tmp_path_helper[0] = tmp_path_helper[0].reverse(); } else { - if(rotation_angle * num_copies != 360){ - split_extreme(path_on_start,divider_start); - for (Geom::PathVector::const_iterator path_it_start = path_on_start.begin(); path_it_start != path_on_start.end(); ++path_it_start) { - Geom::Path original_start = *path_it_start; - if (path_it->empty()) { - continue; - } - if(Geom::are_near(append_path.initialPoint(),original_start.initialPoint())) { - original_start.reverse(); - } - original_start.append(append_path); - append_path = original_start; - } - } tmp_path_helper.push_back(append_path); } if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),tmp_path_helper[tmp_path_helper.size()-1].initialPoint())) { tmp_path_helper[tmp_path_helper.size()-1].close(); } } + if(rotation_angle * num_copies != 360 && tmp_path_helper.size() > 0){ + split(path_on_start,divider_start); + for (Geom::PathVector::const_iterator path_it_start = path_on_start.begin(); path_it_start != path_on_start.end(); ++path_it_start) { + Geom::Path original_start = *path_it_start; + if (path_it->empty()) { + continue; + } + + if( Geom::are_near(tmp_path_helper[0].initialPoint(),original_start.initialPoint())){ + Geom::Point A(divider_start.pointAt(1)); + Geom::Point B(divider_start.pointAt(2)); + + Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); + double hyp = Geom::distance(A, B); + double c = (B[0] - A[0]) / hyp; // cos(alpha) + double s = (B[1] - A[1]) / hyp; // sin(alpha) + + Geom::Affine m2(c, -s, s, c, 0.0, 0.0); + Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + + Geom::Affine m = m1.inverse() * m2; + m = m * sca; + m = m * m2.inverse(); + m = m * m1; + original_start.setInitial(tmp_path_helper[0].initialPoint()); + Geom::Path mirror = original_start * m; + mirror = mirror.reverse(); + mirror.setInitial(original_start.finalPoint()); + original_start.append(mirror); + original_start = original_start.reverse(); + original_start.setFinal(tmp_path_helper[0].initialPoint()); + original_start.append(tmp_path_helper[0]); + tmp_path_helper[0] = original_start; + } + } + } + if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),tmp_path_helper[0].initialPoint())) { tmp_path_helper[0].close(); } @@ -395,14 +365,10 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Geom::Path divider = Geom::Path(line_start); divider.appendNew((Geom::Point)origin); divider.appendNew(line_end); - Geom::Point line_oposite = origin + dir * Rotate(-deg_to_rad((rotation_angle/2)+starting_angle)) * size_divider; + Geom::Point line_oposite = origin + dir * Rotate(-deg_to_rad((rotation_angle * num_copies /2)+starting_angle + 180)) * size_divider; Geom::Path divider_start = Geom::Path(line_start); divider_start.appendNew((Geom::Point)origin); divider_start.appendNew(line_oposite); - Geom::Path divider_end = Geom::Path(line_end); - divider_end.appendNew((Geom::Point)origin); - divider_end.appendNew(line_oposite); - Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(kaleidoscope) { @@ -427,7 +393,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider, divider_start, divider_end, size_divider); + setKaleidoscope(tmp_path,divider, divider_start, size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index e16d3ceee..efbb5f746 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, Geom::Path divider_end, double sizeDivider); + virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); @@ -46,8 +46,6 @@ public: virtual void split(std::vector &path_in,Geom::Path divider); - virtual void split_extreme(std::vector &path_on,Geom::Path divider_extreme); - virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); -- cgit v1.2.3 From d50fe92ba2df09544c11aca985e1746ecdc47fe2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 4 Jun 2015 01:20:27 +0200 Subject: opening kaleidscope (bzr r13708.1.33) --- src/live_effects/lpe-copy_rotate.cpp | 24 ++++++++++++------------ src/live_effects/lpe-copy_rotate.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 990bc1192..559e117cf 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -52,7 +52,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - kaleidoscope(_("kaleidoscope"), _("kaleidoscope"), "kaleidoscope", &wr, this, false), + fusion_paths(_("Fusioned paths"), _("Fusion paths by helper line"), "fusion_paths", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -60,7 +60,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); - registerParameter(&kaleidoscope); + registerParameter(&fusion_paths); registerParameter(&starting_angle); registerParameter(&rotation_angle); registerParameter(&num_copies); @@ -92,7 +92,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(kaleidoscope) { + if(fusion_paths) { Geom::Coord angle = Geom::rad_to_deg(atan(-postmul[1]/postmul[0])); angle += starting_angle; starting_angle.param_set_value(angle); @@ -113,10 +113,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if(copies_to_360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if(kaleidoscope && rotation_angle * num_copies > 360 && rotation_angle > 0){ + if(fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0){ num_copies.param_set_value(floor(360/rotation_angle)); } - if(kaleidoscope || copies_to_360) { + if(fusion_paths || copies_to_360) { num_copies.param_set_increments(2,2); if((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -135,7 +135,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * dist_angle_handle; - if( kaleidoscope || copies_to_360 ) { + if( fusion_paths || copies_to_360 ) { rot_pos = origin; } SPLPEItem * item = const_cast(lpeitem); @@ -189,7 +189,7 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } if(position == 1) { if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ - portion_original = portion_original.reverse(); + //portion_original = portion_original.reverse(); } tmp_path.push_back(portion_original); } @@ -203,7 +203,7 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) if(cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ - portion_original = portion_original.reverse(); + // portion_original = portion_original.reverse(); } if (!original.closed()) { tmp_path.push_back(portion_original); @@ -226,7 +226,7 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } void -LPECopyRotate::setKaleidoscope(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, double size_divider) +LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, double size_divider) { std::vector path_on_start = path_on; split(path_on,divider); @@ -359,7 +359,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); Geom::Point line_start = origin + dir * Rotate(-deg_to_rad(starting_angle)) * size_divider; - Geom::Point line_end = origin + dir * Rotate(-deg_to_rad(rotation_angle+starting_angle)) * size_divider; + Geom::Point line_end = origin + dir * Rotate(-deg_to_rad(rotation_angle + starting_angle)) * size_divider; //Note:: beter way to do this //Whith AppendNew have problems whith the crossing order Geom::Path divider = Geom::Path(line_start); @@ -371,7 +371,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p divider_start.appendNew(line_oposite); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); - if(kaleidoscope) { + if(fusion_paths) { std::vector path_out; std::vector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); @@ -393,7 +393,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setKaleidoscope(tmp_path,divider, divider_start, size_divider); + setFusion(tmp_path,divider, divider_start, size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index efbb5f746..02141b359 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setKaleidoscope(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, double sizeDivider); + virtual void setFusion(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); @@ -64,7 +64,7 @@ private: ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copies_to_360; - BoolParam kaleidoscope; + BoolParam fusion_paths; Geom::Point A; Geom::Point B; -- cgit v1.2.3 From ee3b91ebda768eb483c159dc3072cb5a20df5086 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 4 Jun 2015 20:37:00 +0200 Subject: Change from kaleidoscope to multiangle fusion (bzr r13708.1.34) --- src/live_effects/lpe-copy_rotate.cpp | 77 +++++++++++++----------------------- src/live_effects/lpe-copy_rotate.h | 2 +- 2 files changed, 28 insertions(+), 51 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 559e117cf..d12c03f7e 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -116,7 +116,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if(fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0){ num_copies.param_set_value(floor(360/rotation_angle)); } - if(fusion_paths || copies_to_360) { + if(fusion_paths && copies_to_360) { num_copies.param_set_increments(2,2); if((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -172,7 +172,6 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) double time_start = 0.0; Geom::Path original = path_on[0]; int position = 0; - Geom::Line divider_line(divider.pointAt(0),divider.pointAt(1)); Geom::Crossings cs = crossings(original,divider); std::vector crossed; for(unsigned int i = 0; i < cs.size(); i++) { @@ -184,27 +183,21 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) Geom::Path portion_original = original.portion(time_start,timeEnd); Geom::Point side_checker = portion_original.pointAt(0.001); position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); - if(num_copies > 2) { + if(rotation_angle != 180) { position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if(position == 1) { - if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ - //portion_original = portion_original.reverse(); - } tmp_path.push_back(portion_original); } portion_original.clear(); time_start = timeEnd; } position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); - if(num_copies > 2) { + if(rotation_angle != 180) { position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if(cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); - if(!Geom::are_near(portion_original.pointAt(0),divider_line)){ - // portion_original = portion_original.reverse(); - } if (!original.closed()) { tmp_path.push_back(portion_original); } else { @@ -215,7 +208,6 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } else { tmp_path.push_back(portion_original); } - //temp_path[0].close(); } portion_original.clear(); } @@ -226,9 +218,8 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } void -LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, Geom::Path divider_start, double size_divider) +LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, double size_divider) { - std::vector path_on_start = path_on; split(path_on,divider); std::vector tmp_path; Geom::Affine pre = Geom::Translate(-origin); @@ -300,39 +291,29 @@ LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, G } } if(rotation_angle * num_copies != 360 && tmp_path_helper.size() > 0){ - split(path_on_start,divider_start); - for (Geom::PathVector::const_iterator path_it_start = path_on_start.begin(); path_it_start != path_on_start.end(); ++path_it_start) { - Geom::Path original_start = *path_it_start; - if (path_it->empty()) { - continue; + Geom::Ray base_a(divider.pointAt(1),divider.pointAt(0)); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle * num_copies) + starting_angle)) * size_divider; + Geom::Ray base_b(divider.pointAt(1), base_point); + if(Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && Geom::are_near(tmp_path_helper[0].finalPoint(),base_a)){ + tmp_path_helper[0].close(); + if(tmp_path_helper.size() > 1){ + tmp_path_helper[tmp_path_helper.size()-1].close(); } - - if( Geom::are_near(tmp_path_helper[0].initialPoint(),original_start.initialPoint())){ - Geom::Point A(divider_start.pointAt(1)); - Geom::Point B(divider_start.pointAt(2)); - - Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); - double hyp = Geom::distance(A, B); - double c = (B[0] - A[0]) / hyp; // cos(alpha) - double s = (B[1] - A[1]) / hyp; // sin(alpha) - - Geom::Affine m2(c, -s, s, c, 0.0, 0.0); - Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); - - Geom::Affine m = m1.inverse() * m2; - m = m * sca; - m = m * m2.inverse(); - m = m * m1; - original_start.setInitial(tmp_path_helper[0].initialPoint()); - Geom::Path mirror = original_start * m; - mirror = mirror.reverse(); - mirror.setInitial(original_start.finalPoint()); - original_start.append(mirror); - original_start = original_start.reverse(); - original_start.setFinal(tmp_path_helper[0].initialPoint()); - original_start.append(tmp_path_helper[0]); - tmp_path_helper[0] = original_start; + } else if(Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),base_b) && + Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)){ + tmp_path_helper[0].close(); + if(tmp_path_helper.size() > 1){ + tmp_path_helper[tmp_path_helper.size()-1].close(); } + } else if((Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)) || + (Geom::are_near(tmp_path_helper[0].initialPoint(),base_b) && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_a))){ + Geom::Path close_path = Geom::Path(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + close_path.appendNew((Geom::Point)origin); + close_path.appendNew(tmp_path_helper[0].initialPoint()); + tmp_path_helper[0].append(close_path); } } @@ -351,7 +332,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if(num_copies == 1) { + if(num_copies == 1 && !fusion_paths) { return pwd2_in; } @@ -365,10 +346,6 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Geom::Path divider = Geom::Path(line_start); divider.appendNew((Geom::Point)origin); divider.appendNew(line_end); - Geom::Point line_oposite = origin + dir * Rotate(-deg_to_rad((rotation_angle * num_copies /2)+starting_angle + 180)) * size_divider; - Geom::Path divider_start = Geom::Path(line_start); - divider_start.appendNew((Geom::Point)origin); - divider_start.appendNew(line_oposite); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(fusion_paths) { @@ -393,7 +370,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p original.close(true); } tmp_path.push_back(original); - setFusion(tmp_path,divider, divider_start, size_divider); + setFusion(tmp_path, divider, size_divider); path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 02141b359..b230a6fc9 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,7 +38,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setFusion(std::vector &path_in, Geom::Path divider, Geom::Path divider_start, double sizeDivider); + virtual void setFusion(std::vector &path_in, Geom::Path divider, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); -- cgit v1.2.3 From e9e6116349cc51e31ae3a643a89644aa4e817b0a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 4 Jun 2015 22:21:35 +0200 Subject: fix minor bug (bzr r13708.1.36) --- src/live_effects/lpe-copy_rotate.cpp | 42 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index d12c03f7e..cfc1b92cf 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -110,7 +110,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if(copies_to_360 ) { + if( copies_to_360 ) { rotation_angle.param_set_value(360.0/(double)num_copies); } if(fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0){ @@ -181,16 +181,18 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) for(unsigned int i = 0; i < crossed.size(); i++) { double timeEnd = crossed[i]; Geom::Path portion_original = original.portion(time_start,timeEnd); - Geom::Point side_checker = portion_original.pointAt(0.001); - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); - if(rotation_angle != 180) { - position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); - } - if(position == 1) { - tmp_path.push_back(portion_original); + if(!portion_original.empty()){ + Geom::Point side_checker = portion_original.pointAt(0.001); + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); + if(rotation_angle != 180) { + position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); + } + if(position == 1) { + tmp_path.push_back(portion_original); + } + portion_original.clear(); + time_start = timeEnd; } - portion_original.clear(); - time_start = timeEnd; } position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); if(rotation_angle != 180) { @@ -198,18 +200,20 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } if(cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); - if (!original.closed()) { - tmp_path.push_back(portion_original); - } else { - if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { - portion_original.setFinal(tmp_path[0].initialPoint()); - portion_original.append(tmp_path[0]); - tmp_path[0] = portion_original; - } else { + if(!portion_original.empty()){ + if (!original.closed()) { tmp_path.push_back(portion_original); + } else { + if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { + portion_original.setFinal(tmp_path[0].initialPoint()); + portion_original.append(tmp_path[0]); + tmp_path[0] = portion_original; + } else { + tmp_path.push_back(portion_original); + } } + portion_original.clear(); } - portion_original.clear(); } if(cs.size()==0 && position == 1) { tmp_path.push_back(original); -- cgit v1.2.3 From 713ebbaf2d2961951d599543cff3b3cae721955c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 25 Jul 2015 00:19:48 +0200 Subject: fixes for update to trunk (bzr r13708.1.38) --- src/live_effects/lpe-copy_rotate.cpp | 32 ++++++++++++++++---------------- src/live_effects/lpe-copy_rotate.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index cfc1b92cf..083f56be8 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -166,9 +166,9 @@ LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Ge } void -LPECopyRotate::split(std::vector &path_on,Geom::Path divider) +LPECopyRotate::split(Geom::PathVector &path_on,Geom::Path divider) { - std::vector tmp_path; + Geom::PathVector tmp_path; double time_start = 0.0; Geom::Path original = path_on[0]; int position = 0; @@ -222,17 +222,17 @@ LPECopyRotate::split(std::vector &path_on,Geom::Path divider) } void -LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, double size_divider) +LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double size_divider) { split(path_on,divider); - std::vector tmp_path; + Geom::PathVector tmp_path; Geom::Affine pre = Geom::Translate(-origin); for (Geom::PathVector::const_iterator path_it = path_on.begin(); path_it != path_on.end(); ++path_it) { Geom::Path original = *path_it; if (path_it->empty()) { continue; } - std::vector tmp_path_helper; + Geom::PathVector tmp_path_helper; Geom::Path append_path = original; for (int i = 0; i < num_copies; ++i) { Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * (i))); @@ -258,35 +258,35 @@ LPECopyRotate::setFusion(std::vector &path_on, Geom::Path divider, d } append_path *= m; if(i != 0 && tmp_path_helper.size() > 0 &&( Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.finalPoint()))) { - Geom::Path tmp_append = append_path.reverse(); + Geom::Path tmp_append = append_path.reversed(); tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.initialPoint())) { Geom::Path tmp_append = append_path; - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.initialPoint())) { Geom::Path tmp_append = append_path; tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.finalPoint())) { - Geom::Path tmp_append = append_path.reverse(); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + Geom::Path tmp_append = append_path.reversed(); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reverse(); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),append_path.finalPoint())) { - Geom::Path tmp_append = append_path.reverse(); + Geom::Path tmp_append = append_path.reversed(); tmp_append.setInitial(tmp_path_helper[0].finalPoint()); tmp_path_helper[0].append(tmp_append); } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].initialPoint(),append_path.initialPoint())) { Geom::Path tmp_append = append_path; - tmp_path_helper[0] = tmp_path_helper[0].reverse(); + tmp_path_helper[0] = tmp_path_helper[0].reversed(); tmp_append.setInitial(tmp_path_helper[0].finalPoint()); tmp_path_helper[0].append(tmp_append); - tmp_path_helper[0] = tmp_path_helper[0].reverse(); + tmp_path_helper[0] = tmp_path_helper[0].reversed(); } else { tmp_path_helper.push_back(append_path); } @@ -353,8 +353,8 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p Piecewise > output; Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle)); if(fusion_paths) { - std::vector path_out; - std::vector tmp_path; + Geom::PathVector path_out; + Geom::PathVector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index b230a6fc9..e45fa6d37 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -38,13 +38,13 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setFusion(std::vector &path_in, Geom::Path divider, double sizeDivider); + virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); - virtual void split(std::vector &path_in,Geom::Path divider); + virtual void split(Geom::PathVector &path_in,Geom::Path divider); virtual void resetDefaults(SPItem const* item); -- cgit v1.2.3 From 8c56f58ee39a66e2a25252e01c795296a958ec40 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 25 Jul 2015 04:15:13 +0200 Subject: Fix helper path (bzr r13682.1.29) --- src/live_effects/lpe-mirror_symmetry.cpp | 44 ++++++++------------------------ src/live_effects/lpe-mirror_symmetry.h | 1 - 2 files changed, 10 insertions(+), 35 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 7a9870d78..79cdf947d 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -42,18 +42,9 @@ namespace MS { class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity { public: - KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) - { - this->knoth = effect->knoth; - }; - virtual ~KnotHolderEntityCenterMirrorSymmetry() - { - this->knoth = NULL; - } + KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; -private: - KnotHolder *knoth; }; } // namespace MS @@ -65,8 +56,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : fusion_paths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusion_paths", &wr, this, true), reverse_fusion(_("Reverse fusion"), _("Reverse fusion"), "reverse_fusion", &wr, this, false), reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), - center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring"), - knoth(NULL) + center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") { show_orig_path = true; @@ -106,10 +96,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) path.appendNew( point_b ); reflection_line.set_new_value(path.toPwSb(), true); line_separation.setPoints(point_a, point_b); - center.param_setValue(path.pointAt(0.5)); - if(knoth) { - knoth->update_knots(); - } + center.param_setValue(path.pointAt(0.5), true); } else if( mode == MT_FREE) { Geom::PathVector line_m(reflection_line.get_pathvector()); if(!are_near(previous_center,center, 0.01)) { @@ -120,13 +107,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) reflection_line.set_new_value(line_m[0].toPwSb(), true); line_separation.setPoints(point_a, point_b); } else { - center.param_setValue(line_m[0].pointAt(0.5)); + center.param_setValue(line_m[0].pointAt(0.5), true); point_a = line_m[0].initialPoint(); point_b = line_m[0].finalPoint(); line_separation.setPoints(point_a, point_b); - if(knoth) { - knoth->update_knots(); - } } previous_center = center; } @@ -228,7 +212,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) position *= -1; } if(position == 1) { - Geom::Path mirror = portion.reverse() * m; + Geom::Path mirror = portion.reversed() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); if(i!=0) { @@ -246,11 +230,11 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } if(cs.size()!=0 && position == 1) { Geom::Path portion = original.portion(time_start, original.size()); - portion = portion.reverse(); - Geom::Path mirror = portion.reverse() * m; + portion = portion.reversed(); + Geom::Path mirror = portion.reversed() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); - portion = portion.reverse(); + portion = portion.reversed(); if (!original.closed()) { temp_path.push_back(portion); } else { @@ -287,22 +271,14 @@ void LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { using namespace Geom; - - PathVector pathv; - Geom::Path line_m_expanded; - Geom::Point line_start = line_separation.pointAt(-100000.0); - Geom::Point line_end = line_separation.pointAt(100000.0); - line_m_expanded.start( line_start); - line_m_expanded.appendNew( line_end); - pathv.push_back(line_m_expanded); - hp_vec.push_back(pathv); + hp_vec.clear(); + hp_vec.push_back(reflection_line.get_pathvector()); } void LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { { - knoth = knotholder; KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Adjust the center") ); diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index b30972308..12bf2e7d3 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -66,7 +66,6 @@ private: Geom::Line line_separation; Geom::Point previous_center; PointParam center; - KnotHolder *knoth; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 46df96973716748cde5c889a49379fcc6bbd82b9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 25 Jul 2015 04:30:46 +0200 Subject: update credits (bzr r13682.1.31) --- src/live_effects/lpe-mirror_symmetry.cpp | 1 + src/live_effects/lpe-mirror_symmetry.h | 1 + 2 files changed, 2 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 79cdf947d..685dc6354 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -6,6 +6,7 @@ * Maximilian Albert * Johan Engelen * Abhishek Sharma + * Jabiertxof * * Copyright (C) Johan Engelen 2007 * Copyright (C) Maximilin Albert 2008 diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 12bf2e7d3..0874f0c7e 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -8,6 +8,7 @@ * Authors: * Maximilian Albert * Johan Engelen + * Jabiertxof * * Copyright (C) Johan Engelen 2007 * Copyright (C) Maximilin Albert 2008 -- cgit v1.2.3 From 4aba6b92f30733f400891d2c3a6d77c1ae1d7a47 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 2 Mar 2016 20:34:31 +0100 Subject: Fix for bug 1540070 Fixed bugs: - https://launchpad.net/bugs/1540070 (bzr r14678) --- src/live_effects/effect.cpp | 3 ++- src/live_effects/effect.h | 2 ++ src/live_effects/lpe-bendpath.cpp | 5 +---- src/live_effects/lpe-copy_rotate.cpp | 5 +---- src/live_effects/lpe-envelope.cpp | 4 +--- src/live_effects/lpe-lattice.cpp | 5 +---- src/live_effects/lpe-lattice2.cpp | 4 +--- src/live_effects/lpe-mirror_symmetry.cpp | 10 +--------- src/live_effects/lpe-mirror_symmetry.h | 2 -- src/live_effects/lpe-offset.cpp | 10 +--------- src/live_effects/lpe-offset.h | 2 -- src/live_effects/lpe-perspective-envelope.cpp | 4 +--- src/live_effects/lpe-perspective_path.cpp | 3 +-- src/live_effects/lpe-roughen.cpp | 4 +--- src/live_effects/lpe-simplify.cpp | 4 +--- src/live_effects/lpe-transform_2pts.cpp | 3 +-- src/live_effects/lpe-vonkoch.cpp | 5 +---- 17 files changed, 17 insertions(+), 58 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index fe7bf3a97..47fd02554 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,7 +356,8 @@ Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item) } Effect::Effect(LivePathEffectObject *lpeobject) - : _provides_knotholder_entities(false), + : apply_to_clippath_and_mask(false), + _provides_knotholder_entities(false), oncanvasedit_it(0), is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true), show_orig_path(false), diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index ea57ff243..898e089b7 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -121,6 +121,7 @@ public: inline bool isVisible() const { return is_visible; } void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); + bool apply_to_clippath_and_mask; protected: Effect(LivePathEffectObject *lpeobject); @@ -144,6 +145,7 @@ protected: std::vector param_vector; bool _provides_knotholder_entities; + int oncanvasedit_it; BoolParam is_visible; diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index d7c0b69a4..bc112285f 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -81,6 +81,7 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : prop_scale.param_set_increments(0.01, 0.10); _provides_knotholder_entities = true; + apply_to_clippath_and_mask = true; concatenate_before_pwd2 = true; } @@ -95,10 +96,6 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) // get the item bounding box original_bbox(lpeitem); original_height = boundingbox_Y.max() - boundingbox_Y.min(); - SPLPEItem * item = const_cast(lpeitem); - - item->apply_to_clippath(item); - item->apply_to_mask(item); } Geom::Piecewise > diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 87d8f05a9..8dfaf7525 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -61,6 +61,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : { show_orig_path = true; _provides_knotholder_entities = true; + apply_to_clippath_and_mask = true; // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copiesTo360); @@ -111,10 +112,6 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if(copiesTo360 ){ rot_pos = origin; } - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); - } diff --git a/src/live_effects/lpe-envelope.cpp b/src/live_effects/lpe-envelope.cpp index 05a672ae8..e873c0b15 100644 --- a/src/live_effects/lpe-envelope.cpp +++ b/src/live_effects/lpe-envelope.cpp @@ -42,6 +42,7 @@ LPEEnvelope::LPEEnvelope(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&bend_path3) ); registerParameter( dynamic_cast(&bend_path4) ); concatenate_before_pwd2 = true; + apply_to_clippath_and_mask = true; } LPEEnvelope::~LPEEnvelope() @@ -54,9 +55,6 @@ LPEEnvelope::doBeforeEffect (SPLPEItem const* lpeitem) { // get the item bounding box original_bbox(lpeitem); - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } Geom::Piecewise > diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index c05bae7e1..3c23e349e 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -78,7 +78,7 @@ LPELattice::LPELattice(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&grid_point14) ); registerParameter( dynamic_cast(&grid_point15) ); - + apply_to_clippath_and_mask = true; } LPELattice::~LPELattice() @@ -176,9 +176,6 @@ void LPELattice::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem); - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } void diff --git a/src/live_effects/lpe-lattice2.cpp b/src/live_effects/lpe-lattice2.cpp index b749370fa..0c403daec 100644 --- a/src/live_effects/lpe-lattice2.cpp +++ b/src/live_effects/lpe-lattice2.cpp @@ -103,6 +103,7 @@ LPELattice2::LPELattice2(LivePathEffectObject *lpeobject) : registerParameter(&grid_point_28x30); registerParameter(&grid_point_29x31); registerParameter(&grid_point_32x33x34x35); + apply_to_clippath_and_mask = true; } LPELattice2::~LPELattice2() @@ -358,9 +359,6 @@ LPELattice2::doBeforeEffect (SPLPEItem const* lpeitem) horizontal(grid_point_17, grid_point_19,horiz); horizontal(grid_point_20x21, grid_point_22x23,horiz); } - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } void diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 783053df2..c13cffb6a 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -33,7 +33,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100") { show_orig_path = true; - + apply_to_clippath_and_mask = true; registerParameter( dynamic_cast(&discard_orig_path) ); registerParameter( dynamic_cast(&reflection_line) ); } @@ -42,14 +42,6 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry() { } -void -LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) -{ - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); -} - void LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) { diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 7a484a473..64a72d7b3 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -30,8 +30,6 @@ public: virtual void doOnApply (SPLPEItem const* lpeitem); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); private: diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index dd7af92a2..d611b88a1 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -31,7 +31,7 @@ LPEOffset::LPEOffset(LivePathEffectObject *lpeobject) : offset_pt(_("Offset"), _("Handle to control the distance of the offset from the curve"), "offset_pt", &wr, this) { show_orig_path = true; - + apply_to_clippath_and_mask = true; registerParameter(dynamic_cast(&offset_pt)); } @@ -57,14 +57,6 @@ static void append_half_circle(Geom::Piecewise > &pwd2, pwd2.continuousConcat(cap_pwd2); } -void -LPEOffset::doBeforeEffect (SPLPEItem const* lpeitem) -{ - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); -} - Geom::Piecewise > LPEOffset::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { diff --git a/src/live_effects/lpe-offset.h b/src/live_effects/lpe-offset.h index 997311c7d..9966fd45d 100644 --- a/src/live_effects/lpe-offset.h +++ b/src/live_effects/lpe-offset.h @@ -28,8 +28,6 @@ public: virtual void doOnApply (SPLPEItem const* lpeitem); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); private: diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index 72c1b0e99..5b29df4a7 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -56,6 +56,7 @@ LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) registerParameter(&up_right_point); registerParameter(&down_left_point); registerParameter(&down_right_point); + apply_to_clippath_and_mask = true; } LPEPerspectiveEnvelope::~LPEPerspectiveEnvelope() @@ -371,9 +372,6 @@ LPEPerspectiveEnvelope::doBeforeEffect (SPLPEItem const* lpeitem) horizontal(up_left_point, down_left_point,horiz); horizontal(up_right_point, down_right_point,horiz); } - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); setDefaults(); } diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 901519b4f..c8cdd7912 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -64,6 +64,7 @@ LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : concatenate_before_pwd2 = true; // don't split the path into its subpaths _provides_knotholder_entities = true; + apply_to_clippath_and_mask = true; } LPEPerspectivePath::~LPEPerspectivePath() @@ -100,8 +101,6 @@ LPEPerspectivePath::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Affine doc2d = Geom::Scale(1, -1) * Geom::Translate(0, item->document->getHeight().value("px")); pmat = pmat * doc2d; pmat.copy_tmat(tmat); - item->apply_to_clippath(item); - item->apply_to_mask(item); } void LPEPerspectivePath::refresh(Gtk::Entry* perspective) { diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index b4ee54f1a..105fe2fc4 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -87,6 +87,7 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) segments.param_set_increments(1, 1); segments.param_set_digits(0); seed = 0; + apply_to_clippath_and_mask = true; } LPERoughen::~LPERoughen() {} @@ -102,9 +103,6 @@ void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) displace_y.resetRandomizer(); global_randomize.resetRandomizer(); srand(1); - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } Gtk::Widget *LPERoughen::newWidget() diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index 4b62c6c65..f807bdc8d 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -60,6 +60,7 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) helper_size.param_set_digits(2); radius_helper_nodes = 6.0; + apply_to_clippath_and_mask = true; } LPESimplify::~LPESimplify() {} @@ -71,10 +72,7 @@ LPESimplify::doBeforeEffect (SPLPEItem const* lpeitem) hp.clear(); } bbox = SP_ITEM(lpeitem)->visualBounds(); - SPLPEItem * item = const_cast(lpeitem); radius_helper_nodes = helper_size; - item->apply_to_clippath(item); - item->apply_to_mask(item); } Gtk::Widget * diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index dd1a29689..1cd59b7fa 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -78,6 +78,7 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : strech.param_set_range(0, 999.0); strech.param_set_increments(0.01, 0.01); strech.param_set_digits(4); + apply_to_clippath_and_mask = true; } LPETransform2Pts::~LPETransform2Pts() @@ -167,8 +168,6 @@ LPETransform2Pts::doBeforeEffect (SPLPEItem const* lpeitem) previous_angle = transformed.angle(); previous_lenght = Geom::distance((Geom::Point)start, (Geom::Point)end); previous_start = start; - splpeitem->apply_to_clippath(splpeitem); - splpeitem->apply_to_mask(splpeitem); } void diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 7b424e019..7eda7446e 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -64,7 +64,7 @@ LPEVonKoch::LPEVonKoch(LivePathEffectObject *lpeobject) : registerParameter( dynamic_cast(&drawall) ); registerParameter( dynamic_cast(&maxComplexity) ); //registerParameter( dynamic_cast(&draw_boxes) ); - + apply_to_clippath_and_mask = true; nbgenerations.param_make_integer(); nbgenerations.param_set_range(0, Geom::infinity()); maxComplexity.param_make_integer(); @@ -262,9 +262,6 @@ LPEVonKoch::doBeforeEffect (SPLPEItem const* lpeitem) tmp_pathv.push_back(tmp_path); ref_path.set_new_value(tmp_pathv,true); } - SPLPEItem * item = const_cast(lpeitem); - item->apply_to_clippath(item); - item->apply_to_mask(item); } -- cgit v1.2.3 From 78abefac4fdb9cd2a453818d09fc868366327b7a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 14 Mar 2016 18:24:16 +0100 Subject: Order LPE list (bzr r14706) --- src/live_effects/effect.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 47fd02554..38d59a43a 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -133,25 +133,24 @@ const Util::EnumData LPETypeData[] = { /* 0.91 */ {POWERSTROKE, N_("Power stroke"), "powerstroke"}, {CLONE_ORIGINAL, N_("Clone original path"), "clone_original"}, -/* EXPERIMENTAL */ +/* 0.92 */ + {SIMPLIFY, N_("Simplify"), "simplify"}, + {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, + {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, + {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, + {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, {SHOW_HANDLES, N_("Show handles"), "show_handles"}, {ROUGHEN, N_("Roughen"), "roughen"}, {BSPLINE, N_("BSpline"), "bspline"}, {JOIN_TYPE, N_("Join type"), "join_type"}, {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, -/* Ponyscape */ +/* Ponyscape -> Inkscape 0.92*/ {ATTACH_PATH, N_("Attach path"), "attach_path"}, {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, -/* 0.91 */ - {SIMPLIFY, N_("Simplify"), "simplify"}, - {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, - {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, - {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, - {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); -- cgit v1.2.3 From 235b6bd52fd472cbc18224d4724961c70fd6214f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 14 Mar 2016 18:34:24 +0100 Subject: Fix order LPE (bzr r13708.1.41) --- src/live_effects/effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index c8696ea3a..2e811ed37 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -144,13 +144,13 @@ const Util::EnumData LPETypeData[] = { {BSPLINE, N_("BSpline"), "bspline"}, {JOIN_TYPE, N_("Join type"), "join_type"}, {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, + {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, /* Ponyscape -> Inkscape 0.92*/ {ATTACH_PATH, N_("Attach path"), "attach_path"}, {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, - {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); -- cgit v1.2.3 From 1bd6284551204ec5b44775a27069595366742ac9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 14 Mar 2016 23:56:39 +0100 Subject: Fix compiling bugs (bzr r13708.1.42) --- src/live_effects/lpe-copy_rotate.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index c60de961d..a16a21bf0 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -93,7 +93,7 @@ void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { if(fusion_paths) { - Geom::Coord angle = Geom::rad_to_deg(atan(-postmul[1]/postmul[0])); + Geom::Coord angle = Geom::deg_from_rad(atan(-postmul[1]/postmul[0])); angle += starting_angle; starting_angle.param_set_value(angle); } @@ -235,11 +235,11 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s Geom::PathVector tmp_path_helper; Geom::Path append_path = original; for (int i = 0; i < num_copies; ++i) { - Geom::Rotate rot(-Geom::deg_to_rad(rotation_angle * (i))); + Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); if(i%2 != 0) { Geom::Point A = (Geom::Point)origin; - Geom::Point B = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle*i)+starting_angle)) * size_divider; + Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); double hyp = Geom::distance(A, B); double c = (B[0] - A[0]) / hyp; // cos(alpha) @@ -299,7 +299,7 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::deg_to_rad((rotation_angle * num_copies) + starting_angle)) * size_divider; + Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle * num_copies) + starting_angle)) * size_divider; Geom::Ray base_b(divider.pointAt(1), base_point); if(Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && Geom::are_near(tmp_path_helper[0].finalPoint(),base_a)){ tmp_path_helper[0].close(); @@ -343,8 +343,8 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point line_start = origin + dir * Rotate(-deg_to_rad(starting_angle)) * size_divider; - Geom::Point line_end = origin + dir * Rotate(-deg_to_rad(rotation_angle + starting_angle)) * size_divider; + Geom::Point line_start = origin + dir * Rotate(-rad_from_deg(starting_angle)) * size_divider; + Geom::Point line_end = origin + dir * Rotate(-rad_from_deg(rotation_angle + starting_angle)) * size_divider; //Note:: beter way to do this //Whith AppendNew have problems whith the crossing order Geom::Path divider = Geom::Path(line_start); @@ -383,7 +383,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } } else { for (int i = 0; i < num_copies; ++i) { - Rotate rot(-deg_to_rad(rotation_angle * i)); + Rotate rot(-rad_from_deg(rotation_angle * i)); Affine t = pre * rot * Translate(origin); output.concat(pwd2_in * t); } -- cgit v1.2.3 From ae7a4f0320d820a6183dde933fba576bc2c9f58f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 18 Mar 2016 18:34:07 +0100 Subject: Bug #1419517 Fix Crash when applying new path effect after deleting pattern of Pattern-along-path LPE Fixed bugs: - https://launchpad.net/bugs/1419517 (bzr r14717) --- src/live_effects/parameter/path.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index e0369e662..7ea1d465c 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -294,7 +294,12 @@ void PathParam::set_new_value (Geom::PathVector const &newpath, bool write_to_svg) { remove_link(); - _pathvector = newpath; + if (newpath.empty()) { + param_set_and_write_default(); + return; + } else { + _pathvector = newpath; + } must_recalculate_pwd2 = true; if (write_to_svg) { -- cgit v1.2.3 From 56b52d05b683b379bd9711531cc052fc1d7c3ecf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 18 Mar 2016 23:30:57 +0100 Subject: Fix Krzysztof comments on merge proposal (bzr r13708.1.43) --- src/live_effects/lpe-copy_rotate.cpp | 203 +++++++++++++++++++---------------- src/live_effects/lpe-copy_rotate.h | 17 +-- 2 files changed, 109 insertions(+), 111 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index a16a21bf0..83175f3e2 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -44,6 +44,29 @@ public: } // namespace CR +int +pointSideOfLine(Geom::Point const &A, Geom::Point const &B, Geom::Point const &X) +{ + //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line + double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); + return (pos < 0) ? -1 : (pos > 0); +} + +bool +pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) +{ + //http://totologic.blogspot.com.es/2014/01/accurate-point-in-triangle-test.html + using Geom::X; + using Geom::Y; + double denominator = (p1[X]*(p2[Y] - p3[Y]) + p1[Y]*(p3[X] - p2[X]) + p2[X]*p3[Y] - p2[Y]*p3[X]); + double t1 = (p[X]*(p3[Y] - p1[Y]) + p[Y]*(p1[X] - p3[X]) - p1[X]*p3[Y] + p1[Y]*p3[X]) / denominator; + double t2 = (p[X]*(p2[Y] - p1[Y]) + p[Y]*(p1[X] - p2[X]) - p1[X]*p2[Y] + p1[Y]*p2[X]) / -denominator; + double s = t1 + t2; + + return 0 <= t1 && t1 <= 1 && 0 <= t2 && t2 <= 1 && s <= 1; +} + + LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), @@ -110,22 +133,22 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - if( copies_to_360 ) { + if (copies_to_360) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if(fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0){ + if (fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0) { num_copies.param_set_value(floor(360/rotation_angle)); } - if(fusion_paths && copies_to_360) { + if (fusion_paths && copies_to_360) { num_copies.param_set_increments(2,2); - if((int)num_copies%2 !=0) { + if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); } } else { num_copies.param_set_increments(1,1); } - if(dist_angle_handle < 1.0) { + if (dist_angle_handle < 1.0) { dist_angle_handle = 1.0; } A = Point(boundingbox_X.min(), boundingbox_Y.middle()); @@ -135,7 +158,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; - if( fusion_paths || copies_to_360 ) { + if ( fusion_paths || copies_to_360 ) { rot_pos = origin; } SPLPEItem * item = const_cast(lpeitem); @@ -143,30 +166,8 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) item->apply_to_mask(item); } -int -LPECopyRotate::pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X) -{ - //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); - return (pos < 0) ? -1 : (pos > 0); -} - -bool -LPECopyRotate::pointInTriangle(Geom::Point p, Geom::Point p1, Geom::Point p2, Geom::Point p3) -{ - //http://totologic.blogspot.com.es/2014/01/accurate-point-in-triangle-test.html - using Geom::X; - using Geom::Y; - double denominator = (p1[X]*(p2[Y] - p3[Y]) + p1[Y]*(p3[X] - p2[X]) + p2[X]*p3[Y] - p2[Y]*p3[X]); - double t1 = (p[X]*(p3[Y] - p1[Y]) + p[Y]*(p1[X] - p3[X]) - p1[X]*p3[Y] + p1[Y]*p3[X]) / denominator; - double t2 = (p[X]*(p2[Y] - p1[Y]) + p[Y]*(p1[X] - p2[X]) - p1[X]*p2[Y] + p1[Y]*p2[X]) / -denominator; - double s = t1 + t2; - - return 0 <= t1 && t1 <= 1 && 0 <= t2 && t2 <= 1 && s <= 1; -} - void -LPECopyRotate::split(Geom::PathVector &path_on,Geom::Path divider) +LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) { Geom::PathVector tmp_path; double time_start = 0.0; @@ -177,34 +178,34 @@ LPECopyRotate::split(Geom::PathVector &path_on,Geom::Path divider) for(unsigned int i = 0; i < cs.size(); i++) { crossed.push_back(cs[i].ta); } - std::sort (crossed.begin(), crossed.end()); - for(unsigned int i = 0; i < crossed.size(); i++) { - double timeEnd = crossed[i]; - Geom::Path portion_original = original.portion(time_start,timeEnd); - if(!portion_original.empty()){ + std::sort(crossed.begin(), crossed.end()); + for (unsigned int i = 0; i < crossed.size(); i++) { + double time_end = crossed[i]; + Geom::Path portion_original = original.portion(time_start,time_end); + if (!portion_original.empty()) { Geom::Point side_checker = portion_original.pointAt(0.001); position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); - if(rotation_angle != 180) { + if (rotation_angle != 180) { position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } - if(position == 1) { + if (position == 1) { tmp_path.push_back(portion_original); } portion_original.clear(); - time_start = timeEnd; + time_start = time_end; } } position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); - if(rotation_angle != 180) { + if (rotation_angle != 180) { position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } - if(cs.size() > 0 && position == 1) { + if (cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); if(!portion_original.empty()){ if (!original.closed()) { tmp_path.push_back(portion_original); } else { - if(tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { + if (tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { portion_original.setFinal(tmp_path[0].initialPoint()); portion_original.append(tmp_path[0]); tmp_path[0] = portion_original; @@ -215,7 +216,7 @@ LPECopyRotate::split(Geom::PathVector &path_on,Geom::Path divider) portion_original.clear(); } } - if(cs.size()==0 && position == 1) { + if (cs.size()==0 && position == 1) { tmp_path.push_back(original); } path_on = tmp_path; @@ -235,9 +236,11 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s Geom::PathVector tmp_path_helper; Geom::Path append_path = original; for (int i = 0; i < num_copies; ++i) { + Geom::Path last_helper; + Geom::Path start_helper; Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); - if(i%2 != 0) { + if (i%2 != 0) { Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); @@ -257,72 +260,82 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s append_path = original; } append_path *= m; - if(i != 0 && tmp_path_helper.size() > 0 &&( Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.finalPoint()))) { - Geom::Path tmp_append = append_path.reversed(); - tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); - tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.initialPoint())) { - Geom::Path tmp_append = append_path; - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); - tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); - tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); - } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),append_path.initialPoint())) { - Geom::Path tmp_append = append_path; - tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); - tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),append_path.finalPoint())) { - Geom::Path tmp_append = append_path.reversed(); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); - tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); - tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); - } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),append_path.finalPoint())) { - Geom::Path tmp_append = append_path.reversed(); - tmp_append.setInitial(tmp_path_helper[0].finalPoint()); - tmp_path_helper[0].append(tmp_append); - } else if(i != 0 && tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].initialPoint(),append_path.initialPoint())) { - Geom::Path tmp_append = append_path; - tmp_path_helper[0] = tmp_path_helper[0].reversed(); - tmp_append.setInitial(tmp_path_helper[0].finalPoint()); - tmp_path_helper[0].append(tmp_append); - tmp_path_helper[0] = tmp_path_helper[0].reversed(); + if (i != 0 && tmp_path_helper.size() > 0) { + last_helper = tmp_path_helper[tmp_path_helper.size()-1]; + start_helper = tmp_path_helper[0]; + if (Geom::are_near(last_helper.finalPoint(), append_path.finalPoint())) { + Geom::Path tmp_append = append_path.reversed(); + tmp_append.setInitial(last_helper.finalPoint()); + last_helper.append(tmp_append); + } else if (Geom::are_near(last_helper.initialPoint(), append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + last_helper = last_helper.reversed(); + tmp_append.setInitial(last_helper.finalPoint()); + last_helper.append(tmp_append); + last_helper = last_helper.reversed(); + } else if (Geom::are_near(last_helper.finalPoint(), append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + tmp_append.setInitial(last_helper.finalPoint()); + last_helper.append(tmp_append); + } else if (Geom::are_near(last_helper.initialPoint(), append_path.finalPoint())) { + Geom::Path tmp_append = append_path.reversed(); + last_helper = last_helper.reversed(); + tmp_append.setInitial(last_helper.finalPoint()); + last_helper.append(tmp_append); + last_helper = last_helper.reversed(); + } else if (Geom::are_near(start_helper.finalPoint(), append_path.finalPoint())) { + Geom::Path tmp_append = append_path.reversed(); + tmp_append.setInitial(start_helper.finalPoint()); + start_helper.append(tmp_append); + } else if (Geom::are_near(start_helper.initialPoint(), append_path.initialPoint())) { + Geom::Path tmp_append = append_path; + start_helper = start_helper.reversed(); + tmp_append.setInitial(start_helper.finalPoint()); + start_helper.append(tmp_append); + start_helper = start_helper.reversed(); + } else { + tmp_path_helper.push_back(append_path); + } } else { tmp_path_helper.push_back(append_path); } - if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),tmp_path_helper[tmp_path_helper.size()-1].initialPoint())) { - tmp_path_helper[tmp_path_helper.size()-1].close(); + if (tmp_path_helper.size() > 0) { + if ( Geom::are_near(last_helper.finalPoint(),last_helper.initialPoint())) { + last_helper.close(); + } } } - if(rotation_angle * num_copies != 360 && tmp_path_helper.size() > 0){ + if (rotation_angle * num_copies != 360 && tmp_path_helper.size() > 0) { + Geom::Path last_helper = tmp_path_helper[tmp_path_helper.size()-1]; + Geom::Path start_helper = tmp_path_helper[0]; Geom::Ray base_a(divider.pointAt(1),divider.pointAt(0)); double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle * num_copies) + starting_angle)) * size_divider; Geom::Ray base_b(divider.pointAt(1), base_point); - if(Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && Geom::are_near(tmp_path_helper[0].finalPoint(),base_a)){ - tmp_path_helper[0].close(); - if(tmp_path_helper.size() > 1){ - tmp_path_helper[tmp_path_helper.size()-1].close(); + if (Geom::are_near(start_helper.initialPoint(),base_a) && Geom::are_near(start_helper.finalPoint(),base_a)) { + start_helper.close(); + if (tmp_path_helper.size() > 1) { + last_helper.close(); } - } else if(Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),base_b) && - Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)){ - tmp_path_helper[0].close(); - if(tmp_path_helper.size() > 1){ - tmp_path_helper[tmp_path_helper.size()-1].close(); + } else if (Geom::are_near(last_helper.initialPoint(),base_b) && + Geom::are_near(last_helper.finalPoint(),base_b)) { + start_helper.close(); + if (tmp_path_helper.size() > 1) { + last_helper.close(); } - } else if((Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)) || - (Geom::are_near(tmp_path_helper[0].initialPoint(),base_b) && Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_a))){ - Geom::Path close_path = Geom::Path(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + } else if ((Geom::are_near(start_helper.initialPoint(),base_a) && Geom::are_near(last_helper.finalPoint(),base_b)) || + (Geom::are_near(start_helper.initialPoint(),base_b) && Geom::are_near(last_helper.finalPoint(),base_a))) { + Geom::Path close_path = Geom::Path(last_helper.finalPoint()); close_path.appendNew((Geom::Point)origin); - close_path.appendNew(tmp_path_helper[0].initialPoint()); - tmp_path_helper[0].append(close_path); + close_path.appendNew(start_helper.initialPoint()); + start_helper.append(close_path); } } - if(tmp_path_helper.size() > 0 && Geom::are_near(tmp_path_helper[0].finalPoint(),tmp_path_helper[0].initialPoint())) { - tmp_path_helper[0].close(); + if (tmp_path_helper.size() > 0 && Geom::are_near(start_helper.finalPoint(),start_helper.initialPoint())) { + start_helper.close(); } tmp_path.insert(tmp_path.end(), tmp_path_helper.begin(), tmp_path_helper.end()); tmp_path_helper.clear(); @@ -336,7 +349,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if(num_copies == 1 && !fusion_paths) { + if (num_copies == 1 && !fusion_paths) { return pwd2_in; } @@ -352,7 +365,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p divider.appendNew(line_end); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); - if(fusion_paths) { + if (fusion_paths) { Geom::PathVector path_out; Geom::PathVector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); @@ -368,7 +381,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p } } Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()) { + if (end_open && path_it->closed()) { original.close(false); original.appendNew( original.initialPoint() ); original.close(true); @@ -378,7 +391,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); tmp_path.clear(); } - if(path_out.size()>0) { + if (path_out.size()>0) { output = paths_to_pw(path_out); } } else { diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index e45fa6d37..077699b80 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -31,25 +31,13 @@ class LPECopyRotate : public Effect, GroupBBoxEffect { public: LPECopyRotate(LivePathEffectObject *lpeobject); virtual ~LPECopyRotate(); - virtual void doOnApply (SPLPEItem const* lpeitem); - virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); - - virtual bool pointInTriangle(Geom::Point p, Geom::Point p0, Geom::Point p1, Geom::Point p2); - - virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); - virtual void split(Geom::PathVector &path_in,Geom::Path divider); - virtual void resetDefaults(SPItem const* item); - virtual void transform_multiply(Geom::Affine const& postmul, bool set); - /* the knotholder entity classes must be declared friends */ friend class CR::KnotHolderEntityStartingAngle; friend class CR::KnotHolderEntityRotationAngle; @@ -64,16 +52,13 @@ private: ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copies_to_360; - BoolParam fusion_paths; - + BoolParam fusion_paths ; Geom::Point A; Geom::Point B; Geom::Point dir; - Geom::Point start_pos; Geom::Point rot_pos; double dist_angle_handle; - LPECopyRotate(const LPECopyRotate&); LPECopyRotate& operator=(const LPECopyRotate&); }; -- cgit v1.2.3 From 16a30a307c06154881b9c563cb77309810a15baf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 19 Mar 2016 01:13:27 +0100 Subject: Fix more Krzysztof comments on merge proposal, temporary disable LPE on clip and paths (bzr r13708.1.44) --- src/live_effects/lpe-copy_rotate.cpp | 147 ++++++++++++++++++----------------- src/live_effects/lpe-copy_rotate.h | 4 +- 2 files changed, 77 insertions(+), 74 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 83175f3e2..f204f8608 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -74,7 +74,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fusion_paths(_("Fusioned paths"), _("Fusion paths by helper line"), "fusion_paths", &wr, this, false), + fuse_paths(_("Fuse paths"), _("Fuse paths by helper line"), "fuse_paths", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -83,7 +83,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : // register all your parameters here, so Inkscape knows which parameters this effect has: registerParameter(&copies_to_360); - registerParameter(&fusion_paths); + registerParameter(&fuse_paths); registerParameter(&starting_angle); registerParameter(&rotation_angle); registerParameter(&num_copies); @@ -115,7 +115,7 @@ LPECopyRotate::doOnApply(SPLPEItem const* lpeitem) void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { - if(fusion_paths) { + if(fuse_paths) { Geom::Coord angle = Geom::deg_from_rad(atan(-postmul[1]/postmul[0])); angle += starting_angle; starting_angle.param_set_value(angle); @@ -136,10 +136,10 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) if (copies_to_360) { rotation_angle.param_set_value(360.0/(double)num_copies); } - if (fusion_paths && rotation_angle * num_copies > 360 && rotation_angle > 0) { + if (fuse_paths && rotation_angle * num_copies > 360 && rotation_angle > 0) { num_copies.param_set_value(floor(360/rotation_angle)); } - if (fusion_paths && copies_to_360) { + if (fuse_paths && copies_to_360) { num_copies.param_set_increments(2,2); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); @@ -158,7 +158,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) // likely due to SVG's choice of coordinate system orientation (max) start_pos = origin + dir * Rotate(-rad_from_deg(starting_angle)) * dist_angle_handle; rot_pos = origin + dir * Rotate(-rad_from_deg(rotation_angle+starting_angle)) * dist_angle_handle; - if ( fusion_paths || copies_to_360 ) { + if ( fuse_paths || copies_to_360 ) { rot_pos = origin; } SPLPEItem * item = const_cast(lpeitem); @@ -235,9 +235,8 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s } Geom::PathVector tmp_path_helper; Geom::Path append_path = original; + for (int i = 0; i < num_copies; ++i) { - Geom::Path last_helper; - Geom::Path start_helper; Geom::Rotate rot(-Geom::rad_from_deg(rotation_angle * (i))); Geom::Affine m = pre * rot * Geom::Translate(origin); if (i%2 != 0) { @@ -251,8 +250,8 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s Geom::Affine m2(c, -s, s, c, 0.0, 0.0); Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); - Geom::Affine tmpM = m1.inverse() * m2; - m = tmpM; + Geom::Affine tmp_m = m1.inverse() * m2; + m = tmp_m; m = m * sca; m = m * m2.inverse(); m = m * m1; @@ -260,82 +259,86 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s append_path = original; } append_path *= m; - if (i != 0 && tmp_path_helper.size() > 0) { - last_helper = tmp_path_helper[tmp_path_helper.size()-1]; - start_helper = tmp_path_helper[0]; - if (Geom::are_near(last_helper.finalPoint(), append_path.finalPoint())) { + if (tmp_path_helper.size() > 0) { + if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(), append_path.finalPoint())) { Geom::Path tmp_append = append_path.reversed(); - tmp_append.setInitial(last_helper.finalPoint()); - last_helper.append(tmp_append); - } else if (Geom::are_near(last_helper.initialPoint(), append_path.initialPoint())) { + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + } else if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(), append_path.initialPoint())) { Geom::Path tmp_append = append_path; - last_helper = last_helper.reversed(); - tmp_append.setInitial(last_helper.finalPoint()); - last_helper.append(tmp_append); - last_helper = last_helper.reversed(); - } else if (Geom::are_near(last_helper.finalPoint(), append_path.initialPoint())) { + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); + } else if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(), append_path.initialPoint())) { Geom::Path tmp_append = append_path; - tmp_append.setInitial(last_helper.finalPoint()); - last_helper.append(tmp_append); - } else if (Geom::are_near(last_helper.initialPoint(), append_path.finalPoint())) { + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + } else if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(), append_path.finalPoint())) { Geom::Path tmp_append = append_path.reversed(); - last_helper = last_helper.reversed(); - tmp_append.setInitial(last_helper.finalPoint()); - last_helper.append(tmp_append); - last_helper = last_helper.reversed(); - } else if (Geom::are_near(start_helper.finalPoint(), append_path.finalPoint())) { + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); + tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); + } else if (Geom::are_near(tmp_path_helper[0].finalPoint(), append_path.finalPoint())) { Geom::Path tmp_append = append_path.reversed(); - tmp_append.setInitial(start_helper.finalPoint()); - start_helper.append(tmp_append); - } else if (Geom::are_near(start_helper.initialPoint(), append_path.initialPoint())) { + tmp_append.setInitial(tmp_path_helper[0].finalPoint()); + tmp_path_helper[0].append(tmp_append); + } else if (Geom::are_near(tmp_path_helper[0].initialPoint(), append_path.initialPoint())) { Geom::Path tmp_append = append_path; - start_helper = start_helper.reversed(); - tmp_append.setInitial(start_helper.finalPoint()); - start_helper.append(tmp_append); - start_helper = start_helper.reversed(); + tmp_path_helper[0] = tmp_path_helper[0].reversed(); + tmp_append.setInitial(tmp_path_helper[0].finalPoint()); + tmp_path_helper[0].append(tmp_append); + tmp_path_helper[0] = tmp_path_helper[0].reversed(); } else { tmp_path_helper.push_back(append_path); } + if ( Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),tmp_path_helper[tmp_path_helper.size()-1].initialPoint())) { + tmp_path_helper[tmp_path_helper.size()-1].close(); + } } else { tmp_path_helper.push_back(append_path); } - if (tmp_path_helper.size() > 0) { - if ( Geom::are_near(last_helper.finalPoint(),last_helper.initialPoint())) { - last_helper.close(); - } - } } - if (rotation_angle * num_copies != 360 && tmp_path_helper.size() > 0) { - Geom::Path last_helper = tmp_path_helper[tmp_path_helper.size()-1]; - Geom::Path start_helper = tmp_path_helper[0]; - Geom::Ray base_a(divider.pointAt(1),divider.pointAt(0)); - double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); - double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); - Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle * num_copies) + starting_angle)) * size_divider; - Geom::Ray base_b(divider.pointAt(1), base_point); - if (Geom::are_near(start_helper.initialPoint(),base_a) && Geom::are_near(start_helper.finalPoint(),base_a)) { - start_helper.close(); - if (tmp_path_helper.size() > 1) { - last_helper.close(); - } - } else if (Geom::are_near(last_helper.initialPoint(),base_b) && - Geom::are_near(last_helper.finalPoint(),base_b)) { - start_helper.close(); - if (tmp_path_helper.size() > 1) { - last_helper.close(); + if (tmp_path_helper.size() > 0) { + tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1]; + tmp_path_helper[0] = tmp_path_helper[0]; + if (rotation_angle * num_copies != 360) { + Geom::Ray base_a(divider.pointAt(1),divider.pointAt(0)); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double size_divider = Geom::distance(origin,bbox) + (diagonal * 2); + Geom::Point base_point = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle * num_copies) + starting_angle)) * size_divider; + Geom::Ray base_b(divider.pointAt(1), base_point); + if (Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && + Geom::are_near(tmp_path_helper[0].finalPoint(),base_a)) + { + tmp_path_helper[0].close(); + if (tmp_path_helper.size() > 1) { + tmp_path_helper[tmp_path_helper.size()-1].close(); + } + } else if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].initialPoint(),base_b) && + Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)) + { + tmp_path_helper[0].close(); + if (tmp_path_helper.size() > 1) { + tmp_path_helper[tmp_path_helper.size()-1].close(); + } + } else if ((Geom::are_near(tmp_path_helper[0].initialPoint(),base_a) && + Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_b)) || + (Geom::are_near(tmp_path_helper[0].initialPoint(),base_b) && + Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(),base_a))) + { + Geom::Path close_path = Geom::Path(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); + close_path.appendNew((Geom::Point)origin); + close_path.appendNew(tmp_path_helper[0].initialPoint()); + tmp_path_helper[0].append(close_path); } - } else if ((Geom::are_near(start_helper.initialPoint(),base_a) && Geom::are_near(last_helper.finalPoint(),base_b)) || - (Geom::are_near(start_helper.initialPoint(),base_b) && Geom::are_near(last_helper.finalPoint(),base_a))) { - Geom::Path close_path = Geom::Path(last_helper.finalPoint()); - close_path.appendNew((Geom::Point)origin); - close_path.appendNew(start_helper.initialPoint()); - start_helper.append(close_path); } - } - if (tmp_path_helper.size() > 0 && Geom::are_near(start_helper.finalPoint(),start_helper.initialPoint())) { - start_helper.close(); + if (Geom::are_near(tmp_path_helper[0].finalPoint(),tmp_path_helper[0].initialPoint())) { + tmp_path_helper[0].close(); + } } tmp_path.insert(tmp_path.end(), tmp_path_helper.begin(), tmp_path_helper.end()); tmp_path_helper.clear(); @@ -349,7 +352,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p { using namespace Geom; - if (num_copies == 1 && !fusion_paths) { + if (num_copies == 1 && !fuse_paths) { return pwd2_in; } @@ -365,7 +368,7 @@ LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & p divider.appendNew(line_end); Piecewise > output; Affine pre = Translate(-origin) * Rotate(-rad_from_deg(starting_angle)); - if (fusion_paths) { + if (fuse_paths) { Geom::PathVector path_out; Geom::PathVector tmp_path; PathVector const original_pathv = path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h index 077699b80..87af867df 100644 --- a/src/live_effects/lpe-copy_rotate.h +++ b/src/live_effects/lpe-copy_rotate.h @@ -35,7 +35,7 @@ public: virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void setFusion(Geom::PathVector &path_in, Geom::Path divider, double sizeDivider); - virtual void split(Geom::PathVector &path_in,Geom::Path divider); + virtual void split(Geom::PathVector &path_in, Geom::Path const ÷r); virtual void resetDefaults(SPItem const* item); virtual void transform_multiply(Geom::Affine const& postmul, bool set); /* the knotholder entity classes must be declared friends */ @@ -52,7 +52,7 @@ private: ScalarParam rotation_angle; ScalarParam num_copies; BoolParam copies_to_360; - BoolParam fusion_paths ; + BoolParam fuse_paths; Geom::Point A; Geom::Point B; Geom::Point dir; -- cgit v1.2.3 From 05b3344e7b4151a0ef334ed34c5b566801094806 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 19 Mar 2016 12:17:59 +0100 Subject: Fix a problem with LPE on clips and paths making extremly slow on LPE (bzr r14719) --- src/live_effects/effect.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 38d59a43a..deed7a0a1 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -467,6 +467,10 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) pathvector_before_effect = sp_curve->get_pathvector(); } doBeforeEffect(lpeitem); + if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { + sp_lpe_item->apply_to_clippath(sp_lpe_item); + sp_lpe_item->apply_to_mask(sp_lpe_item); + } } /** -- cgit v1.2.3 From d9f06856ceb526436c47237546f3e18f24d65b9f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 19 Mar 2016 21:08:57 +0100 Subject: Start fixing Krzysztof review (bzr r13682.1.34) --- src/live_effects/lpe-mirror_symmetry.cpp | 24 ++++++++++++------------ src/live_effects/lpe-mirror_symmetry.h | 9 ++------- 2 files changed, 14 insertions(+), 19 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 9ea25dbb3..d25225797 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -52,18 +52,18 @@ public: LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), - mode(_("Mode"), _("Symetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), + mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - fusion_paths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusion_paths", &wr, this, true), - reverse_fusion(_("Reverse fusion"), _("Reverse fusion"), "reverse_fusion", &wr, this, false), - reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), - center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") + fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, true), + oposite_fuse(_("Oposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), + reflection_line(_("Axis of reflection:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), + center(_("Center of mirroring"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") { show_orig_path = true; registerParameter(&mode); registerParameter( &discard_orig_path); - registerParameter( &fusion_paths); - registerParameter( &reverse_fusion); + registerParameter( &fuse_paths); + registerParameter( &oposite_fuse); registerParameter( &reflection_line); registerParameter( ¢er); apply_to_clippath_and_mask = true; @@ -161,7 +161,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) line_m_expanded.start( line_start); line_m_expanded.appendNew( line_end); - if (!discard_orig_path && !fusion_paths) { + if (!discard_orig_path && !fuse_paths) { path_out = path_in; } @@ -181,7 +181,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) m = m * m2.inverse(); m = m * m1; - if(fusion_paths && !discard_orig_path) { + if(fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { @@ -209,7 +209,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Path portion = original.portion(time_start, timeEnd); Geom::Point middle = portion.pointAt((double)portion.size()/2.0); position = pointSideOfLine(line_start, line_end, middle); - if(reverse_fusion) { + if(oposite_fuse) { position *= -1; } if(position == 1) { @@ -226,7 +226,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) time_start = timeEnd; } position = pointSideOfLine(line_start, line_end, original.finalPoint()); - if(reverse_fusion) { + if(oposite_fuse) { position *= -1; } if(cs.size()!=0 && position == 1) { @@ -259,7 +259,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } } - if (!fusion_paths || discard_orig_path) { + if (!fuse_paths || discard_orig_path) { for (int i = 0; i < static_cast(path_in.size()); ++i) { path_out.push_back(path_in[i] * m); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index 0874f0c7e..f4e4678a7 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -42,15 +42,10 @@ class LPEMirrorSymmetry : public Effect, GroupBBoxEffect { public: LPEMirrorSymmetry(LivePathEffectObject *lpeobject); virtual ~LPEMirrorSymmetry(); - virtual void doOnApply (SPLPEItem const* lpeitem); - virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); - virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); - /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); @@ -61,8 +56,8 @@ protected: private: EnumParam mode; BoolParam discard_orig_path; - BoolParam fusion_paths; - BoolParam reverse_fusion; + BoolParam fuse_paths; + BoolParam oposite_fuse; PathParam reflection_line; Geom::Line line_separation; Geom::Point previous_center; -- cgit v1.2.3 From 7ea0b4c0ca0839a7b837759d2696259e6c91b179 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 20 Mar 2016 14:11:16 +0100 Subject: Add advert tooltip message to copy rotate (bzr r14724) --- src/live_effects/lpe-copy_rotate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f204f8608..c0c510fa6 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -74,7 +74,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fuse_paths(_("Fuse paths"), _("Fuse paths by helper line"), "fuse_paths", &wr, this, false), + fuse_paths(_("Fuse paths"), _("Fuse paths by helper line -Use fill rule: evenodd for best result-"), "fuse_paths", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; -- cgit v1.2.3 From 9f0f6845ee2584b8fdb110db408e66afad5afa26 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 20 Mar 2016 18:22:19 +0100 Subject: Various minor bugfixes to rotate copies (bzr r14728) --- src/live_effects/lpe-copy_rotate.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index c0c510fa6..f07b2c698 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -74,7 +74,7 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), - fuse_paths(_("Fuse paths"), _("Fuse paths by helper line -Use fill rule: evenodd for best result-"), "fuse_paths", &wr, this, false), + fuse_paths(_("Fuse paths"), _("Fuse paths by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), dist_angle_handle(100.0) { show_orig_path = true; @@ -143,6 +143,7 @@ LPECopyRotate::doBeforeEffect (SPLPEItem const* lpeitem) num_copies.param_set_increments(2,2); if ((int)num_copies%2 !=0) { num_copies.param_set_value(num_copies+1); + rotation_angle.param_set_value(360.0/(double)num_copies); } } else { num_copies.param_set_increments(1,1); @@ -181,6 +182,9 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) std::sort(crossed.begin(), crossed.end()); for (unsigned int i = 0; i < crossed.size(); i++) { double time_end = crossed[i]; + if(time_start == time_end){ + continue; + } Geom::Path portion_original = original.portion(time_start,time_end); if (!portion_original.empty()) { Geom::Point side_checker = portion_original.pointAt(0.001); -- cgit v1.2.3 From 400e02890fda98daad1149a13976f0e17567f6fc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 20 Mar 2016 22:51:26 +0100 Subject: Fix a bug in rotate copies on apply over a ellipse when origin and end are the center of rotation (bzr r14729) --- src/live_effects/lpe-copy_rotate.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f07b2c698..f3e05f061 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -71,8 +71,8 @@ LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : Effect(lpeobject), origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"), starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0), - rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0), - num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5), + rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 60.0), + num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 6), copies_to_360(_("360º Copies"), _("No rotation angle, fixed to 360º"), "copies_to_360", &wr, this, true), fuse_paths(_("Fuse paths"), _("Fuse paths by helper line, use fill-rule: evenodd for best result"), "fuse_paths", &wr, this, false), dist_angle_handle(100.0) @@ -199,9 +199,10 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) time_start = time_end; } } - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); + Geom::Point side_checker = original.pointAt(original.size() - 0.001); + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); if (rotation_angle != 180) { - position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); + position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if (cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); -- cgit v1.2.3 From 651e8c239d9aedfb88f31b7d0ace14facbc866d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 21 Mar 2016 02:02:35 +0100 Subject: Some improvements and bugfixes to rotate copies (bzr r14730) --- src/live_effects/lpe-copy_rotate.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index f3e05f061..d2dd437cb 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -182,12 +182,12 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) std::sort(crossed.begin(), crossed.end()); for (unsigned int i = 0; i < crossed.size(); i++) { double time_end = crossed[i]; - if(time_start == time_end){ + if (time_start == time_end || time_end - time_start < Geom::EPSILON) { continue; } Geom::Path portion_original = original.portion(time_start,time_end); if (!portion_original.empty()) { - Geom::Point side_checker = portion_original.pointAt(0.001); + Geom::Point side_checker = portion_original.pointAt(0.0001); position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); if (rotation_angle != 180) { position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); @@ -199,10 +199,9 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) time_start = time_end; } } - Geom::Point side_checker = original.pointAt(original.size() - 0.001); - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); + position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); if (rotation_angle != 180) { - position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); + position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } if (cs.size() > 0 && position == 1) { Geom::Path portion_original = original.portion(time_start, original.size()); @@ -274,7 +273,6 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); } else if (Geom::are_near(tmp_path_helper[tmp_path_helper.size()-1].finalPoint(), append_path.initialPoint())) { Geom::Path tmp_append = append_path; tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); @@ -284,7 +282,6 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); tmp_append.setInitial(tmp_path_helper[tmp_path_helper.size()-1].finalPoint()); tmp_path_helper[tmp_path_helper.size()-1].append(tmp_append); - tmp_path_helper[tmp_path_helper.size()-1] = tmp_path_helper[tmp_path_helper.size()-1].reversed(); } else if (Geom::are_near(tmp_path_helper[0].finalPoint(), append_path.finalPoint())) { Geom::Path tmp_append = append_path.reversed(); tmp_append.setInitial(tmp_path_helper[0].finalPoint()); @@ -294,7 +291,6 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s tmp_path_helper[0] = tmp_path_helper[0].reversed(); tmp_append.setInitial(tmp_path_helper[0].finalPoint()); tmp_path_helper[0].append(tmp_append); - tmp_path_helper[0] = tmp_path_helper[0].reversed(); } else { tmp_path_helper.push_back(append_path); } -- cgit v1.2.3 From 3de7e5dc56d38f9f52575f8ed47334d68e6223ad Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 24 Mar 2016 02:25:49 +0100 Subject: "Backport" some Krzysztof review parts of mirror symmetry LPE also hapens on rotate copies LPE (bzr r14740) --- src/live_effects/lpe-copy_rotate.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index d2dd437cb..efea76039 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -44,14 +44,6 @@ public: } // namespace CR -int -pointSideOfLine(Geom::Point const &A, Geom::Point const &B, Geom::Point const &X) -{ - //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (B[Geom::X]-A[Geom::X])*(X[Geom::Y]-A[Geom::Y]) - (B[Geom::Y]-A[Geom::Y])*(X[Geom::X]-A[Geom::X]); - return (pos < 0) ? -1 : (pos > 0); -} - bool pointInTriangle(Geom::Point const &p, Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) { @@ -188,7 +180,7 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) Geom::Path portion_original = original.portion(time_start,time_end); if (!portion_original.empty()) { Geom::Point side_checker = portion_original.pointAt(0.0001); - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), side_checker); + position = Geom::sgn(Geom::cross(divider[1].finalPoint() - divider[0].finalPoint(), side_checker - divider[0].finalPoint())); if (rotation_angle != 180) { position = pointInTriangle(side_checker, divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } @@ -199,7 +191,7 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) time_start = time_end; } } - position = pointSideOfLine(divider[0].finalPoint(), divider[1].finalPoint(), original.finalPoint()); + position = Geom::sgn(Geom::cross(divider[1].finalPoint() - divider[0].finalPoint(), original.finalPoint() - divider[0].finalPoint())); if (rotation_angle != 180) { position = pointInTriangle(original.finalPoint(), divider.initialPoint(), divider[0].finalPoint(), divider[1].finalPoint()); } @@ -246,13 +238,13 @@ LPECopyRotate::setFusion(Geom::PathVector &path_on, Geom::Path divider, double s if (i%2 != 0) { Geom::Point A = (Geom::Point)origin; Geom::Point B = origin + dir * Geom::Rotate(-Geom::rad_from_deg((rotation_angle*i)+starting_angle)) * size_divider; - Geom::Affine m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]); + Geom::Translate m1(A[0], A[1]); double hyp = Geom::distance(A, B); double c = (B[0] - A[0]) / hyp; // cos(alpha) double s = (B[1] - A[1]) / hyp; // sin(alpha) Geom::Affine m2(c, -s, s, c, 0.0, 0.0); - Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + Geom::Scale sca(1.0, -1.0); Geom::Affine tmp_m = m1.inverse() * m2; m = tmp_m; -- cgit v1.2.3 From 13783613a9af3770294713af80a8e17b51089266 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 24 Mar 2016 02:27:33 +0100 Subject: Fixing Krzysztof review (bzr r13682.1.36) --- src/live_effects/lpe-mirror_symmetry.cpp | 66 +++++++++++++++----------------- src/live_effects/lpe-mirror_symmetry.h | 1 - 2 files changed, 31 insertions(+), 36 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index d25225797..60ad13fc8 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -83,23 +83,28 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); - if(mode == MT_Y) { + if (mode == MT_Y) { point_a = Geom::Point(boundingbox_X.min(),center[Y]); point_b = Geom::Point(boundingbox_X.max(),center[Y]); } - if(mode == MT_X) { + if (mode == MT_X) { point_a = Geom::Point(center[X],boundingbox_Y.min()); point_b = Geom::Point(center[X],boundingbox_Y.max()); } - if( mode == MT_X || mode == MT_Y ) { + if ( mode == MT_X || mode == MT_Y ) { Geom::Path path; path.start( point_a ); path.appendNew( point_b ); reflection_line.set_new_value(path.toPwSb(), true); line_separation.setPoints(point_a, point_b); center.param_setValue(path.pointAt(0.5), true); - } else if( mode == MT_FREE) { + } else if ( mode == MT_FREE) { Geom::PathVector line_m(reflection_line.get_pathvector()); + Geom::Line line_symm; + line_symm->setPoints(line_m->initialPoint(), line_m->finalPoint()); + Geom::GenericRect bbox(boundingbox_X.min(), boundingbox_Y.min(), boundingbox_X.max(), boundingbox_Y.max()); + line_m[0].initialPoint = bbox->nearestEdgePoint(line_m->initialPoint()); + line_m[0].finalPoint = bbox->nearestEdgePoint(line_m->finalPoint()) if(!are_near(previous_center,center, 0.01)) { Geom::Point trans = center - line_m[0].pointAt(0.5); line_m[0] *= Geom::Affine(1,0,0,1,trans[X],trans[Y]); @@ -111,6 +116,7 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) center.param_setValue(line_m[0].pointAt(0.5), true); point_a = line_m[0].initialPoint(); point_b = line_m[0].finalPoint(); + reflection_line.set_new_value(line_m[0].toPwSb(), true); line_separation.setPoints(point_a, point_b); } previous_center = center; @@ -138,52 +144,42 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) previous_center = center; } -int -LPEMirrorSymmetry::pointSideOfLine(Geom::Point point_a, Geom::Point point_b, Geom::Point point_x) -{ - //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line - double pos = (point_b[Geom::X]-point_a[Geom::X])*(point_x[Geom::Y]-point_a[Geom::Y]) - (point_b[Geom::Y]-point_a[Geom::Y])*(point_x[Geom::X]-point_a[Geom::X]); - return (pos < 0) ? -1 : (pos > 0); -} Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { // Don't allow empty path parameter: - if ( reflection_line.get_pathvector().empty() ) { + Geom::PathVector line_m(reflection_line.get_pathvector()); + if ( line_m.empty() ) { return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector path_out; - Geom::Path line_m_expanded; - Geom::Point line_start = line_separation.pointAt(-100000.0); - Geom::Point line_end = line_separation.pointAt(100000.0); - line_m_expanded.start( line_start); - line_m_expanded.appendNew( line_end); - + if (!discard_orig_path && !fuse_paths) { path_out = path_in; } - Geom::Point point_a(line_start); - Geom::Point point_b(line_end); + Geom::Point point_a(line_separation.initialPoint()); + Geom::Point point_b(line_separation.finalPoint()); - Geom::Affine m1(1.0, 0.0, 0.0, 1.0, point_a[0], point_a[1]); + Geom::Translate m1(point_a[0], point_a[1]); double hyp = Geom::distance(point_a, point_b); double c = (point_b[0] - point_a[0]) / hyp; // cos(alpha) double s = (point_b[1] - point_a[1]) / hyp; // sin(alpha) Geom::Affine m2(c, -s, s, c, 0.0, 0.0); - Geom::Affine sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + Geom::Scale sca(1.0, -1.0); Geom::Affine m = m1.inverse() * m2; m = m * sca; m = m * m2.inverse(); m = m * m1; - if(fuse_paths && !discard_orig_path) { + if (fuse_paths && !discard_orig_path) { for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { + path_it != original_pathv.end(); ++path_it) + { if (path_it->empty()) { continue; } @@ -197,22 +193,22 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) end_open = true; } } - Geom::Path original = (Geom::Path)(*path_it); - if(end_open && path_it->closed()) { + Geom::Path original = path_it; + if (end_open && path_it->closed()) { original.close(false); original.appendNew( original.initialPoint() ); original.close(true); } - Geom::Crossings cs = crossings(original, line_m_expanded); - for(unsigned int i = 0; i < cs.size(); i++) { + Geom::Crossings cs = crossings(original, line_m); + for (unsigned int i = 0; i < cs.size(); i++) { double timeEnd = cs[i].ta; Geom::Path portion = original.portion(time_start, timeEnd); Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = pointSideOfLine(line_start, line_end, middle); - if(oposite_fuse) { + position = Geom::sgn(Geom::cross(point_b - point_a, middle - point_a)); + if (oposite_fuse) { position *= -1; } - if(position == 1) { + if (position == 1) { Geom::Path mirror = portion.reversed() * m; mirror.setInitial(portion.finalPoint()); portion.append(mirror); @@ -225,11 +221,11 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) portion.clear(); time_start = timeEnd; } - position = pointSideOfLine(line_start, line_end, original.finalPoint()); - if(oposite_fuse) { + position = position = Geom::sgn(Geom::cross(point_b - point_a, original.finalPoint() - point_a )); + if (oposite_fuse) { position *= -1; } - if(cs.size()!=0 && position == 1) { + if (cs.size()!=0 && position == 1) { Geom::Path portion = original.portion(time_start, original.size()); portion = portion.reversed(); Geom::Path mirror = portion.reversed() * m; @@ -250,7 +246,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) } portion.clear(); } - if(cs.size() == 0 && position == 1) { + if (cs.size() == 0 && position == 1) { temp_path.push_back(original); temp_path.push_back(original * m); } diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index f4e4678a7..cd6f2a0ce 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -44,7 +44,6 @@ public: virtual ~LPEMirrorSymmetry(); virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual int pointSideOfLine(Geom::Point A, Geom::Point B, Geom::Point X); virtual Geom::PathVector doEffect_path (Geom::PathVector const & path_in); /* the knotholder entity classes must be declared friends */ friend class MS::KnotHolderEntityCenterMirrorSymmetry; -- cgit v1.2.3 From f72d5b89423864be61cf0399f6177986fc7ccd3b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 24 Mar 2016 18:37:34 +0100 Subject: Fixes and added horizontal and vertical page mode (bzr r13682.1.38) --- src/live_effects/lpe-mirror_symmetry.cpp | 255 +++++++++++++++++++------------ src/live_effects/lpe-mirror_symmetry.h | 7 +- 2 files changed, 159 insertions(+), 103 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 60ad13fc8..9a2a54a13 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -27,11 +27,14 @@ #include <2geom/affine.h> #include "knot-holder-entity.h" #include "knotholder.h" +#include "inkscape.h" namespace Inkscape { namespace LivePathEffect { static const Util::EnumData ModeTypeData[MT_END] = { + { MT_V, N_("Vertical Page Center"), "Vertical Page Center, use select tool to move item instead line" }, + { MT_H, N_("Horizontal Page Center"), "Horizontal Page Center, use select tool to move item instead line" }, { MT_FREE, N_("Free from reflection line"), "Free from path" }, { MT_X, N_("X from middle knot"), "X from middle knot" }, { MT_Y, N_("Y from middle knot"), "Y from middle knot" } @@ -48,24 +51,38 @@ public: virtual Geom::Point knot_get() const; }; +class KnotHolderEntityStartMirrorSymmetry : public LPEKnotHolderEntity { +public: + KnotHolderEntityStartMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + +class KnotHolderEntityEndMirrorSymmetry : public LPEKnotHolderEntity { +public: + KnotHolderEntityEndMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect){}; + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; +}; + } // namespace MS LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : Effect(lpeobject), mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), - fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, true), + fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), oposite_fuse(_("Oposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), - reflection_line(_("Axis of reflection:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"), - center(_("Center of mirroring"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring") + start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), + end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring") { show_orig_path = true; registerParameter(&mode); registerParameter( &discard_orig_path); registerParameter( &fuse_paths); registerParameter( &oposite_fuse); - registerParameter( &reflection_line); - registerParameter( ¢er); + registerParameter( &start_point); + registerParameter( &end_point); apply_to_clippath_and_mask = true; } @@ -79,51 +96,60 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) { using namespace Geom; - SPLPEItem * item = const_cast(lpeitem); Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); if (mode == MT_Y) { - point_a = Geom::Point(boundingbox_X.min(),center[Y]); - point_b = Geom::Point(boundingbox_X.max(),center[Y]); + point_a = Geom::Point(boundingbox_X.min(),center_point[Y]); + point_b = Geom::Point(boundingbox_X.max(),center_point[Y]); } if (mode == MT_X) { - point_a = Geom::Point(center[X],boundingbox_Y.min()); - point_b = Geom::Point(center[X],boundingbox_Y.max()); + point_a = Geom::Point(center_point[X],boundingbox_Y.min()); + point_b = Geom::Point(center_point[X],boundingbox_Y.max()); } + line_separation.setPoints(point_a, point_b); if ( mode == MT_X || mode == MT_Y ) { - Geom::Path path; - path.start( point_a ); - path.appendNew( point_b ); - reflection_line.set_new_value(path.toPwSb(), true); - line_separation.setPoints(point_a, point_b); - center.param_setValue(path.pointAt(0.5), true); + start_point.param_setValue(point_a); + end_point.param_setValue(point_b); + center_point = Geom::middle_point(point_a, point_b); } else if ( mode == MT_FREE) { - Geom::PathVector line_m(reflection_line.get_pathvector()); - Geom::Line line_symm; - line_symm->setPoints(line_m->initialPoint(), line_m->finalPoint()); - Geom::GenericRect bbox(boundingbox_X.min(), boundingbox_Y.min(), boundingbox_X.max(), boundingbox_Y.max()); - line_m[0].initialPoint = bbox->nearestEdgePoint(line_m->initialPoint()); - line_m[0].finalPoint = bbox->nearestEdgePoint(line_m->finalPoint()) - if(!are_near(previous_center,center, 0.01)) { - Geom::Point trans = center - line_m[0].pointAt(0.5); - line_m[0] *= Geom::Affine(1,0,0,1,trans[X],trans[Y]); - point_a = line_m[0].initialPoint(); - point_b = line_m[0].finalPoint(); - reflection_line.set_new_value(line_m[0].toPwSb(), true); - line_separation.setPoints(point_a, point_b); + if(!are_near(previous_center,center_point, 0.01)) { + Geom::Point trans = center_point - previous_center; + start_point.param_setValue(start_point * trans); + end_point.param_setValue(end_point * trans); + line_separation.setPoints(start_point, end_point); } else { - center.param_setValue(line_m[0].pointAt(0.5), true); - point_a = line_m[0].initialPoint(); - point_b = line_m[0].finalPoint(); - reflection_line.set_new_value(line_m[0].toPwSb(), true); - line_separation.setPoints(point_a, point_b); + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + line_separation.setPoints(start_point, end_point); + } + } else if ( mode == MT_V){ + if(SP_ACTIVE_DESKTOP){ + SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); + Geom::Rect view_box_rect = doc->getViewBox(); + Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); + sp *= lpeitem->transform.inverse(); + start_point.param_setValue(sp); + Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); + ep *= lpeitem->transform.inverse(); + end_point.param_setValue(ep); + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + line_separation.setPoints(start_point, end_point); + } + } else { //horizontal page + if(SP_ACTIVE_DESKTOP){ + SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); + Geom::Rect view_box_rect = doc->getViewBox(); + Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); + sp *= lpeitem->transform.inverse(); + start_point.param_setValue(sp); + Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); + ep *= lpeitem->transform.inverse(); + end_point.param_setValue(ep); + center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); + line_separation.setPoints(start_point, end_point); } - previous_center = center; } - - item->apply_to_clippath(item); - item->apply_to_mask(item); + previous_center = center_point; } void @@ -136,23 +162,18 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem) Point point_a(boundingbox_X.max(), boundingbox_Y.min()); Point point_b(boundingbox_X.max(), boundingbox_Y.max()); Point point_c(boundingbox_X.max(), boundingbox_Y.middle()); - Geom::Path path; - path.start( point_a ); - path.appendNew( point_b ); - reflection_line.set_new_value(path.toPwSb(), true); - center.param_setValue(point_c); - previous_center = center; + start_point.param_setValue(point_a); + start_point.param_update_default(point_a); + end_point.param_setValue(point_b); + end_point.param_update_default(point_b); + center_point = point_c; + previous_center = center_point; } Geom::PathVector LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) { - // Don't allow empty path parameter: - Geom::PathVector line_m(reflection_line.get_pathvector()); - if ( line_m.empty() ) { - return path_in; - } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector path_out; @@ -183,7 +204,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) if (path_it->empty()) { continue; } - Geom::PathVector temp_path; + Geom::PathVector tmp_path; double time_start = 0.0; int position = 0; bool end_open = false; @@ -193,65 +214,88 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) end_open = true; } } - Geom::Path original = path_it; + Geom::Path original = *path_it; if (end_open && path_it->closed()) { original.close(false); original.appendNew( original.initialPoint() ); original.close(true); } - Geom::Crossings cs = crossings(original, line_m); - for (unsigned int i = 0; i < cs.size(); i++) { - double timeEnd = cs[i].ta; - Geom::Path portion = original.portion(time_start, timeEnd); - Geom::Point middle = portion.pointAt((double)portion.size()/2.0); - position = Geom::sgn(Geom::cross(point_b - point_a, middle - point_a)); - if (oposite_fuse) { - position *= -1; - } - if (position == 1) { - Geom::Path mirror = portion.reversed() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - if(i!=0) { - portion.setFinal(portion.initialPoint()); - portion.close(); + Geom::Point s = start_point; + Geom::Point e = end_point; + double dir = line_separation.angle(); + double diagonal = Geom::distance(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + Geom::Rect bbox(Geom::Point(boundingbox_X.min(),boundingbox_Y.min()),Geom::Point(boundingbox_X.max(),boundingbox_Y.max())); + double size_divider = Geom::distance(center_point, bbox) + diagonal; + s = Geom::Point::polar(dir,size_divider) + center_point; + e = Geom::Point::polar(dir + Geom::rad_from_deg(180),size_divider) + center_point; + Geom::Path divider = Geom::Path(s); + divider.appendNew(e); + Geom::Crossings cs = crossings(original, divider); + std::vector crossed; + for(unsigned int i = 0; i < cs.size(); i++) { + crossed.push_back(cs[i].ta); + } + std::sort(crossed.begin(), crossed.end()); + for (unsigned int i = 0; i < crossed.size(); i++) { + double time_end = crossed[i]; + if (time_start != time_end && time_end - time_start > Geom::EPSILON) { + Geom::Path portion = original.portion(time_start, time_end); + if (!portion.empty()) { + Geom::Point middle = portion.pointAt((double)portion.size()/2.0); + position = Geom::sgn(Geom::cross(e - s, middle - s)); + if (!oposite_fuse) { + position *= -1; + } + if (position == 1) { + Geom::Path mirror = portion.reversed() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + if(i!=0) { + portion.setFinal(portion.initialPoint()); + portion.close(); + } + tmp_path.push_back(portion); + } + portion.clear(); } - temp_path.push_back(portion); } - portion.clear(); - time_start = timeEnd; + time_start = time_end; } - position = position = Geom::sgn(Geom::cross(point_b - point_a, original.finalPoint() - point_a )); - if (oposite_fuse) { + position = Geom::sgn(Geom::cross(e - s, original.finalPoint() - s)); + if (!oposite_fuse) { position *= -1; } if (cs.size()!=0 && position == 1) { - Geom::Path portion = original.portion(time_start, original.size()); - portion = portion.reversed(); - Geom::Path mirror = portion.reversed() * m; - mirror.setInitial(portion.finalPoint()); - portion.append(mirror); - portion = portion.reversed(); - if (!original.closed()) { - temp_path.push_back(portion); - } else { - if(cs.size() >1 ) { - portion.setFinal(temp_path[0].initialPoint()); - portion.setInitial(temp_path[0].finalPoint()); - temp_path[0].append(portion); - } else { - temp_path.push_back(portion); + if (time_start != original.size() && original.size() - time_start > Geom::EPSILON) { + Geom::Path portion = original.portion(time_start, original.size()); + if (!portion.empty()) { + portion = portion.reversed(); + Geom::Path mirror = portion.reversed() * m; + mirror.setInitial(portion.finalPoint()); + portion.append(mirror); + portion = portion.reversed(); + if (!original.closed()) { + tmp_path.push_back(portion); + } else { + if (cs.size() > 1 && tmp_path.size() > 0 && tmp_path[0].size() > 0 ) { + portion.setFinal(tmp_path[0].initialPoint()); + portion.setInitial(tmp_path[0].finalPoint()); + tmp_path[0].append(portion); + } else { + tmp_path.push_back(portion); + } + tmp_path[0].close(); + } + portion.clear(); } - temp_path[0].close(); } - portion.clear(); } if (cs.size() == 0 && position == 1) { - temp_path.push_back(original); - temp_path.push_back(original * m); + tmp_path.push_back(original); + tmp_path.push_back(original * m); } - path_out.insert(path_out.end(), temp_path.begin(), temp_path.end()); - temp_path.clear(); + path_out.insert(path_out.end(), tmp_path.begin(), tmp_path.end()); + tmp_path.clear(); } } @@ -269,19 +313,28 @@ LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector { using namespace Geom; hp_vec.clear(); - hp_vec.push_back(reflection_line.get_pathvector()); + Geom::Path path; + Geom::Point s = start_point; + Geom::Point e = end_point; + path.start( s ); + path.appendNew( e ); + Geom::PathVector helper; + helper.push_back(path); + hp_vec.push_back(helper); } void LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + SPKnotShapeType knot_shape = SP_KNOT_SHAPE_CIRCLE; + SPKnotModeType knot_mode = SP_KNOT_MODE_XOR; + guint32 knot_color = 0x0000ff00; { - KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this); - e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, - _("Adjust the center") ); - knotholder->add(e); + KnotHolderEntity *c = new MS::KnotHolderEntityCenterMirrorSymmetry(this); + c->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, + _("Adjust the center"), knot_shape, knot_mode, knot_color ); + knotholder->add(c); } - }; namespace MS { @@ -293,7 +346,7 @@ KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point { LPEMirrorSymmetry* lpe = dynamic_cast(_effect); Geom::Point const s = snap_knot_position(p, state); - lpe->center.param_setValue(s); + lpe->center_point = s; // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating. sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true); @@ -303,7 +356,7 @@ Geom::Point KnotHolderEntityCenterMirrorSymmetry::knot_get() const { LPEMirrorSymmetry const *lpe = dynamic_cast(_effect); - return lpe->center; + return lpe->center_point; } } // namespace CR diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h index cd6f2a0ce..3a244cb7e 100644 --- a/src/live_effects/lpe-mirror_symmetry.h +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -32,6 +32,8 @@ class KnotHolderEntityCenterMirrorSymmetry; } enum ModeType { + MT_V, + MT_H, MT_FREE, MT_X, MT_Y, @@ -57,10 +59,11 @@ private: BoolParam discard_orig_path; BoolParam fuse_paths; BoolParam oposite_fuse; - PathParam reflection_line; + PointParam start_point; + PointParam end_point; Geom::Line line_separation; Geom::Point previous_center; - PointParam center; + Geom::Point center_point; LPEMirrorSymmetry(const LPEMirrorSymmetry&); LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); -- cgit v1.2.3 From 4862708928a1a9d0252ec89a4925f575be904012 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 11 Apr 2016 14:49:28 +0100 Subject: Partialy fix bug #172137. commented in bug (bzr r14778) --- src/live_effects/lpe-patternalongpath.cpp | 7 +++++++ src/live_effects/lpe-patternalongpath.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 9397d848f..911c410f9 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -259,9 +259,16 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set) // overriding the Effect class default method, disabling transform forwarding to the parameters. // only take translations into account + // Check if proportional stroke-width scaling is on + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool transform_stroke = prefs ? prefs->getBool("/options/transform/stroke", true) : true; + if (transform_stroke && !scale_y_rel) { + prop_scale.param_set_value(prop_scale * ((postmul.expansionX() + postmul.expansionY()) / 2)); + } if (postmul.isTranslation()) { pattern.param_transform_multiply(postmul, set); } + sp_lpe_item_update_patheffect (sp_lpe_item, false, true); } void diff --git a/src/live_effects/lpe-patternalongpath.h b/src/live_effects/lpe-patternalongpath.h index 3b9a17ab0..3d7fc02bc 100644 --- a/src/live_effects/lpe-patternalongpath.h +++ b/src/live_effects/lpe-patternalongpath.h @@ -42,7 +42,7 @@ public: virtual void transform_multiply(Geom::Affine const& postmul, bool set); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); - + virtual void addKnotHolderEntities(KnotHolder * knotholder, SPDesktop * desktop, SPItem * item); PathParam pattern; -- cgit v1.2.3 From 8948544b36d4caef900860cd6aa8672deb5814b0 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 13 Apr 2016 14:18:46 +0100 Subject: Remove old uses of GTK_STOCK macros (bzr r14826) --- src/live_effects/parameter/originalpatharray.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 7e3a6f5fe..4ee068ebf 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -144,7 +144,7 @@ Gtk::Widget* OriginalPathArrayParam::param_newWidget() { // Paste path to link button - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("gtk-stock", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); @@ -156,7 +156,7 @@ Gtk::Widget* OriginalPathArrayParam::param_newWidget() } { // Remove linked path - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_REMOVE, Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon("gtk-remove", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); @@ -168,7 +168,7 @@ Gtk::Widget* OriginalPathArrayParam::param_newWidget() } { // Move Down - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_GO_DOWN, Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( "gtk-go-down", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); @@ -180,7 +180,7 @@ Gtk::Widget* OriginalPathArrayParam::param_newWidget() } { // Move Down - Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_GO_UP, Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Widget *pIcon = Gtk::manage( sp_icon_get_icon( "gtk-go-up", Inkscape::ICON_SIZE_BUTTON) ); Gtk::Button *pButton = Gtk::manage(new Gtk::Button()); pButton->set_relief(Gtk::RELIEF_NONE); pIcon->show(); -- cgit v1.2.3 From e71c798f2fd8610baaddbb58d103b2ef44d65ccb Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 20 Apr 2016 23:14:10 -0700 Subject: minor warning cleanup. (bzr r14861) --- src/live_effects/parameter/filletchamferpointarray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index 117d57460..b321a5831 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -491,7 +491,7 @@ std::vector FilletChamferPointArrayParam::get_times(int index, Geom::Pat curve_it1 = subpaths[positions.first][positions.second].duplicate(); Coord it1_length = (*curve_it1).length(tolerance); double time_it1, time_it2, time_it1_B, intpart; - if(_vector.size() <= index){ + if (static_cast(_vector.size()) <= index){ std::vector out; out.push_back(0); out.push_back(1); -- cgit v1.2.3 From efb5cb4a7a22316994b7a89b51d3d0ca654dabd4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 7 May 2016 22:55:11 -0700 Subject: Clarify license. Most Inkscape source code does not specify GPL version, so it is essentially GPL v1+ under section 9. Authors of the few GPL v2 only files were contacted and all agreed to relicense under GPL v2 or later. We also have a few files copies from GIMP, which are GPL v3+, so the complete program is available under GPL v3 or later. (bzr r14873) --- src/live_effects/lpe-jointype.cpp | 2 +- src/live_effects/lpe-jointype.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index 2eef315dd..fe42932be 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -4,7 +4,7 @@ * * Copyright (C) 2014 Authors * -* Released under GNU GPL v2, read the file 'COPYING' for more information +* Released under GNU GPL v2+, read the file 'COPYING' for more information */ #include "live_effects/parameter/enum.h" diff --git a/src/live_effects/lpe-jointype.h b/src/live_effects/lpe-jointype.h index fddaeb619..ef7abdcc7 100644 --- a/src/live_effects/lpe-jointype.h +++ b/src/live_effects/lpe-jointype.h @@ -3,7 +3,7 @@ * * Copyright (C) 2014 Authors * - * Released under GNU GPL v2, read the file COPYING for more information + * Released under GNU GPL v2+, read the file COPYING for more information */ #ifndef INKSCAPE_LPE_JOINTYPE_H -- cgit v1.2.3 From 96731f992a6c14dd8a6b80075e1648356b3544ef Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 09:39:27 +0200 Subject: Fixing page transforms (bzr r13682.1.39) --- src/live_effects/lpe-mirror_symmetry.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 9a2a54a13..c4bd919f8 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -127,10 +127,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); - sp *= lpeitem->transform.inverse(); + sp *= lpeitem->i2dt_affine().inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); - ep *= lpeitem->transform.inverse(); + ep *= lpeitem->i2dt_affine().inverse(); end_point.param_setValue(ep); center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); @@ -140,10 +140,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); - sp *= lpeitem->transform.inverse(); + sp *= lpeitem->i2dt_affine().inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); - ep *= lpeitem->transform.inverse(); + ep *= lpeitem->i2dt_affine().inverse(); end_point.param_setValue(ep); center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); -- cgit v1.2.3 From d756856a3abe21eba762bf7562402feb91f257b1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 11:08:40 +0200 Subject: Fix transform in document based axis (bzr r13682.1.41) --- src/live_effects/lpe-mirror_symmetry.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index c4bd919f8..88fee4c47 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -127,10 +127,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(view_box_rect.width()/2.0, 0); - sp *= lpeitem->i2dt_affine().inverse(); + sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width()/2.0, view_box_rect.height()); - ep *= lpeitem->i2dt_affine().inverse(); + ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); @@ -140,10 +140,10 @@ LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem) SPDocument * doc = SP_ACTIVE_DESKTOP->getDocument(); Geom::Rect view_box_rect = doc->getViewBox(); Geom::Point sp = Geom::Point(0, view_box_rect.height()/2.0); - sp *= lpeitem->i2dt_affine().inverse(); + sp *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); start_point.param_setValue(sp); Geom::Point ep = Geom::Point(view_box_rect.width(), view_box_rect.height()/2.0); - ep *= lpeitem->i2dt_affine().inverse(); + ep *= i2anc_affine(SP_OBJECT(lpeitem), SP_OBJECT(SP_ACTIVE_DESKTOP->currentLayer()->parent)) .inverse(); end_point.param_setValue(ep); center_point = Geom::middle_point((Geom::Point)start_point, (Geom::Point)end_point); line_separation.setPoints(start_point, end_point); @@ -178,7 +178,7 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::PathVector path_out; if (!discard_orig_path && !fuse_paths) { - path_out = path_in; + path_out = pathv_to_linear_and_cubic_beziers(path_in); } Geom::Point point_a(line_separation.initialPoint()); -- cgit v1.2.3 From f406f7e1c62d59ac437111138bbfe69c66efe847 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 9 May 2016 01:33:44 +0200 Subject: Disable fillet-chamfer for 0.92 release (bzr r14880) --- src/live_effects/effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 437aed5bd..732c67304 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -112,6 +112,7 @@ const Util::EnumData LPETypeData[] = { {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, {TEXT_LABEL, N_("Text label"), "text_label"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, #endif /* 0.46 */ {BEND_PATH, N_("Bend"), "bend_path"}, @@ -135,7 +136,6 @@ const Util::EnumData LPETypeData[] = { {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, {SHOW_HANDLES, N_("Show handles"), "show_handles"}, -- cgit v1.2.3 From f93510e1fdca73da2e7755a5c2a40341e9355830 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Mon, 16 May 2016 16:40:00 +0200 Subject: UI. Fixing typos in original strings. Translations. PO template update. (bzr r14894) --- src/live_effects/lpe-mirror_symmetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/live_effects') diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index 88fee4c47..9f3070ff4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -72,7 +72,7 @@ LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) : mode(_("Mode"), _("Symmetry move mode"), "mode", MTConverter, &wr, this, MT_FREE), discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false), fuse_paths(_("Fuse paths"), _("Fuse original and the reflection into a single path"), "fuse_paths", &wr, this, false), - oposite_fuse(_("Oposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), + oposite_fuse(_("Opposite fuse"), _("Picks the other side of the mirror as the original"), "oposite_fuse", &wr, this, false), start_point(_("Start mirror line"), _("Start mirror line"), "start_point", &wr, this, "Adjust the start of mirroring"), end_point(_("End mirror line"), _("End mirror line"), "end_point", &wr, this, "Adjust end of mirroring") { -- cgit v1.2.3