summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-patternalongpath.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/live_effects/lpe-patternalongpath.cpp')
-rw-r--r--src/live_effects/lpe-patternalongpath.cpp84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp
index 911c410f9..b026bbc22 100644
--- a/src/live_effects/lpe-patternalongpath.cpp
+++ b/src/live_effects/lpe-patternalongpath.cpp
@@ -6,22 +6,16 @@
#include "live_effects/lpe-patternalongpath.h"
#include "live_effects/lpeobject.h"
-#include "sp-shape.h"
#include "display/curve.h"
-#include "svg/svg.h"
-#include "ui/widget/scalar.h"
-#include <2geom/sbasis.h>
-#include <2geom/sbasis-geometric.h>
#include <2geom/bezier-to-sbasis.h>
-#include <2geom/sbasis-to-bezier.h>
-#include <2geom/d2.h>
-#include <2geom/piecewise.h>
-#include "knot-holder-entity.h"
#include "knotholder.h"
-
+#include <cmath>
#include <algorithm>
+// TODO due to internal breakage in glibmm headers, this must be last:
+#include <glibmm/i18n.h>
+
using std::vector;
@@ -70,7 +64,7 @@ static const Util::EnumDataConverter<PAPCopyType> PAPCopyTypeConverter(PAPCopyTy
LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"),
- original_height(0),
+ original_height(0.0),
prop_scale(_("_Width:"), _("Width of the pattern"), "prop_scale", &wr, this, 1.0),
copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"),
"copytype", PAPCopyTypeConverter, &wr, this, PAPCT_SINGLE_STRETCHED),
@@ -91,16 +85,16 @@ LPEPatternAlongPath::LPEPatternAlongPath(LivePathEffectObject *lpeobject) :
fuse_tolerance(_("_Fuse nearby ends:"), _("Fuse ends closer than this number. 0 means don't fuse."),
"fuse_tolerance", &wr, this, 0)
{
- registerParameter( dynamic_cast<Parameter *>(&pattern) );
- registerParameter( dynamic_cast<Parameter *>(&copytype) );
- registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
- registerParameter( dynamic_cast<Parameter *>(&scale_y_rel) );
- registerParameter( dynamic_cast<Parameter *>(&spacing) );
- registerParameter( dynamic_cast<Parameter *>(&normal_offset) );
- registerParameter( dynamic_cast<Parameter *>(&tang_offset) );
- registerParameter( dynamic_cast<Parameter *>(&prop_units) );
- registerParameter( dynamic_cast<Parameter *>(&vertical_pattern) );
- registerParameter( dynamic_cast<Parameter *>(&fuse_tolerance) );
+ registerParameter(&pattern);
+ registerParameter(&copytype);
+ registerParameter(&prop_scale);
+ registerParameter(&scale_y_rel);
+ registerParameter(&spacing);
+ registerParameter(&normal_offset);
+ registerParameter(&tang_offset);
+ registerParameter(&prop_units);
+ registerParameter(&vertical_pattern);
+ registerParameter(&fuse_tolerance);
prop_scale.param_set_digits(3);
prop_scale.param_set_increments(0.01, 0.10);
@@ -151,15 +145,15 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
double xspace = spacing;
double noffset = normal_offset;
double toffset = tang_offset;
- if (prop_units.get_value() && pattBndsY){
+ if (prop_units.get_value()){
xspace *= pattBndsX->extent();
noffset *= pattBndsY->extent();
toffset *= pattBndsX->extent();
}
//Prevent more than 90% overlap...
- if (xspace < -pattBndsX->extent()*.9) {
- xspace = -pattBndsX->extent()*.9;
+ if (xspace < -pattBndsX->extent() * 0.9) {
+ xspace = -pattBndsX->extent() * 0.9;
}
//TODO: dynamical update of parameter ranges?
//if (prop_units.get_value()){
@@ -168,7 +162,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
// spacing.param_set_range(-pattBndsX.extent()*.9, Geom::infinity());
// }
- y0+=noffset;
+ y0 += noffset;
std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > paths_in;
paths_in = split_at_discontinuities(pwd2_in);
@@ -177,11 +171,14 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
Geom::Piecewise<Geom::D2<Geom::SBasis> > path_i = paths_in[idx];
Piecewise<SBasis> x = x0;
Piecewise<SBasis> y = y0;
- Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1);
- uskeleton = remove_short_cuts(uskeleton,.01);
+ Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2, 0.1);
+ uskeleton = remove_short_cuts(uskeleton, 0.01);
Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton));
- n = force_continuity(remove_short_cuts(n,.1));
-
+ if (Geom::are_near(pwd2_in[0].at0(),pwd2_in[pwd2_in.size()-1].at1(), 0.01)) {
+ n = force_continuity(remove_short_cuts(n, 0.1), 0.01);
+ } else {
+ n = force_continuity(remove_short_cuts(n, 0.1));
+ }
int nbCopies = 0;
double scaling = 1;
switch(type) {
@@ -201,13 +198,13 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
case PAPCT_REPEATED_STRETCHED:
// if uskeleton is closed:
- if(path_i.segs.front().at0() == path_i.segs.back().at1()){
- nbCopies = static_cast<int>(std::floor((uskeleton.domain().extent() - toffset)/(pattBndsX->extent()+xspace)));
+ if (are_near(path_i.segs.front().at0(), path_i.segs.back().at1())){
+ nbCopies = std::max(1, static_cast<int>(std::floor((uskeleton.domain().extent() - toffset)/(pattBndsX->extent()+xspace))));
pattBndsX = Interval(pattBndsX->min(),pattBndsX->max()+xspace);
scaling = (uskeleton.domain().extent() - toffset)/(((double)nbCopies)*pattBndsX->extent());
// if not closed: no space at the end
}else{
- nbCopies = static_cast<int>(std::floor((uskeleton.domain().extent() - toffset + xspace)/(pattBndsX->extent()+xspace)));
+ nbCopies = std::max(1, static_cast<int>(std::floor((uskeleton.domain().extent() - toffset + xspace)/(pattBndsX->extent()+xspace))));
pattBndsX = Interval(pattBndsX->min(),pattBndsX->max()+xspace);
scaling = (uskeleton.domain().extent() - toffset)/(((double)nbCopies)*pattBndsX->extent() - xspace);
}
@@ -217,18 +214,18 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
return pwd2_in;
};
+ //Ceil to 6 decimals
+ scaling = ceil(scaling * 1000000) / 1000000;
double pattWidth = pattBndsX->extent() * scaling;
- if (scaling != 1.0) {
- x*=scaling;
- }
+ x *= scaling;
if ( scale_y_rel.get_value() ) {
- y*=(scaling*prop_scale);
+ y *= prop_scale * scaling;
} else {
- if (prop_scale != 1.0) y *= prop_scale;
+ y *= prop_scale;
}
x += toffset;
-
+
double offs = 0;
for (int i=0; i<nbCopies; i++){
if (fuse_tolerance > 0){
@@ -241,7 +238,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con
offs+=pattWidth;
}
}
- if (fuse_tolerance > 0){
+ if (fuse_tolerance > 0){
pre_output = fuse_nearby_ends(pre_output, fuse_tolerance);
for (unsigned i=0; i<pre_output.size(); i++){
output.concat(pre_output[i]);
@@ -264,11 +261,12 @@ LPEPatternAlongPath::transform_multiply(Geom::Affine const& postmul, bool set)
bool transform_stroke = prefs ? prefs->getBool("/options/transform/stroke", true) : true;
if (transform_stroke && !scale_y_rel) {
prop_scale.param_set_value(prop_scale * ((postmul.expansionX() + postmul.expansionY()) / 2));
- }
+ prop_scale.write_to_SVG();
+ }
if (postmul.isTranslation()) {
pattern.param_transform_multiply(postmul, set);
+ pattern.write_to_SVG();
}
- sp_lpe_item_update_patheffect (sp_lpe_item, false, true);
}
void
@@ -279,10 +277,10 @@ LPEPatternAlongPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vect
void
-LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
+LPEPatternAlongPath::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item)
{
KnotHolderEntity *e = new WPAP::KnotHolderEntityWidthPatternAlongPath(this);
- e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE);
+ e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _("Change the width"), SP_KNOT_SHAPE_CIRCLE);
knotholder->add(e);
}