summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-powerstroke.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/live_effects/lpe-powerstroke.cpp')
-rw-r--r--src/live_effects/lpe-powerstroke.cpp58
1 files changed, 20 insertions, 38 deletions
diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp
index 03102a84a..d87f92fcc 100644
--- a/src/live_effects/lpe-powerstroke.cpp
+++ b/src/live_effects/lpe-powerstroke.cpp
@@ -13,31 +13,20 @@
#include "live_effects/lpe-powerstroke.h"
#include "live_effects/lpe-powerstroke-interpolators.h"
-#include "sp-shape.h"
#include "style.h"
-#include "xml/repr.h"
-#include "sp-paint-server.h"
#include "svg/svg-color.h"
#include "desktop-style.h"
#include "svg/css-ostringstream.h"
#include "display/curve.h"
-#include <2geom/path.h>
-#include <2geom/piecewise.h>
-#include <2geom/sbasis-geometric.h>
-#include <2geom/transforms.h>
-#include <2geom/bezier-utils.h>
#include <2geom/elliptical-arc.h>
-#include <2geom/sbasis-to-bezier.h>
#include <2geom/path-sink.h>
#include <2geom/path-intersection.h>
-#include <2geom/crossing.h>
-#include <2geom/ellipse.h>
#include <2geom/circle.h>
-#include <2geom/math-utils.h>
-#include <math.h>
+#include "helper/geom.h"
-#include "spiro.h"
+// TODO due to internal breakage in glibmm headers, this must be last:
+#include <glibmm/i18n.h>
namespace Geom {
// should all be moved to 2geom at some point
@@ -190,14 +179,14 @@ LPEPowerStroke::LPEPowerStroke(LivePathEffectObject *lpeobject) :
interpolator_beta.addSlider(true);
interpolator_beta.param_set_range(0.,1.);
- registerParameter( dynamic_cast<Parameter *>(&offset_points) );
- registerParameter( dynamic_cast<Parameter *>(&sort_points) );
- registerParameter( dynamic_cast<Parameter *>(&interpolator_type) );
- registerParameter( dynamic_cast<Parameter *>(&interpolator_beta) );
- registerParameter( dynamic_cast<Parameter *>(&start_linecap_type) );
- registerParameter( dynamic_cast<Parameter *>(&linejoin_type) );
- registerParameter( dynamic_cast<Parameter *>(&miter_limit) );
- registerParameter( dynamic_cast<Parameter *>(&end_linecap_type) );
+ registerParameter(&offset_points);
+ registerParameter(&sort_points);
+ registerParameter(&interpolator_type);
+ registerParameter(&interpolator_beta);
+ registerParameter(&start_linecap_type);
+ registerParameter(&linejoin_type);
+ registerParameter(&miter_limit);
+ registerParameter(&end_linecap_type);
}
LPEPowerStroke::~LPEPowerStroke()
@@ -205,14 +194,13 @@ LPEPowerStroke::~LPEPowerStroke()
}
-
void
LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem)
{
- if (SP_IS_SHAPE(lpeitem)) {
+ if (SP_IS_SHAPE(lpeitem) && offset_points.data().empty()) {
SPLPEItem* item = const_cast<SPLPEItem*>(lpeitem);
std::vector<Geom::Point> points;
- Geom::PathVector const &pathv = SP_SHAPE(lpeitem)->_curve->get_pathvector();
+ Geom::PathVector const &pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeitem)->_curve->get_pathvector());
double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed / 2 : 1.;
SPCSSAttr *css = sp_repr_css_attr_new ();
@@ -565,12 +553,11 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
if (path_in.empty()) {
return path_out;
}
-
- // for now, only regard first subpath and ignore the rest
- Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = path_in[0].toPwSb();
-
+ Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in);
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = pathv[0].toPwSb();
Piecewise<D2<SBasis> > der = derivative(pwd2_in);
- Piecewise<D2<SBasis> > n = rot90(unitVector(der));
+ Piecewise<D2<SBasis> > n = unitVector(der,0.0001);
+ n = rot90(n);
offset_points.set_pwd2(pwd2_in, n);
LineCapType end_linecap = static_cast<LineCapType>(end_linecap_type.get_value());
@@ -583,7 +570,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
if (sort_points) {
sort(ts.begin(), ts.end(), compare_offsets);
}
- if (path_in[0].closed()) {
+ if (pathv[0].closed()) {
// add extra points for interpolation between first and last point
Point first_point = ts.front();
Point last_point = ts.back();
@@ -605,7 +592,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
for (std::size_t i = 0, e = ts.size(); i < e; ++i) {
ts[i][Geom::X] *= xcoord_scaling;
}
-
// create stroke path where points (x,y) := (t, offset)
Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast<Geom::Interpolate::InterpolatorType>(interpolator_type.get_value()));
if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast<Geom::Interpolate::CubicBezierJohan*>(interpolator)) {
@@ -626,7 +612,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
// find time values for which x lies outside path domain
// and only take portion of x and y that lies within those time values
std::vector< double > rtsmin = roots (x - pwd2_in.domain().min());
- std::vector< double > rtsmax = roots (x - pwd2_in.domain().max());
+ std::vector< double > rtsmax = roots (x + pwd2_in.domain().max());
if ( !rtsmin.empty() && !rtsmax.empty() ) {
x = portion(x, rtsmin.at(0), rtsmax.at(0));
y = portion(y, rtsmin.at(0), rtsmax.at(0));
@@ -639,8 +625,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE);
-
- if (path_in[0].closed()) {
+ if (pathv[0].closed()) {
fixed_path.close(true);
path_out.push_back(fixed_path);
fixed_mirrorpath.close(true);
@@ -684,7 +669,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
}
fixed_path.append(fixed_mirrorpath);
-
switch (start_linecap) {
case LINECAP_ZERO_WIDTH:
// do nothing
@@ -720,11 +704,9 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in)
break;
}
}
-
fixed_path.close(true);
path_out.push_back(fixed_path);
}
-
return path_out;
}