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