Code

New LPE: circle through 3 points
authorcilix42 <cilix42@users.sourceforge.net>
Mon, 16 Jun 2008 16:16:38 +0000 (16:16 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Mon, 16 Jun 2008 16:16:38 +0000 (16:16 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-circle_3pts.cpp [new file with mode: 0644]
src/live_effects/lpe-circle_3pts.h [new file with mode: 0644]

index 4f0d46e363485fe32fa5f5d524f6c95701975500..843a8beb6614fd158d6ccd62fd9016b2452e8cd1 100644 (file)
@@ -52,5 +52,7 @@ live_effects_liblive_effects_a_SOURCES = \
        live_effects/lpe-perspective_path.cpp   \
        live_effects/lpe-perspective_path.h             \
        live_effects/lpe-mirror_reflect.cpp     \
-       live_effects/lpe-mirror_reflect.h
+       live_effects/lpe-mirror_reflect.h       \
+       live_effects/lpe-circle_3pts.cpp        \
+       live_effects/lpe-circle_3pts.h
 
index 9476f0377d15cc6255a32fe4602ddbda8de531a8..4f4aaff3fc88775d4ea648aad75511e99effd814 100644 (file)
@@ -56,6 +56,7 @@
 #include "live_effects/lpe-perp_bisector.h"
 #include "live_effects/lpe-tangent_to_curve.h"
 #include "live_effects/lpe-mirror_reflect.h"
+#include "live_effects/lpe-circle_3pts.h"
 // end of includes
 
 namespace Inkscape {
@@ -83,6 +84,7 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
     {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"},
     {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"},
     {MIRROR_REFLECT, N_("Mirror reflection"), "mirror_reflect"},
+    {CIRCLE_3PTS, N_("Circle through 3 points"), "circle_3pts"},
 };
 const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
 
@@ -144,6 +146,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case MIRROR_REFLECT:
             neweffect = static_cast<Effect*> ( new LPEMirrorReflect(lpeobj) );
             break;
+        case CIRCLE_3PTS:
+            neweffect = static_cast<Effect*> ( new LPECircle3Pts(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index 799c4cf755260ba09a9f91b510e2ab886354d190..93f2e60b15b61c9910955aa13b46158f987fd06a 100644 (file)
@@ -73,6 +73,7 @@ enum EffectType {
     PERP_BISECTOR,
     TANGENT_TO_CURVE,
     MIRROR_REFLECT,
+    CIRCLE_3PTS,
     INVALID_LPE // This must be last
 };
 
diff --git a/src/live_effects/lpe-circle_3pts.cpp b/src/live_effects/lpe-circle_3pts.cpp
new file mode 100644 (file)
index 0000000..d600ef0
--- /dev/null
@@ -0,0 +1,99 @@
+#define INKSCAPE_LPE_CIRCLE_3PTS_CPP
+/** \file
+ * LPE "Circle through 3 points" 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-circle_3pts.h"
+
+// You might need to include other 2geom files. You can add them here:
+#include <2geom/path.h>
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPECircle3Pts::LPECircle3Pts(LivePathEffectObject *lpeobject) :
+    Effect(lpeobject)
+{
+}
+
+LPECircle3Pts::~LPECircle3Pts()
+{
+}
+
+static void _circle(Geom::Point center, double radius, std::vector<Geom::Path> &path_out) {
+    using namespace Geom;
+
+    Geom::Path pb;
+
+    D2<SBasis> B;
+    Linear bo = Linear(0, 2 * M_PI);
+
+    B[0] = cos(bo,4);
+    B[1] = sin(bo,4);
+
+    B = B * radius + center;
+
+    pb.append(SBasisCurve(B));
+
+    path_out.push_back(pb);
+}
+
+static void _circle3(Geom::Point const &A, Geom::Point const &B, Geom::Point const &C, std::vector<Geom::Path> &path_out) {
+    using namespace Geom;
+
+    Point D = (A + B)/2;
+    Point E = (B + C)/2;
+
+    Point v = (B - A).ccw();
+    Point w = (C - B).ccw();
+    double det = -v[0] * w[1] + v[1] * w[0];
+
+    Point F = E - D;
+    double lambda = 1/det * (-w[1] * F[0] + w[0] * F[1]);
+
+    Point M = D + v * lambda;
+    double radius = L2(M - A);
+
+    _circle(M, radius, path_out);
+}
+
+std::vector<Geom::Path>
+LPECircle3Pts::doEffect_path (std::vector<Geom::Path> const & path_in)
+{
+    std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
+
+    // we assume that the path has >= 3 nodes
+    Geom::Point A = path_in[0].initialPoint();
+    Geom::Point B = path_in[0].pointAt(1);
+    Geom::Point C = path_in[0].pointAt(2);
+
+    _circle3(A, B, C, path_out);
+
+    return path_out;
+}
+
+/* ######################## */
+
+} //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-circle_3pts.h b/src/live_effects/lpe-circle_3pts.h
new file mode 100644 (file)
index 0000000..2533fe2
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef INKSCAPE_LPE_CIRCLE_3PTS_H
+#define INKSCAPE_LPE_CIRCLE_3PTS_H
+
+/** \file
+ * LPE "Circle through 3 points" 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/effect.h"
+#include "live_effects/parameter/parameter.h"
+#include "live_effects/parameter/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPECircle3Pts : public Effect {
+public:
+    LPECircle3Pts(LivePathEffectObject *lpeobject);
+    virtual ~LPECircle3Pts();
+
+    virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
+
+private:
+    LPECircle3Pts(const LPECircle3Pts&);
+    LPECircle3Pts& operator=(const LPECircle3Pts&);
+};
+
+} //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 :