diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-07-08 21:18:50 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-07-08 21:18:50 +0000 |
| commit | d4f8d56e508fdc427992fb950c67a98af765f187 (patch) | |
| tree | df972c0abe2d1d96d4c23ef86eb463da43bce2f4 /src/live_effects/lpe-mirror_symmetry.cpp | |
| parent | fix calligraphy and erasertools bugs introduced by rev19197 (diff) | |
| download | inkscape-d4f8d56e508fdc427992fb950c67a98af765f187.tar.gz inkscape-d4f8d56e508fdc427992fb950c67a98af765f187.zip | |
Rename LPE: mirror reflect --> mirror symmetry
(bzr r6238)
Diffstat (limited to 'src/live_effects/lpe-mirror_symmetry.cpp')
| -rw-r--r-- | src/live_effects/lpe-mirror_symmetry.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
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 <mirror_symmetry> implementation: mirrors a path with respect to a given line. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-mirror_symmetry.h" +#include <sp-path.h> +#include <display/curve.h> +#include <svg/path-string.h> + +#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<Parameter *>(&discard_orig_path) ); + registerParameter( dynamic_cast<Parameter *>(&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<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(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<Geom::Path> +LPEMirrorSymmetry::doEffect_path (std::vector<Geom::Path> const & path_in) +{ + std::vector<Geom::Path> path_out; + if (!discard_orig_path) { + path_out = path_in; + } + + std::vector<Geom::Path> 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<int>(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 : |
