From f4db63be4e929f4706410914295deccaceea19cd Mon Sep 17 00:00:00 2001 From: cilix42 Date: Sun, 18 May 2008 20:47:27 +0000 Subject: [PATCH] New LPE: Perpendicular bisector --- src/live_effects/Makefile_insert | 4 +- src/live_effects/effect.cpp | 5 ++ src/live_effects/effect.h | 1 + src/live_effects/lpe-perp_bisector.cpp | 94 ++++++++++++++++++++++++++ src/live_effects/lpe-perp_bisector.h | 48 +++++++++++++ 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/live_effects/lpe-perp_bisector.cpp create mode 100644 src/live_effects/lpe-perp_bisector.h 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 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 LPETypeConverter(LPETypeData, INVALID_LPE); @@ -119,6 +121,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case ENVELOPE: neweffect = static_cast ( new LPEEnvelope(lpeobj) ); break; + case PERP_BISECTOR: + neweffect = static_cast ( 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 implementation. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilin Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-perp_bisector.h" +#include "display/curve.h" +#include + +#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(&length_left) ); + registerParameter( dynamic_cast(&length_right) ); +} + +LPEPerpBisector::~LPEPerpBisector() +{ + +} + +Geom::Point LPEPerpBisector::left_end(Geom::Piecewise > 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 > +LPEPerpBisector::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + + Piecewise > 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(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 implementation, see lpe-perp_bisector.cpp. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilin Albert 2008 + * + * 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 > + doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + + Geom::Point left_end(Geom::Piecewise > const & pwd2_in); + +private: + ScalarParam length_left; + ScalarParam length_right; + + LPEPerpBisector(const LPEPerpBisector&); + LPEPerpBisector& operator=(const LPEPerpBisector&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif -- 2.30.2