summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-11-10 21:35:13 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-11-10 21:35:13 +0000
commita2377f88de39790b2324a846f9e619d78d399afc (patch)
tree53527a2c2212de467883a79d18ee02f589a9218b /src
parentFix a bug pointed by su_v in IRC aboutr shapes (diff)
downloadinkscape-a2377f88de39790b2324a846f9e619d78d399afc.tar.gz
inkscape-a2377f88de39790b2324a846f9e619d78d399afc.zip
adding blending support
(bzr r13682.1.1)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/effect.cpp2
-rw-r--r--src/live_effects/lpe-mirror_symmetry.cpp102
-rw-r--r--src/live_effects/lpe-mirror_symmetry.h5
3 files changed, 93 insertions, 16 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index fbdc78f8a..9433dec7f 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -106,7 +106,6 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{EXTRUDE, N_("Extrude"), "extrude"},
{LATTICE, N_("Lattice Deformation"), "lattice"},
{LINE_SEGMENT, N_("Line Segment"), "line_segment"},
- {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
{OFFSET, N_("Offset"), "offset"},
{PARALLEL, N_("Parallel"), "parallel"},
{PATH_LENGTH, N_("Path length"), "path_length"},
@@ -153,6 +152,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
{PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"},
{FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"},
{INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"},
+ {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"},
};
const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp
index 0bb67a4a2..8877ffd9c 100644
--- a/src/live_effects/lpe-mirror_symmetry.cpp
+++ b/src/live_effects/lpe-mirror_symmetry.cpp
@@ -21,6 +21,7 @@
#include <svg/path-string.h>
#include <2geom/path.h>
+#include <2geom/path-intersection.h>
#include <2geom/transforms.h>
#include <2geom/affine.h>
@@ -30,11 +31,13 @@ namespace LivePathEffect {
LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false),
- reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L100,100")
+ joinPaths(_("Join the paths"), _("Join the resulting paths"), "joinPaths", &wr, this, true),
+ reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0")
{
show_orig_path = true;
registerParameter( dynamic_cast<Parameter *>(&discard_orig_path) );
+ registerParameter( dynamic_cast<Parameter *>(&joinPaths) );
registerParameter( dynamic_cast<Parameter *>(&reflection_line) );
}
@@ -55,15 +58,10 @@ LPEMirrorSymmetry::doOnApply (SPLPEItem const* lpeitem)
{
using namespace Geom;
- // fixme: what happens if the bbox is empty?
- // fixme: this is probably wrong
- Geom::Affine t = lpeitem->i2dt_affine();
- Geom::Rect bbox = *lpeitem->desktopVisualBounds();
+ original_bbox(lpeitem);
- Point A(bbox.left(), bbox.bottom());
- Point B(bbox.left(), bbox.top());
- A *= t;
- B *= t;
+ Point A(boundingbox_X.max(), boundingbox_Y.max());
+ Point B(boundingbox_X.max(), boundingbox_Y.min());
Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
reflection_line.set_new_value(rline, true);
}
@@ -77,11 +75,12 @@ LPEMirrorSymmetry::doEffect_path (std::vector<Geom::Path> const & path_in)
}
std::vector<Geom::Path> path_out;
- if (!discard_orig_path) {
+ std::vector<Geom::Path> mline(reflection_line.get_pathvector());
+
+ if (!discard_orig_path && !joinPaths) {
path_out = path_in;
}
- std::vector<Geom::Path> mline(reflection_line.get_pathvector());
Geom::Point A(mline.front().initialPoint());
Geom::Point B(mline.back().finalPoint());
@@ -97,9 +96,84 @@ LPEMirrorSymmetry::doEffect_path (std::vector<Geom::Path> const & path_in)
m = m * sca;
m = m * m2.inverse();
m = m * m1;
-
- for (int i = 0; i < static_cast<int>(path_in.size()); ++i) {
- path_out.push_back(path_in[i] * m);
+
+ if(joinPaths){
+ for (Geom::PathVector::const_iterator path_it = path_in.begin();
+ path_it != path_in.end(); ++path_it) {
+ if (path_it->empty()){
+ continue;
+ }
+ Geom::Path original;
+ Geom::Path mlineExpanded;
+ Geom::Line lineSeparation;
+ lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint());
+ mlineExpanded.start( lineSeparation.pointAt(-100000));
+ mlineExpanded.appendNew<Geom::LineSegment>( lineSeparation.pointAt(100000));
+ Geom::Crossings cs = crossings(*path_it, mlineExpanded);
+ double timeStart = 0.0;
+ //http://stackoverflow.com/questions/1560492/how-to-tell-whether-a-point-is-to-the-right-or-left-side-of-a-line
+ double pos = (lineSeparation.pointAt(100000)[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X])*(path_it->initialPoint()[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y]) - (lineSeparation.pointAt(100000)[Geom::Y]-lineSeparation.pointAt(-100000)[Geom::Y])*(path_it->initialPoint()[Geom::X]-lineSeparation.pointAt(-100000)[Geom::X]);
+ int position = (pos < 0) ? -1 : (pos > 0);
+ unsigned int counter = 0;
+
+ for(unsigned int i = 0; i < cs.size(); i++) {
+ double timeEnd = cs[i].ta;
+ Geom::Path portion = path_it->portion(timeStart, timeEnd);
+ if(position == -1 && i==0){
+ counter++;
+ }
+ if(counter%2!=0){
+ if (!discard_orig_path){
+ if(i==0){
+ original = portion;
+ } else {
+ original.append(portion, (Geom::Path::Stitching)1);
+ }
+ original.append(portion.reverse() * m, (Geom::Path::Stitching)1);
+ if (!path_it->closed()){
+ path_out.push_back(original);
+ original.clear();
+ }
+ } else {
+ path_out.push_back(portion * m);
+ }
+ }
+ timeStart = timeEnd;
+ counter++;
+ }
+ if(cs.size()!=0 && ((cs.size()%2 == 0 && position == -1)||(cs.size()%2 != 0 && position == 1))){
+ Geom::Path portion = path_it->portion(timeStart, nearest_point(path_it->finalPoint(), *path_it));
+ if (!discard_orig_path){
+ if(!path_it->closed()){
+ original = portion;
+ } else {
+ original.append(portion, (Geom::Path::Stitching)1);
+ }
+ original.append(portion.reverse() * m, (Geom::Path::Stitching)1);
+ if (!path_it->closed()){
+ path_out.push_back(original);
+ original.clear();
+ }
+ } else {
+ path_out.push_back(portion * m);
+ }
+
+ }
+ if (path_it->closed() && !original.empty() && !discard_orig_path) {
+ original.close();
+ path_out.push_back(original);
+ }
+ if(cs.size() == 0){
+ path_out.push_back(*path_it);
+ path_out.push_back(*path_it * m);
+ }
+ }
+ }
+
+ if (!joinPaths) {
+ for (int i = 0; i < static_cast<int>(path_in.size()); ++i) {
+ path_out.push_back(path_in[i] * m);
+ }
}
return path_out;
diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h
index a4a2b86c0..2ea8161d4 100644
--- a/src/live_effects/lpe-mirror_symmetry.h
+++ b/src/live_effects/lpe-mirror_symmetry.h
@@ -20,10 +20,12 @@
#include "live_effects/parameter/point.h"
#include "live_effects/parameter/path.h"
+#include "live_effects/lpegroupbbox.h"
+
namespace Inkscape {
namespace LivePathEffect {
-class LPEMirrorSymmetry : public Effect {
+class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{
public:
LPEMirrorSymmetry(LivePathEffectObject *lpeobject);
virtual ~LPEMirrorSymmetry();
@@ -36,6 +38,7 @@ public:
private:
BoolParam discard_orig_path;
+ BoolParam joinPaths;
PathParam reflection_line;
LPEMirrorSymmetry(const LPEMirrorSymmetry&);