diff options
| author | Maximilian Albert <maximilian.albert@gmail.com> | 2008-06-02 09:13:23 +0000 |
|---|---|---|
| committer | cilix42 <cilix42@users.sourceforge.net> | 2008-06-02 09:13:23 +0000 |
| commit | 616d67c2c67d117ce27cb16d742470ad163e5ad1 (patch) | |
| tree | 8816f10c237c60d82b83e697b212e2cbe4336104 /src | |
| parent | basic support for <title> and <desc> (diff) | |
| download | inkscape-616d67c2c67d117ce27cb16d742470ad163e5ad1.tar.gz inkscape-616d67c2c67d117ce27cb16d742470ad163e5ad1.zip | |
set eol-style:native for recently added files
(bzr r5782)
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-constructgrid.cpp | 206 | ||||
| -rw-r--r-- | src/live_effects/lpe-constructgrid.h | 86 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice.cpp | 506 | ||||
| -rw-r--r-- | src/live_effects/lpe-lattice.h | 138 | ||||
| -rw-r--r-- | src/live_effects/lpe-perp_bisector.cpp | 408 |
5 files changed, 672 insertions, 672 deletions
diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp index 1273e8b7c..144f4720d 100644 --- a/src/live_effects/lpe-constructgrid.cpp +++ b/src/live_effects/lpe-constructgrid.cpp @@ -1,103 +1,103 @@ -#define INKSCAPE_LPE_CONSTRUCTGRID_CPP
-/** \file
- * LPE Construct Grid implementation
- */
-/*
- * Authors:
- * Johan Engelen
-*
-* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "live_effects/lpe-constructgrid.h"
-
-#include <2geom/path.h>
-#include <2geom/transforms.h>
-
-#include "nodepath.h"
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-using namespace Geom;
-
-LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
- nr_x(_("Size X"), _("The size of the grid in X direction."), "nr_x", &wr, this, 5),
- nr_y(_("Size Y"), _("The size of the grid in Y direction."), "nr_y", &wr, this, 5)
-{
- registerParameter( dynamic_cast<Parameter *>(&nr_x) );
- registerParameter( dynamic_cast<Parameter *>(&nr_y) );
-
- nr_x.param_make_integer();
- nr_y.param_make_integer();
- nr_x.param_set_range(1, NR_HUGE);
- nr_y.param_set_range(1, NR_HUGE);
-}
-
-LPEConstructGrid::~LPEConstructGrid()
-{
-
-}
-
-std::vector<Geom::Path>
-LPEConstructGrid::doEffect_path (std::vector<Geom::Path> const & path_in)
-{
- // Check that the path has at least 3 nodes (i.e. 2 segments), more nodes are ignored
- if (path_in[0].size() >= 2) {
- // read the first 3 nodes:
- Geom::Path::const_iterator it ( path_in[0].begin() );
- Geom::Point first_p = (*it++).initialPoint();
- Geom::Point origin = (*it++).initialPoint();
- Geom::Point second_p = (*it++).initialPoint();
- // make first_p and second_p be the construction *vectors* of the grid:
- first_p -= origin;
- second_p -= origin;
- Geom::Translate first_translation( first_p );
- Geom::Translate second_translation( second_p );
-
- // create the gridpaths of the two directions
- Geom::Path first_path( origin );
- first_path.appendNew<LineSegment>( origin + first_p*nr_y );
- Geom::Path second_path( origin );
- second_path.appendNew<LineSegment>( origin + second_p*nr_x );
-
- // use the gridpaths and set them in the correct grid
- std::vector<Geom::Path> path_out;
- path_out.push_back(first_path);
- for (int ix = 0; ix < nr_x; ix++) {
- path_out.push_back(path_out.back() * second_translation );
- }
- path_out.push_back(second_path);
- for (int iy = 0; iy < nr_y; iy++) {
- path_out.push_back(path_out.back() * first_translation );
- }
-
- return path_out;
- } else {
- return path_in;
- }
-}
-
-void
-LPEConstructGrid::setup_nodepath(Inkscape::NodePath::Path *np)
-{
- Effect::setup_nodepath(np);
- sp_nodepath_make_straight_path(np);
-}
-
-} //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 :
+#define INKSCAPE_LPE_CONSTRUCTGRID_CPP +/** \file + * LPE Construct Grid implementation + */ +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-constructgrid.h" + +#include <2geom/path.h> +#include <2geom/transforms.h> + +#include "nodepath.h" + +namespace Inkscape { +namespace LivePathEffect { + +using namespace Geom; + +LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + nr_x(_("Size X"), _("The size of the grid in X direction."), "nr_x", &wr, this, 5), + nr_y(_("Size Y"), _("The size of the grid in Y direction."), "nr_y", &wr, this, 5) +{ + registerParameter( dynamic_cast<Parameter *>(&nr_x) ); + registerParameter( dynamic_cast<Parameter *>(&nr_y) ); + + nr_x.param_make_integer(); + nr_y.param_make_integer(); + nr_x.param_set_range(1, NR_HUGE); + nr_y.param_set_range(1, NR_HUGE); +} + +LPEConstructGrid::~LPEConstructGrid() +{ + +} + +std::vector<Geom::Path> +LPEConstructGrid::doEffect_path (std::vector<Geom::Path> const & path_in) +{ + // Check that the path has at least 3 nodes (i.e. 2 segments), more nodes are ignored + if (path_in[0].size() >= 2) { + // read the first 3 nodes: + Geom::Path::const_iterator it ( path_in[0].begin() ); + Geom::Point first_p = (*it++).initialPoint(); + Geom::Point origin = (*it++).initialPoint(); + Geom::Point second_p = (*it++).initialPoint(); + // make first_p and second_p be the construction *vectors* of the grid: + first_p -= origin; + second_p -= origin; + Geom::Translate first_translation( first_p ); + Geom::Translate second_translation( second_p ); + + // create the gridpaths of the two directions + Geom::Path first_path( origin ); + first_path.appendNew<LineSegment>( origin + first_p*nr_y ); + Geom::Path second_path( origin ); + second_path.appendNew<LineSegment>( origin + second_p*nr_x ); + + // use the gridpaths and set them in the correct grid + std::vector<Geom::Path> path_out; + path_out.push_back(first_path); + for (int ix = 0; ix < nr_x; ix++) { + path_out.push_back(path_out.back() * second_translation ); + } + path_out.push_back(second_path); + for (int iy = 0; iy < nr_y; iy++) { + path_out.push_back(path_out.back() * first_translation ); + } + + return path_out; + } else { + return path_in; + } +} + +void +LPEConstructGrid::setup_nodepath(Inkscape::NodePath::Path *np) +{ + Effect::setup_nodepath(np); + sp_nodepath_make_straight_path(np); +} + +} //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-constructgrid.h b/src/live_effects/lpe-constructgrid.h index 006ff6f54..716960d32 100644 --- a/src/live_effects/lpe-constructgrid.h +++ b/src/live_effects/lpe-constructgrid.h @@ -1,43 +1,43 @@ -#ifndef INKSCAPE_LPE_CONSTRUCTGRID_H
-#define INKSCAPE_LPE_CONSTRUCTGRID_H
-
-/** \file
- * Implementation of the construct grid LPE, see lpe-constructgrid.cpp
- */
-
-/*
- * Authors:
- * Johan Engelen
-*
-* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "live_effects/effect.h"
-#include "live_effects/parameter/parameter.h"
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-class LPEConstructGrid : public Effect {
-public:
- LPEConstructGrid(LivePathEffectObject *lpeobject);
- virtual ~LPEConstructGrid();
-
- virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
-
- virtual void setup_nodepath(Inkscape::NodePath::Path *np);
-
-private:
- ScalarParam nr_x;
- ScalarParam nr_y;
-
- LPEConstructGrid(const LPEConstructGrid&);
- LPEConstructGrid& operator=(const LPEConstructGrid&);
-};
-
-} //namespace LivePathEffect
-} //namespace Inkscape
-
-#endif // INKSCAPE_LPE_CONSTRUCTGRID_H
+#ifndef INKSCAPE_LPE_CONSTRUCTGRID_H +#define INKSCAPE_LPE_CONSTRUCTGRID_H + +/** \file + * Implementation of the construct grid LPE, see lpe-constructgrid.cpp + */ + +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEConstructGrid : public Effect { +public: + LPEConstructGrid(LivePathEffectObject *lpeobject); + virtual ~LPEConstructGrid(); + + virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in); + + virtual void setup_nodepath(Inkscape::NodePath::Path *np); + +private: + ScalarParam nr_x; + ScalarParam nr_y; + + LPEConstructGrid(const LPEConstructGrid&); + LPEConstructGrid& operator=(const LPEConstructGrid&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif // INKSCAPE_LPE_CONSTRUCTGRID_H diff --git a/src/live_effects/lpe-lattice.cpp b/src/live_effects/lpe-lattice.cpp index 001aa6b13..d70920279 100644 --- a/src/live_effects/lpe-lattice.cpp +++ b/src/live_effects/lpe-lattice.cpp @@ -1,253 +1,253 @@ -#define INKSCAPE_LPE_LATTICE_CPP
-/** \file
- * LPE <lattice> implementation
-
- */
-/*
- * Authors:
- * Johan Engelen <j.b.c.engelen@utwente.nl>
- * Steren Giannini
- * Noé Falzon
- * Victor Navez
-*
-* Copyright (C) 2007-2008 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "live_effects/lpe-lattice.h"
-
-#include "sp-shape.h"
-#include "sp-item.h"
-#include "sp-path.h"
-#include "display/curve.h"
-#include "libnr/n-art-bpath-2geom.h"
-#include "svg/svg.h"
-
-#include <2geom/sbasis.h>
-#include <2geom/sbasis-2d.h>
-#include <2geom/sbasis-geometric.h>
-#include <2geom/bezier-to-sbasis.h>
-#include <2geom/sbasis-to-bezier.h>
-#include <2geom/d2.h>
-#include <2geom/piecewise.h>
-#include <2geom/transforms.h>
-
-using namespace Geom;
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-LPELattice::LPELattice(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
-
- // initialise your parameters here:
- grid_point0(_("Control handle 0"), _("Tadah"), "gridpoint0", &wr, this),
- grid_point1(_("Control handle 1"), _("Tadah"), "gridpoint1", &wr, this),
- grid_point2(_("Control handle 2"), _("Tadah"), "gridpoint2", &wr, this),
- grid_point3(_("Control handle 3"), _("Tadah"), "gridpoint3", &wr, this),
- grid_point4(_("Control handle 4"), _("Tadah"), "gridpoint4", &wr, this),
- grid_point5(_("Control handle 5"), _("Tadah"), "gridpoint5", &wr, this),
- grid_point6(_("Control handle 6"), _("Tadah"), "gridpoint6", &wr, this),
- grid_point7(_("Control handle 7"), _("Tadah"), "gridpoint7", &wr, this),
- grid_point8(_("Control handle 8"), _("Tadah"), "gridpoint8", &wr, this),
- grid_point9(_("Control handle 9"), _("Tadah"), "gridpoint9", &wr, this),
- grid_point10(_("Control handle 10"), _("Tadah"), "gridpoint10", &wr, this),
- grid_point11(_("Control handle 11"), _("Tadah"), "gridpoint11", &wr, this),
- grid_point12(_("Control handle 12"), _("Tadah"), "gridpoint12", &wr, this),
- grid_point13(_("Control handle 13"), _("Tadah"), "gridpoint13", &wr, this),
- grid_point14(_("Control handle 14"), _("Tadah"), "gridpoint14", &wr, this),
- grid_point15(_("Control handle 15"), _("Tadah"), "gridpoint15", &wr, this)
-
-{
- // register all your parameters here, so Inkscape knows which parameters this effect has:
- registerParameter( dynamic_cast<Parameter *>(&grid_point0) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point1) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point2) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point3) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point4) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point5) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point6) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point7) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point8) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point9) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point10) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point11) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point12) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point13) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point14) );
- registerParameter( dynamic_cast<Parameter *>(&grid_point15) );
-
-
-}
-
-LPELattice::~LPELattice()
-{
-
-}
-
-
-Geom::Piecewise<Geom::D2<Geom::SBasis> >
-LPELattice::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
-{
- D2<SBasis2d> sb2;
-
- //Initialisation of the sb2
- for(unsigned dim = 0; dim < 2; dim++) {
- sb2[dim].us = 2;
- sb2[dim].vs = 2;
- const int depth = sb2[dim].us*sb2[dim].vs;
- sb2[dim].resize(depth, Linear2d(0));
- }
-
- //Grouping the point params in a convenient vector
- std::vector<Geom::Point *> handles(16);
-
- handles[0] = &grid_point0;
- handles[1] = &grid_point1;
- handles[2] = &grid_point2;
- handles[3] = &grid_point3;
- handles[4] = &grid_point4;
- handles[5] = &grid_point5;
- handles[6] = &grid_point6;
- handles[7] = &grid_point7;
- handles[8] = &grid_point8;
- handles[9] = &grid_point9;
- handles[10] = &grid_point10;
- handles[11] = &grid_point11;
- handles[12] = &grid_point12;
- handles[13] = &grid_point13;
- handles[14] = &grid_point14;
- handles[15] = &grid_point15;
-
- Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min());
-
- double width = boundingbox_X.extent();
- double height = boundingbox_Y.extent();
-
- //numbering is based on 4 rectangles.
- for(unsigned dim = 0; dim < 2; dim++) {
- Geom::Point dir(0,0);
- dir[dim] = 1;
- for(unsigned vi = 0; vi < sb2[dim].vs; vi++) {
- for(unsigned ui = 0; ui < sb2[dim].us; ui++) {
- for(unsigned iv = 0; iv < 2; iv++) {
- for(unsigned iu = 0; iu < 2; iu++) {
- unsigned corner = iu + 2*iv;
- unsigned i = ui + vi*sb2[dim].us;
-
- //This is the offset from the Upperleft point
- Geom::Point base( (ui + iu*(3-2*ui))*width/3.,
- (vi + iv*(3-2*vi))*height/3.);
-
- //Special action for corners
- if(vi == 0 && ui == 0) {
- base = Geom::Point(0,0);
- }
-
- // i = Upperleft corner of the considerated rectangle
- // corner = actual corner of the rectangle
- // origin = Upperleft point
- double dl = dot((*handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir);
- sb2[dim][i][corner] = dl/( dim ? height : width )*pow(4.0,ui+vi);
- }
- }
- }
- }
- }
-
- Piecewise<D2<SBasis> > output;
- output.push_cut(0.);
- for(unsigned i = 0; i < pwd2_in.size(); i++) {
- D2<SBasis> B = pwd2_in[i];
- B -= origin;
- B*= 1/width;
- //Here comes the magic
- D2<SBasis> tB = compose_each(sb2,B);
- tB = tB * width + origin;
-
- output.push(tB,i+1);
- }
-
- return output;
-}
-
-void
-LPELattice::doBeforeEffect (SPLPEItem *lpeitem)
-{
- original_bbox(lpeitem);
-}
-
-void
-LPELattice::resetDefaults(SPItem * item)
-{
- original_bbox(SP_LPE_ITEM(item), false);
-
- // place the 16 control points
- grid_point0[Geom::X] = boundingbox_X.min();
- grid_point0[Geom::Y] = boundingbox_Y.min();
-
- grid_point1[Geom::X] = boundingbox_X.max();
- grid_point1[Geom::Y] = boundingbox_Y.min();
-
- grid_point2[Geom::X] = boundingbox_X.min();
- grid_point2[Geom::Y] = boundingbox_Y.max();
-
- grid_point3[Geom::X] = boundingbox_X.max();
- grid_point3[Geom::Y] = boundingbox_Y.max();
-
- grid_point4[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();
- grid_point4[Geom::Y] = boundingbox_Y.min();
-
- grid_point5[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();
- grid_point5[Geom::Y] = boundingbox_Y.min();
-
- grid_point6[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();
- grid_point6[Geom::Y] = boundingbox_Y.max();
-
- grid_point7[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();
- grid_point7[Geom::Y] = boundingbox_Y.max();
-
- grid_point8[Geom::X] = boundingbox_X.min();
- grid_point8[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();
-
- grid_point9[Geom::X] = boundingbox_X.max();
- grid_point9[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();
-
- grid_point10[Geom::X] = boundingbox_X.min();
- grid_point10[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();
-
- grid_point11[Geom::X] = boundingbox_X.max();
- grid_point11[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();
-
- grid_point12[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();
- grid_point12[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();
-
- grid_point13[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();
- grid_point13[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min();
-
- grid_point14[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min();
- grid_point14[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();
-
- grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min();
- grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min();
-
-
-
-}
-
-/* ######################## */
-
-} //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 :
+#define INKSCAPE_LPE_LATTICE_CPP +/** \file + * LPE <lattice> implementation + + */ +/* + * Authors: + * Johan Engelen <j.b.c.engelen@utwente.nl> + * Steren Giannini + * Noé Falzon + * Victor Navez +* +* Copyright (C) 2007-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-lattice.h" + +#include "sp-shape.h" +#include "sp-item.h" +#include "sp-path.h" +#include "display/curve.h" +#include "libnr/n-art-bpath-2geom.h" +#include "svg/svg.h" + +#include <2geom/sbasis.h> +#include <2geom/sbasis-2d.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/piecewise.h> +#include <2geom/transforms.h> + +using namespace Geom; + +namespace Inkscape { +namespace LivePathEffect { + +LPELattice::LPELattice(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + + // initialise your parameters here: + grid_point0(_("Control handle 0"), _("Tadah"), "gridpoint0", &wr, this), + grid_point1(_("Control handle 1"), _("Tadah"), "gridpoint1", &wr, this), + grid_point2(_("Control handle 2"), _("Tadah"), "gridpoint2", &wr, this), + grid_point3(_("Control handle 3"), _("Tadah"), "gridpoint3", &wr, this), + grid_point4(_("Control handle 4"), _("Tadah"), "gridpoint4", &wr, this), + grid_point5(_("Control handle 5"), _("Tadah"), "gridpoint5", &wr, this), + grid_point6(_("Control handle 6"), _("Tadah"), "gridpoint6", &wr, this), + grid_point7(_("Control handle 7"), _("Tadah"), "gridpoint7", &wr, this), + grid_point8(_("Control handle 8"), _("Tadah"), "gridpoint8", &wr, this), + grid_point9(_("Control handle 9"), _("Tadah"), "gridpoint9", &wr, this), + grid_point10(_("Control handle 10"), _("Tadah"), "gridpoint10", &wr, this), + grid_point11(_("Control handle 11"), _("Tadah"), "gridpoint11", &wr, this), + grid_point12(_("Control handle 12"), _("Tadah"), "gridpoint12", &wr, this), + grid_point13(_("Control handle 13"), _("Tadah"), "gridpoint13", &wr, this), + grid_point14(_("Control handle 14"), _("Tadah"), "gridpoint14", &wr, this), + grid_point15(_("Control handle 15"), _("Tadah"), "gridpoint15", &wr, this) + +{ + // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast<Parameter *>(&grid_point0) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point1) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point2) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point3) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point4) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point5) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point6) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point7) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point8) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point9) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point10) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point11) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point12) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point13) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point14) ); + registerParameter( dynamic_cast<Parameter *>(&grid_point15) ); + + +} + +LPELattice::~LPELattice() +{ + +} + + +Geom::Piecewise<Geom::D2<Geom::SBasis> > +LPELattice::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) +{ + D2<SBasis2d> sb2; + + //Initialisation of the sb2 + for(unsigned dim = 0; dim < 2; dim++) { + sb2[dim].us = 2; + sb2[dim].vs = 2; + const int depth = sb2[dim].us*sb2[dim].vs; + sb2[dim].resize(depth, Linear2d(0)); + } + + //Grouping the point params in a convenient vector + std::vector<Geom::Point *> handles(16); + + handles[0] = &grid_point0; + handles[1] = &grid_point1; + handles[2] = &grid_point2; + handles[3] = &grid_point3; + handles[4] = &grid_point4; + handles[5] = &grid_point5; + handles[6] = &grid_point6; + handles[7] = &grid_point7; + handles[8] = &grid_point8; + handles[9] = &grid_point9; + handles[10] = &grid_point10; + handles[11] = &grid_point11; + handles[12] = &grid_point12; + handles[13] = &grid_point13; + handles[14] = &grid_point14; + handles[15] = &grid_point15; + + Geom::Point origin = Geom::Point(boundingbox_X.min(),boundingbox_Y.min()); + + double width = boundingbox_X.extent(); + double height = boundingbox_Y.extent(); + + //numbering is based on 4 rectangles. + for(unsigned dim = 0; dim < 2; dim++) { + Geom::Point dir(0,0); + dir[dim] = 1; + for(unsigned vi = 0; vi < sb2[dim].vs; vi++) { + for(unsigned ui = 0; ui < sb2[dim].us; ui++) { + for(unsigned iv = 0; iv < 2; iv++) { + for(unsigned iu = 0; iu < 2; iu++) { + unsigned corner = iu + 2*iv; + unsigned i = ui + vi*sb2[dim].us; + + //This is the offset from the Upperleft point + Geom::Point base( (ui + iu*(3-2*ui))*width/3., + (vi + iv*(3-2*vi))*height/3.); + + //Special action for corners + if(vi == 0 && ui == 0) { + base = Geom::Point(0,0); + } + + // i = Upperleft corner of the considerated rectangle + // corner = actual corner of the rectangle + // origin = Upperleft point + double dl = dot((*handles[corner+4*i] - (base + origin)), dir)/dot(dir,dir); + sb2[dim][i][corner] = dl/( dim ? height : width )*pow(4.0,ui+vi); + } + } + } + } + } + + Piecewise<D2<SBasis> > output; + output.push_cut(0.); + for(unsigned i = 0; i < pwd2_in.size(); i++) { + D2<SBasis> B = pwd2_in[i]; + B -= origin; + B*= 1/width; + //Here comes the magic + D2<SBasis> tB = compose_each(sb2,B); + tB = tB * width + origin; + + output.push(tB,i+1); + } + + return output; +} + +void +LPELattice::doBeforeEffect (SPLPEItem *lpeitem) +{ + original_bbox(lpeitem); +} + +void +LPELattice::resetDefaults(SPItem * item) +{ + original_bbox(SP_LPE_ITEM(item), false); + + // place the 16 control points + grid_point0[Geom::X] = boundingbox_X.min(); + grid_point0[Geom::Y] = boundingbox_Y.min(); + + grid_point1[Geom::X] = boundingbox_X.max(); + grid_point1[Geom::Y] = boundingbox_Y.min(); + + grid_point2[Geom::X] = boundingbox_X.min(); + grid_point2[Geom::Y] = boundingbox_Y.max(); + + grid_point3[Geom::X] = boundingbox_X.max(); + grid_point3[Geom::Y] = boundingbox_Y.max(); + + grid_point4[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min(); + grid_point4[Geom::Y] = boundingbox_Y.min(); + + grid_point5[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); + grid_point5[Geom::Y] = boundingbox_Y.min(); + + grid_point6[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min(); + grid_point6[Geom::Y] = boundingbox_Y.max(); + + grid_point7[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); + grid_point7[Geom::Y] = boundingbox_Y.max(); + + grid_point8[Geom::X] = boundingbox_X.min(); + grid_point8[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min(); + + grid_point9[Geom::X] = boundingbox_X.max(); + grid_point9[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min(); + + grid_point10[Geom::X] = boundingbox_X.min(); + grid_point10[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); + + grid_point11[Geom::X] = boundingbox_X.max(); + grid_point11[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); + + grid_point12[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min(); + grid_point12[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min(); + + grid_point13[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); + grid_point13[Geom::Y] = 1.0/3*boundingbox_Y.max()+2.0/3*boundingbox_Y.min(); + + grid_point14[Geom::X] = 1.0/3*boundingbox_X.max()+2.0/3*boundingbox_X.min(); + grid_point14[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); + + grid_point15[Geom::X] = 2.0/3*boundingbox_X.max()+1.0/3*boundingbox_X.min(); + grid_point15[Geom::Y] = 2.0/3*boundingbox_Y.max()+1.0/3*boundingbox_Y.min(); + + + +} + +/* ######################## */ + +} //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-lattice.h b/src/live_effects/lpe-lattice.h index ad82e2720..16c15083a 100644 --- a/src/live_effects/lpe-lattice.h +++ b/src/live_effects/lpe-lattice.h @@ -1,69 +1,69 @@ -#ifndef INKSCAPE_LPE_LATTICE_H
-#define INKSCAPE_LPE_LATTICE_H
-
-/** \file
- * LPE <lattice> implementation, see lpe-lattice.cpp.
- */
-
-/*
- * Authors:
- * Johan Engelen
- * Steren Giannini
- * Noé Falzon
- * Victor Navez
-*
-* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "live_effects/effect.h"
-#include "live_effects/parameter/point.h"
-#include "live_effects/parameter/enum.h"
-#include "live_effects/parameter/bool.h"
-
-#include "live_effects/lpegroupbbox.h"
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-class LPELattice : public Effect, GroupBBoxEffect {
-public:
-
- LPELattice(LivePathEffectObject *lpeobject);
- virtual ~LPELattice();
-
- virtual void doBeforeEffect (SPLPEItem *lpeitem);
-
- virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
-
- virtual void resetDefaults(SPItem * item);
-
-
-
-private:
- PointParam grid_point0;
- PointParam grid_point1;
- PointParam grid_point2;
- PointParam grid_point3;
- PointParam grid_point4;
- PointParam grid_point5;
- PointParam grid_point6;
- PointParam grid_point7;
- PointParam grid_point8;
- PointParam grid_point9;
- PointParam grid_point10;
- PointParam grid_point11;
- PointParam grid_point12;
- PointParam grid_point13;
- PointParam grid_point14;
- PointParam grid_point15;
-
- LPELattice(const LPELattice&);
- LPELattice& operator=(const LPELattice&);
-};
-
-} //namespace LivePathEffect
-} //namespace Inkscape
-
-#endif
+#ifndef INKSCAPE_LPE_LATTICE_H +#define INKSCAPE_LPE_LATTICE_H + +/** \file + * LPE <lattice> implementation, see lpe-lattice.cpp. + */ + +/* + * Authors: + * Johan Engelen + * Steren Giannini + * Noé Falzon + * Victor Navez +* +* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/point.h" +#include "live_effects/parameter/enum.h" +#include "live_effects/parameter/bool.h" + +#include "live_effects/lpegroupbbox.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPELattice : public Effect, GroupBBoxEffect { +public: + + LPELattice(LivePathEffectObject *lpeobject); + virtual ~LPELattice(); + + virtual void doBeforeEffect (SPLPEItem *lpeitem); + + virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in); + + virtual void resetDefaults(SPItem * item); + + + +private: + PointParam grid_point0; + PointParam grid_point1; + PointParam grid_point2; + PointParam grid_point3; + PointParam grid_point4; + PointParam grid_point5; + PointParam grid_point6; + PointParam grid_point7; + PointParam grid_point8; + PointParam grid_point9; + PointParam grid_point10; + PointParam grid_point11; + PointParam grid_point12; + PointParam grid_point13; + PointParam grid_point14; + PointParam grid_point15; + + LPELattice(const LPELattice&); + LPELattice& operator=(const LPELattice&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp index 52a21fbaf..39423df8b 100644 --- a/src/live_effects/lpe-perp_bisector.cpp +++ b/src/live_effects/lpe-perp_bisector.cpp @@ -1,204 +1,204 @@ -#define INKSCAPE_LPE_PERP_BISECTOR_CPP
-/** \file
- * LPE <perp_bisector> implementation.
- */
-/*
- * 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-perp_bisector.h"
-#include "display/curve.h"
-#include <libnr/n-art-bpath.h>
-#include "sp-path.h"
-#include "line-geometry.h"
-#include "sp-lpe-item.h"
-#include <2geom/path.h>
-
-namespace Inkscape {
-namespace LivePathEffect {
-
-/* FIXME: We should make these member functions of LPEPerpBisector.
- Is there an easy way to register member functions with knotholder?
- KNOWN BUG: Because of the above, this effect does not work well when in an LPE stack
- */
-NR::Point bisector_left_end_get(SPItem *item) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
-
- if (lpe)
- return NR::Point(lpe->C);
- else
- return NR::Point(0,0);
-}
-
-NR::Point bisector_right_end_get(SPItem *item) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
-
- if (lpe)
- return NR::Point(lpe->D);
- else
- return NR::Point(0,0);
-}
-
-void
-bisector_end_set(SPItem *item, NR::Point const &p, bool left) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
-
- if (!lpe)
- return;
-
- double lambda = Geom::nearest_point(p.to_2geom(), lpe->M, lpe->perp_dir);
- if (left) {
- lpe->C = lpe->M + lpe->perp_dir * lambda;
- lpe->length_left.param_set_value(lambda);
- } else {
- lpe->D = lpe->M + lpe->perp_dir * lambda;
- lpe->length_right.param_set_value(-lambda);
- }
-
- // 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), true, true);
-}
-
-void
-bisector_left_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- bisector_end_set(item, p);
-}
-
-void
-bisector_right_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- bisector_end_set(item, p, false);
-}
-
-NR::Point path_start_get(SPItem *item) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
-
- if (lpe)
- return NR::Point(lpe->A);
- else
- return NR::Point(0,0);
-}
-
-NR::Point path_end_get(SPItem *item) {
- Inkscape::LivePathEffect::LPEPerpBisector *lpe =
- dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)));
-
- if (lpe)
- return NR::Point(lpe->B);
- else
- return NR::Point(0,0);
-}
-
-void
-path_set_start_end(SPItem *item, NR::Point const &p, bool start) {
- SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(item)); // TODO: Should we use sp_shape_get_curve()?
- NR::Matrix const i2d (sp_item_i2d_affine (SP_ITEM(item)));
-
- Geom::Point A, B;
- if (start) {
- A = p.to_2geom();
- B = (curve->last_point()).to_2geom();
- } else {
- A = (curve->first_point()).to_2geom();
- B = (p.to_2geom());
- }
-
- SPCurve *c = new SPCurve();
- c->moveto(A);
- c->lineto(B);
- sp_path_set_original_curve(SP_PATH(item), c, TRUE, true);
- c->unref();
-}
-
-void path_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- path_set_start_end(item, p);
-}
-
-void path_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) {
- path_set_start_end(item, p, false);
-}
-
-LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
- length_left(_("Length left"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 200),
- length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 200),
- A(0,0), B(0,0), M(0,0), C(0,0), D(0,0), perp_dir(0,0)
-{
- // register all your parameters here, so Inkscape knows which parameters this effect has:
- registerParameter( dynamic_cast<Parameter *>(&length_left) );
- registerParameter( dynamic_cast<Parameter *>(&length_right) );
-
- registerKnotHolderHandle(path_start_set, path_start_get);
- registerKnotHolderHandle(path_end_set, path_end_get);
- registerKnotHolderHandle(bisector_left_end_set, bisector_left_end_get);
- registerKnotHolderHandle(bisector_right_end_set, bisector_right_end_get);
-}
-
-LPEPerpBisector::~LPEPerpBisector()
-{
-}
-
-void
-LPEPerpBisector::doOnApply (SPLPEItem *lpeitem)
-{
- /* make the path a straight line */
- SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(lpeitem)); // TODO: Should we use sp_shape_get_curve()?
-
- Geom::Point A((curve->first_point()).to_2geom());
- Geom::Point B((curve->last_point()).to_2geom());
-
- SPCurve *c = new SPCurve();
- c->moveto(A);
- c->lineto(B);
- // TODO: Why doesn't sp_path_set_original_curve(SP_PATH(lpeitem), c, TRUE, true) work?
- SP_PATH(lpeitem)->original_curve = c->ref();
- c->unref();
-}
-
-
-Geom::Piecewise<Geom::D2<Geom::SBasis> >
-LPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
-{
- using namespace Geom;
-
- Piecewise<D2<SBasis> > output;
-
- A = pwd2_in.firstValue();
- B = pwd2_in.lastValue();
- M = (A + B)/2;
-
- perp_dir = unit_vector((B - A).ccw());
-
- C = M + perp_dir * length_left;
- D = M - perp_dir * length_right;
-
- output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
-
- return output;
-}
-
-/* ######################## */
-
-} //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 :
+#define INKSCAPE_LPE_PERP_BISECTOR_CPP +/** \file + * LPE <perp_bisector> implementation. + */ +/* + * 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-perp_bisector.h" +#include "display/curve.h" +#include <libnr/n-art-bpath.h> +#include "sp-path.h" +#include "line-geometry.h" +#include "sp-lpe-item.h" +#include <2geom/path.h> + +namespace Inkscape { +namespace LivePathEffect { + +/* FIXME: We should make these member functions of LPEPerpBisector. + Is there an easy way to register member functions with knotholder? + KNOWN BUG: Because of the above, this effect does not work well when in an LPE stack + */ +NR::Point bisector_left_end_get(SPItem *item) { + Inkscape::LivePathEffect::LPEPerpBisector *lpe = + dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))); + + if (lpe) + return NR::Point(lpe->C); + else + return NR::Point(0,0); +} + +NR::Point bisector_right_end_get(SPItem *item) { + Inkscape::LivePathEffect::LPEPerpBisector *lpe = + dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))); + + if (lpe) + return NR::Point(lpe->D); + else + return NR::Point(0,0); +} + +void +bisector_end_set(SPItem *item, NR::Point const &p, bool left) { + Inkscape::LivePathEffect::LPEPerpBisector *lpe = + dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))); + + if (!lpe) + return; + + double lambda = Geom::nearest_point(p.to_2geom(), lpe->M, lpe->perp_dir); + if (left) { + lpe->C = lpe->M + lpe->perp_dir * lambda; + lpe->length_left.param_set_value(lambda); + } else { + lpe->D = lpe->M + lpe->perp_dir * lambda; + lpe->length_right.param_set_value(-lambda); + } + + // 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), true, true); +} + +void +bisector_left_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { + bisector_end_set(item, p); +} + +void +bisector_right_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { + bisector_end_set(item, p, false); +} + +NR::Point path_start_get(SPItem *item) { + Inkscape::LivePathEffect::LPEPerpBisector *lpe = + dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))); + + if (lpe) + return NR::Point(lpe->A); + else + return NR::Point(0,0); +} + +NR::Point path_end_get(SPItem *item) { + Inkscape::LivePathEffect::LPEPerpBisector *lpe = + dynamic_cast<Inkscape::LivePathEffect::LPEPerpBisector *> (sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))); + + if (lpe) + return NR::Point(lpe->B); + else + return NR::Point(0,0); +} + +void +path_set_start_end(SPItem *item, NR::Point const &p, bool start) { + SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(item)); // TODO: Should we use sp_shape_get_curve()? + NR::Matrix const i2d (sp_item_i2d_affine (SP_ITEM(item))); + + Geom::Point A, B; + if (start) { + A = p.to_2geom(); + B = (curve->last_point()).to_2geom(); + } else { + A = (curve->first_point()).to_2geom(); + B = (p.to_2geom()); + } + + SPCurve *c = new SPCurve(); + c->moveto(A); + c->lineto(B); + sp_path_set_original_curve(SP_PATH(item), c, TRUE, true); + c->unref(); +} + +void path_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { + path_set_start_end(item, p); +} + +void path_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { + path_set_start_end(item, p, false); +} + +LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + length_left(_("Length left"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 200), + length_right(_("Length right"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 200), + A(0,0), B(0,0), M(0,0), C(0,0), D(0,0), perp_dir(0,0) +{ + // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast<Parameter *>(&length_left) ); + registerParameter( dynamic_cast<Parameter *>(&length_right) ); + + registerKnotHolderHandle(path_start_set, path_start_get); + registerKnotHolderHandle(path_end_set, path_end_get); + registerKnotHolderHandle(bisector_left_end_set, bisector_left_end_get); + registerKnotHolderHandle(bisector_right_end_set, bisector_right_end_get); +} + +LPEPerpBisector::~LPEPerpBisector() +{ +} + +void +LPEPerpBisector::doOnApply (SPLPEItem *lpeitem) +{ + /* make the path a straight line */ + SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(lpeitem)); // TODO: Should we use sp_shape_get_curve()? + + Geom::Point A((curve->first_point()).to_2geom()); + Geom::Point B((curve->last_point()).to_2geom()); + + SPCurve *c = new SPCurve(); + c->moveto(A); + c->lineto(B); + // TODO: Why doesn't sp_path_set_original_curve(SP_PATH(lpeitem), c, TRUE, true) work? + SP_PATH(lpeitem)->original_curve = c->ref(); + c->unref(); +} + + +Geom::Piecewise<Geom::D2<Geom::SBasis> > +LPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) +{ + using namespace Geom; + + Piecewise<D2<SBasis> > output; + + A = pwd2_in.firstValue(); + B = pwd2_in.lastValue(); + M = (A + B)/2; + + perp_dir = unit_vector((B - A).ccw()); + + C = M + perp_dir * length_left; + D = M - perp_dir * length_right; + + output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y]))); + + return output; +} + +/* ######################## */ + +} //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 : |
