From: cilix42 Date: Tue, 8 Jul 2008 21:18:50 +0000 (+0000) Subject: Rename LPE: mirror reflect --> mirror symmetry X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=76db360f5f052775326e6d406b9e1e9e2966e11a;p=inkscape.git Rename LPE: mirror reflect --> mirror symmetry --- diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 38b652106..c50c10357 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -10,7 +10,7 @@ lpe-gears.cpp lpegroupbbox.cpp lpe-knot.cpp lpe-lattice.cpp -lpe-mirror_reflect.cpp +lpe-mirror_symmetry.cpp lpeobject.cpp lpeobject-reference.cpp lpe-patternalongpath.cpp diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 366a94883..b9f864546 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -51,8 +51,8 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/lpe-circle_with_radius.h \ live_effects/lpe-perspective_path.cpp \ live_effects/lpe-perspective_path.h \ - live_effects/lpe-mirror_reflect.cpp \ - live_effects/lpe-mirror_reflect.h \ + live_effects/lpe-mirror_symmetry.cpp \ + live_effects/lpe-mirror_symmetry.h \ live_effects/lpe-circle_3pts.cpp \ live_effects/lpe-circle_3pts.h \ live_effects/lpe-angle_bisector.cpp \ diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 339e5c833..66d2334e0 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -55,7 +55,7 @@ #include "live_effects/lpe-constructgrid.h" #include "live_effects/lpe-perp_bisector.h" #include "live_effects/lpe-tangent_to_curve.h" -#include "live_effects/lpe-mirror_reflect.h" +#include "live_effects/lpe-mirror_symmetry.h" #include "live_effects/lpe-circle_3pts.h" #include "live_effects/lpe-angle_bisector.h" #include "live_effects/lpe-parallel.h" @@ -87,7 +87,7 @@ const Util::EnumData LPETypeData[INVALID_LPE] = { {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, - {MIRROR_REFLECT, N_("Mirror reflection"), "mirror_reflect"}, + {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {CIRCLE_3PTS, N_("Circle through 3 points"), "circle_3pts"}, {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, {PARALLEL, N_("Parallel"), "parallel"}, @@ -151,8 +151,8 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case TANGENT_TO_CURVE: neweffect = static_cast ( new LPETangentToCurve(lpeobj) ); break; - case MIRROR_REFLECT: - neweffect = static_cast ( new LPEMirrorReflect(lpeobj) ); + case MIRROR_SYMMETRY: + neweffect = static_cast ( new LPEMirrorSymmetry(lpeobj) ); break; case CIRCLE_3PTS: neweffect = static_cast ( new LPECircle3Pts(lpeobj) ); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 38c9ccdaa..dc5d6ec4a 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -69,7 +69,7 @@ enum EffectType { CONSTRUCT_GRID, PERP_BISECTOR, TANGENT_TO_CURVE, - MIRROR_REFLECT, + MIRROR_SYMMETRY, CIRCLE_3PTS, ANGLE_BISECTOR, PARALLEL, diff --git a/src/live_effects/lpe-mirror_reflect.cpp b/src/live_effects/lpe-mirror_reflect.cpp deleted file mode 100644 index 60e307bdb..000000000 --- a/src/live_effects/lpe-mirror_reflect.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#define INKSCAPE_LPE_MIRROR_REFLECT_CPP -/** \file - * LPE implementation: mirrors a path with respect to a given line. - */ -/* - * Authors: - * Maximilian Albert - * Johan Engelen - * - * Copyright (C) Johan Engelen 2007 - * Copyright (C) Maximilin Albert 2008 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-mirror_reflect.h" -#include -#include -#include - -#include <2geom/path.h> -#include <2geom/transforms.h> -#include <2geom/matrix.h> - -namespace Inkscape { -namespace LivePathEffect { - -LPEMirrorReflect::LPEMirrorReflect(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") -{ - show_orig_path = true; - - registerParameter( dynamic_cast(&discard_orig_path) ); - registerParameter( dynamic_cast(&reflection_line) ); -} - -LPEMirrorReflect::~LPEMirrorReflect() -{ - -} - -void -LPEMirrorReflect::acceptParamPath (SPPath *param_path) { - using namespace Geom; - - SPCurve* curve = sp_path_get_curve_for_edit (param_path); - Geom::Point A(curve->first_point().to_2geom()); - Geom::Point B(curve->last_point().to_2geom()); - - Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); - reflection_line.param_set_and_write_new_value(rline); - - SP_OBJECT(param_path)->deleteObject(true); - - // don't remove this; needed for cleanup tasks - Effect::acceptParamPath(param_path); -} - -std::vector -LPEMirrorReflect::doEffect_path (std::vector const & path_in) -{ - std::vector path_out; - if (!discard_orig_path) { - path_out = path_in; - } - - std::vector mline(reflection_line.get_pathvector()); - Geom::Point A(mline.front().initialPoint()); - Geom::Point B(mline.back().finalPoint()); - - Geom::Matrix 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::Matrix m2(c, -s, s, c, 0.0, 0.0); - Geom::Matrix sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); - - Geom::Matrix m = m1.inverse() * m2; - 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); - } - - return path_out; -} - -/* ######################## */ - -} //namespace LivePathEffect -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-mirror_reflect.h b/src/live_effects/lpe-mirror_reflect.h deleted file mode 100644 index 4fd695e0e..000000000 --- a/src/live_effects/lpe-mirror_reflect.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef INKSCAPE_LPE_MIRROR_REFLECT_H -#define INKSCAPE_LPE_MIRROR_REFLECT_H - -/** \file - * LPE implementation: mirrors a path with respect to a given line. - */ -/* - * Authors: - * Maximilian Albert - * Johan Engelen - * - * Copyright (C) Johan Engelen 2007 - * Copyright (C) Maximilin Albert 2008 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/effect.h" -#include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/point.h" -#include "live_effects/parameter/path.h" - -namespace Inkscape { -namespace LivePathEffect { - -class LPEMirrorReflect : public Effect { -public: - LPEMirrorReflect(LivePathEffectObject *lpeobject); - virtual ~LPEMirrorReflect(); - - virtual void acceptParamPath (SPPath *param_path); - virtual int acceptsNumParams() { return 2; } - - virtual std::vector doEffect_path (std::vector const & path_in); - -private: - BoolParam discard_orig_path; - PathParam reflection_line; - - LPEMirrorReflect(const LPEMirrorReflect&); - LPEMirrorReflect& operator=(const LPEMirrorReflect&); -}; - -} //namespace LivePathEffect -} //namespace Inkscape - -#endif diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp new file mode 100644 index 000000000..e41d4084d --- /dev/null +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -0,0 +1,107 @@ +#define INKSCAPE_LPE_MIRROR_SYMMETRY_CPP +/** \file + * LPE implementation: mirrors a path with respect to a given line. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilin Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-mirror_symmetry.h" +#include +#include +#include + +#include <2geom/path.h> +#include <2geom/transforms.h> +#include <2geom/matrix.h> + +namespace Inkscape { +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") +{ + show_orig_path = true; + + registerParameter( dynamic_cast(&discard_orig_path) ); + registerParameter( dynamic_cast(&reflection_line) ); +} + +LPEMirrorSymmetry::~LPEMirrorSymmetry() +{ + +} + +void +LPEMirrorSymmetry::acceptParamPath (SPPath *param_path) { + using namespace Geom; + + SPCurve* curve = sp_path_get_curve_for_edit (param_path); + Geom::Point A(curve->first_point().to_2geom()); + Geom::Point B(curve->last_point().to_2geom()); + + Piecewise > rline = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); + reflection_line.param_set_and_write_new_value(rline); + + SP_OBJECT(param_path)->deleteObject(true); + + // don't remove this; needed for cleanup tasks + Effect::acceptParamPath(param_path); +} + +std::vector +LPEMirrorSymmetry::doEffect_path (std::vector const & path_in) +{ + std::vector path_out; + if (!discard_orig_path) { + path_out = path_in; + } + + std::vector mline(reflection_line.get_pathvector()); + Geom::Point A(mline.front().initialPoint()); + Geom::Point B(mline.back().finalPoint()); + + Geom::Matrix 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::Matrix m2(c, -s, s, c, 0.0, 0.0); + Geom::Matrix sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); + + Geom::Matrix m = m1.inverse() * m2; + 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); + } + + return path_out; +} + +/* ######################## */ + +} //namespace LivePathEffect +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h new file mode 100644 index 000000000..40b0292c4 --- /dev/null +++ b/src/live_effects/lpe-mirror_symmetry.h @@ -0,0 +1,47 @@ +#ifndef INKSCAPE_LPE_MIRROR_SYMMETRY_H +#define INKSCAPE_LPE_MIRROR_SYMMETRY_H + +/** \file + * LPE implementation: mirrors a path with respect to a given line. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilin Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" +#include "live_effects/parameter/path.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEMirrorSymmetry : public Effect { +public: + LPEMirrorSymmetry(LivePathEffectObject *lpeobject); + virtual ~LPEMirrorSymmetry(); + + virtual void acceptParamPath (SPPath *param_path); + virtual int acceptsNumParams() { return 2; } + + virtual std::vector doEffect_path (std::vector const & path_in); + +private: + BoolParam discard_orig_path; + PathParam reflection_line; + + LPEMirrorSymmetry(const LPEMirrorSymmetry&); + LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif