Code

New LPE: Offset
authorcilix42 <cilix42@users.sourceforge.net>
Thu, 3 Jul 2008 09:39:53 +0000 (09:39 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Thu, 3 Jul 2008 09:39:53 +0000 (09:39 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-offset.cpp [new file with mode: 0644]
src/live_effects/lpe-offset.h [new file with mode: 0644]

index d0bfb5b998d68ed8fa5c7af8728668907c3549d4..366a94883ba93170f2b7a3cfd952da102fa3ea8e 100644 (file)
@@ -60,5 +60,7 @@ live_effects_liblive_effects_a_SOURCES = \
        live_effects/lpe-parallel.cpp   \
        live_effects/lpe-parallel.h     \
        live_effects/lpe-copy_rotate.cpp        \
-       live_effects/lpe-copy_rotate.h
+       live_effects/lpe-copy_rotate.h  \
+       live_effects/lpe-offset.cpp     \
+       live_effects/lpe-offset.h
 
index 74e5c29fd17010f95a6dca8f8566fff81554e626..73ba7387a1901392b36c8439bbf9af9892d0891b 100644 (file)
@@ -60,6 +60,7 @@
 #include "live_effects/lpe-angle_bisector.h"
 #include "live_effects/lpe-parallel.h"
 #include "live_effects/lpe-copy_rotate.h"
+#include "live_effects/lpe-offset.h"
 // end of includes
 
 namespace Inkscape {
@@ -91,6 +92,7 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
     {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"},
     {PARALLEL, N_("Parallel"), "parallel"},
     {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"},
+    {OFFSET, N_("Offset"), "offset"},
 };
 const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
 
@@ -164,6 +166,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case COPY_ROTATE:
             neweffect = static_cast<Effect*> ( new LPECopyRotate(lpeobj) );
             break;
+        case OFFSET:
+            neweffect = static_cast<Effect*> ( new LPEOffset(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index 672b90b87cb71bcdacaf3d2b9198be920041e06a..07b58c87cdbf7c3e4afb56a92023bc8b047478c7 100644 (file)
@@ -77,6 +77,7 @@ enum EffectType {
     ANGLE_BISECTOR,
     PARALLEL,
     COPY_ROTATE,
+    OFFSET,
     INVALID_LPE // This must be last
 };
 
diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp
new file mode 100644 (file)
index 0000000..2916b9f
--- /dev/null
@@ -0,0 +1,95 @@
+#define INKSCAPE_LPE_OFFSET_CPP
+/** \file
+ * LPE <offset> implementation
+ */
+/*
+ * Authors:
+ *   Maximilian Albert
+ *
+ * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/lpe-offset.h"
+#include "sp-shape.h"
+#include "display/curve.h"
+
+#include <2geom/path.h>
+#include <2geom/piecewise.h>
+#include <2geom/sbasis-geometric.h>
+#include <2geom/elliptical-arc.h>
+#include <2geom/transforms.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPEOffset::LPEOffset(LivePathEffectObject *lpeobject) :
+    Effect(lpeobject),
+    offset_pt(_("Offset"), _("Handle to control the distance of the offset from the curve"), "offset_pt", &wr, this)
+{
+    show_orig_path = true;
+
+    registerParameter(dynamic_cast<Parameter *>(&offset_pt));
+}
+
+LPEOffset::~LPEOffset()
+{
+}
+
+void
+LPEOffset::doOnApply(SPLPEItem *lpeitem)
+{
+    offset_pt.param_set_and_write_new_value(SP_SHAPE(lpeitem)->curve->first_point().to_2geom());
+}
+
+static void append_half_circle(Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
+                               Geom::Point const center, Geom::Point const &dir) {
+    using namespace Geom;
+
+    double r = L2(dir);
+    EllipticalArc cap(center + dir, r, r, angle_between(Point(1,0), dir), false, false, center - dir);
+    Piecewise<D2<SBasis> > cap_pwd2(cap.toSBasis());
+    pwd2.continuousConcat(cap_pwd2);
+}
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPEOffset::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
+{
+    using namespace Geom;
+
+    Piecewise<D2<SBasis> > output;
+
+    double t = nearest_point(offset_pt, pwd2_in);
+    Point A = pwd2_in.valueAt(t);
+    double offset = L2(A - offset_pt);
+
+    Piecewise<D2<SBasis> > der = unitVector(derivative(pwd2_in));
+    Piecewise<D2<SBasis> > n   = rot90(der);
+
+    output  = pwd2_in + n * offset;
+    append_half_circle(output, pwd2_in.lastValue(), n.lastValue() * offset);
+    output.continuousConcat(reverse(pwd2_in - n * offset));
+    append_half_circle(output, pwd2_in.firstValue(), -n.firstValue() * offset);
+
+    // TODO: here we should remove self-overlaps by applying the "union" boolop
+    //       but we'd need to convert the path to a Shape, which is currently
+    //       broken in 2geom, so we return the unaltered path
+
+    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-offset.h b/src/live_effects/lpe-offset.h
new file mode 100644 (file)
index 0000000..f57d41a
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef INKSCAPE_LPE_OFFSET_H
+#define INKSCAPE_LPE_OFFSET_H
+
+/** \file
+ * LPE <offset> implementation, see lpe-offset.cpp.
+ */
+
+/*
+ * Authors:
+ *   Maximilian Albert
+ *
+ * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Maximilian 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/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPEOffset : public Effect {
+public:
+    LPEOffset(LivePathEffectObject *lpeobject);
+    virtual ~LPEOffset();
+
+    virtual void doOnApply (SPLPEItem *lpeitem);
+
+    virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in);
+
+private:
+    PointParam offset_pt;
+
+    LPEOffset(const LPEOffset&);
+    LPEOffset& operator=(const LPEOffset&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif
+
+/*
+  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 :