diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.cpp | 179 | ||||
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.h | 14 |
2 files changed, 100 insertions, 93 deletions
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<SPLPEItem*>(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<Geom::LineSegment>( B ); + path.start( point_a ); + path.appendNew<Geom::LineSegment>( 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<Geom::Path> 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<Geom::Path> 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<Geom::LineSegment>( B ); + path.start( point_a ); + path.appendNew<Geom::LineSegment>( 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<Geom::Path> const & path_in) } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); std::vector<Geom::Path> path_out; - Geom::Path mlineExpanded; - Geom::Point lineStart = lineSeparation.pointAt(-100000.0); - Geom::Point lineEnd = lineSeparation.pointAt(100000.0); - mlineExpanded.start( lineStart); - mlineExpanded.appendNew<Geom::LineSegment>( 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<Geom::LineSegment>( 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<Geom::Path> 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<Geom::Path> 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<Geom::Path> 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<Geom::LineSegment>( 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<Geom::Path> 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<Geom::Path> const & path_in) temp_path.clear(); } } - - if (!fusionPaths || discard_orig_path) { + + if (!fusion_paths || discard_orig_path) { for (int i = 0; i < static_cast<int>(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<Geom::LineSegment>( 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<Geom::LineSegment>( 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<ModeType> 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; |
