summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-05-18 20:47:27 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-05-18 20:47:27 +0000
commit2d1c53f4ad65b8c1dd91e3062b9af67c30dc7d72 (patch)
treef6d7bbcfea15c90cb0a4cb5df0dfa855d80f967e /src
parentFix regression in constrained translation (diff)
downloadinkscape-2d1c53f4ad65b8c1dd91e3062b9af67c30dc7d72.tar.gz
inkscape-2d1c53f4ad65b8c1dd91e3062b9af67c30dc7d72.zip
New LPE: Perpendicular bisector
(bzr r5695)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/Makefile_insert4
-rw-r--r--src/live_effects/effect.cpp5
-rw-r--r--src/live_effects/effect.h1
-rw-r--r--src/live_effects/lpe-perp_bisector.cpp94
-rw-r--r--src/live_effects/lpe-perp_bisector.h48
5 files changed, 151 insertions, 1 deletions
diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert
index c476948b6..7e8a9e3a3 100644
--- a/src/live_effects/Makefile_insert
+++ b/src/live_effects/Makefile_insert
@@ -44,5 +44,7 @@ live_effects_liblive_effects_a_SOURCES = \
live_effects/lpe-perspective_path.cpp \
live_effects/lpe-perspective_path.h \
live_effects/lpe-envelope.cpp \
- live_effects/lpe-envelope.h
+ live_effects/lpe-envelope.h \
+ live_effects/lpe-perp_bisector.cpp \
+ live_effects/lpe-perp_bisector.h
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 125d22c3f..6ae30fe4c 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -45,6 +45,7 @@
#include "live_effects/lpe-spiro.h"
#include "live_effects/lpe-constructgrid.h"
#include "live_effects/lpe-envelope.h"
+#include "live_effects/lpe-perp_bisector.h"
// end of includes
#include "nodepath.h"
@@ -70,6 +71,7 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
{SPIRO, N_("Spiro spline"), "spiro"},
{CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"},
{ENVELOPE, N_("Envelope Deformation"), "envelope"},
+ {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"},
};
const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
@@ -119,6 +121,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
case ENVELOPE:
neweffect = static_cast<Effect*> ( new LPEEnvelope(lpeobj) );
break;
+ case PERP_BISECTOR:
+ neweffect = static_cast<Effect*> ( new LPEPerpBisector(lpeobj) );
+ break;
default:
g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr);
neweffect = NULL;
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 328181adc..086b973af 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -66,6 +66,7 @@ enum EffectType {
SPIRO,
CONSTRUCT_GRID,
ENVELOPE,
+ PERP_BISECTOR,
INVALID_LPE // This must be last
};
diff --git a/src/live_effects/lpe-perp_bisector.cpp b/src/live_effects/lpe-perp_bisector.cpp
new file mode 100644
index 000000000..c744f1268
--- /dev/null
+++ b/src/live_effects/lpe-perp_bisector.cpp
@@ -0,0 +1,94 @@
+#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 <2geom/path.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ length_left(_("Length left"), _(""), "length-left", &wr, this, 200),
+ length_right(_("Length right"), _(""), "length-right", &wr, this, 200)
+{
+ registerParameter( dynamic_cast<Parameter *>(&length_left) );
+ registerParameter( dynamic_cast<Parameter *>(&length_right) );
+}
+
+LPEPerpBisector::~LPEPerpBisector()
+{
+
+}
+
+Geom::Point LPEPerpBisector::left_end(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) {
+ Geom::Point A(pwd2_in.firstValue());
+ Geom::Point B(pwd2_in.lastValue());
+ Geom::Point M((A + B)/2);
+
+ Geom::Point dir1((B - M).ccw());
+
+ if (dir1.length() > Geom::EPSILON)
+ dir1 = Geom::unit_vector(dir1) * length_left;
+
+ return M + dir1;
+}
+
+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;
+
+ Point A(pwd2_in.firstValue());
+ Point B(pwd2_in.lastValue());
+ Point M((A + B)/2);
+
+ Point dir1((B - M).ccw());
+ Point dir2((A - M).ccw());
+
+ if (dir1.length() > EPSILON)
+ dir1 = unit_vector(dir1) * length_left;
+
+ if (dir2.length() > EPSILON)
+ dir2 = unit_vector(dir2) * length_right;
+
+ Point C(M + dir1);
+ Point D(M + dir2);
+
+ 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 :
diff --git a/src/live_effects/lpe-perp_bisector.h b/src/live_effects/lpe-perp_bisector.h
new file mode 100644
index 000000000..c25ba35f5
--- /dev/null
+++ b/src/live_effects/lpe-perp_bisector.h
@@ -0,0 +1,48 @@
+#ifndef INKSCAPE_LPE_PERP_BISECTOR_H
+#define INKSCAPE_LPE_PERP_BISECTOR_H
+
+/** \file
+ * LPE <perp_bisector> implementation, see lpe-perp_bisector.cpp.
+ */
+/*
+ * 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/effect.h"
+#include "live_effects/parameter/parameter.h"
+#include "live_effects/parameter/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPEPerpBisector : public Effect {
+public:
+ LPEPerpBisector(LivePathEffectObject *lpeobject);
+ virtual ~LPEPerpBisector();
+
+ virtual EffectType effectType () { return PERP_BISECTOR; }
+
+ virtual Geom::Piecewise<Geom::D2<Geom::SBasis> >
+ doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+ Geom::Point left_end(Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+private:
+ ScalarParam length_left;
+ ScalarParam length_right;
+
+ LPEPerpBisector(const LPEPerpBisector&);
+ LPEPerpBisector& operator=(const LPEPerpBisector&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif