Code

fixed another typo
[inkscape.git] / src / live_effects / lpe-mirror_reflect.cpp
1 #define INKSCAPE_LPE_MIRROR_REFLECT_CPP
2 /** \file
3  * LPE <mirror_reflection> implementation: mirrors a path with respect to a given line.
4  */
5 /*
6  * Authors:
7  *   Maximilian Albert
8  *   Johan Engelen
9  *
10  * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
11  * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include "live_effects/lpe-mirror_reflect.h"
17 #include <sp-path.h>
18 #include <display/curve.h>
19 #include <svg/path-string.h>
21 #include <2geom/path.h>
22 #include <2geom/transforms.h>
23 #include <2geom/matrix.h>
25 namespace Inkscape {
26 namespace LivePathEffect {
28 LPEMirrorReflect::LPEMirrorReflect(LivePathEffectObject *lpeobject) :
29     Effect(lpeobject),
30     reflection_line(_("Reflection line"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100")
31 {
32     registerParameter( dynamic_cast<Parameter *>(&reflection_line) );
33 }
35 LPEMirrorReflect::~LPEMirrorReflect()
36 {
38 }
40 void
41 LPEMirrorReflect::acceptParamPath (SPPath *param_path) {
42     using namespace Geom;
44     SPCurve* curve = sp_path_get_curve_for_edit (param_path);
45     Geom::Point A(curve->first_point().to_2geom());
46     Geom::Point B(curve->last_point().to_2geom());
47     
48     Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
49     reflection_line.param_set_and_write_new_value(rline);
51     SP_OBJECT(param_path)->deleteObject(true);
53     // don't remove this; needed for cleanup tasks
54     Effect::acceptParamPath(param_path);
55 }
57 std::vector<Geom::Path>
58 LPEMirrorReflect::doEffect_path (std::vector<Geom::Path> const & path_in)
59 {
60     std::vector<Geom::Path> path_out;
62     std::vector<Geom::Path> mline(reflection_line.get_pathvector());
63     Geom::Point A(mline.front().initialPoint());
64     Geom::Point B(mline.back().finalPoint());
66     Geom::Matrix m1(1.0, 0.0, 0.0, 1.0, A[0], A[1]);
67     double hyp = Geom::distance(A, B);
68     double c = (B[0] - A[0]) / hyp; // cos(alpha)
69     double s = (B[1] - A[1]) / hyp; // sin(alpha)
71     Geom::Matrix m2(c, -s, s, c, 0.0, 0.0);
72     Geom::Matrix sca(1.0, 0.0, 0.0, -1.0, 0.0, 0.0);
74     Geom::Matrix m = m1.inverse() * m2;
75     m = m * sca;
76     m = m * m2.inverse();
77     m = m * m1;
79     for (int i = 0; i < path_in.size(); ++i) {
80         path_out.push_back(path_in[i] * m);
81     }
83     return path_out;
84 }
86 /* ######################## */
88 } //namespace LivePathEffect
89 } /* namespace Inkscape */
91 /*
92   Local Variables:
93   mode:c++
94   c-file-style:"stroustrup"
95   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
96   indent-tabs-mode:nil
97   fill-column:99
98   End:
99 */
100 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :