summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-10-13 10:11:48 +0000
committerjabiertxof <jabier.arraiza@marker.es>2015-10-13 10:11:48 +0000
commitaf1bbe5ddd52aef9e74a778006b01b3a0e249e5d (patch)
treef633213e83f1a211528e4132e2f606bd2c127665 /src
parentTranslations. German translation update. (diff)
downloadinkscape-af1bbe5ddd52aef9e74a778006b01b3a0e249e5d.tar.gz
inkscape-af1bbe5ddd52aef9e74a778006b01b3a0e249e5d.zip
Fix position node splited
Added parameter to Symm move nodes, Todo:Get better english strings (bzr r14407)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/lpe-roughen.cpp125
-rw-r--r--src/live_effects/lpe-roughen.h7
2 files changed, 111 insertions, 21 deletions
diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp
index 33ffd96d6..108b34a26 100644
--- a/src/live_effects/lpe-roughen.cpp
+++ b/src/live_effects/lpe-roughen.cpp
@@ -49,8 +49,10 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject)
"global_randomize", &wr, this, 1.),
shift_nodes(_("Shift nodes"), _("Shift nodes"), "shift_nodes", &wr, this,
true),
- shift_node_handles(_("Shift node handles"), _("Shift node handles"),
- "shift_node_handles", &wr, this, true)
+ shift_handles(_("Shift node handles"), _("Shift node handles"),
+ "shift_handles", &wr, this, true),
+ shift_handles_sym(_("Sym shift node handles"), _("Sym shift node handles"),
+ "shift_handles_sym", &wr, this, false)
{
registerParameter(&method);
registerParameter(&max_segment_size);
@@ -59,7 +61,8 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject)
registerParameter(&displace_y);
registerParameter(&global_randomize);
registerParameter(&shift_nodes);
- registerParameter(&shift_node_handles);
+ registerParameter(&shift_handles);
+ registerParameter(&shift_handles_sym);
displace_x.param_set_range(0., Geom::infinity());
displace_y.param_set_range(0., Geom::infinity());
global_randomize.param_set_range(0., Geom::infinity());
@@ -170,6 +173,7 @@ void LPERoughen::doEffect(SPCurve *curve)
Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
Geom::Path::const_iterator curve_endit = path_it->end_default();
SPCurve *nCurve = new SPCurve();
+ Geom::Point prev(0, 0);
if (path_it->closed()) {
const Geom::Curve &closingline =
path_it->back_closed();
@@ -212,18 +216,26 @@ void LPERoughen::doEffect(SPCurve *curve)
} else {
splits = ceil(length / max_segment_size);
}
- for (unsigned int t = splits; t >= 1; t--) {
- if (t == 1 && splits != 1) {
+ Geom::Curve const * original = nCurve->last_segment()->duplicate() ;
+ for (unsigned int t = 1; t <= splits; t++) {
+ if(t == splits && splits != 1){
continue;
}
- const SPCurve *tmp;
+ SPCurve const * tmp;
if (splits == 1) {
tmp = jitter(nCurve->last_segment());
} else {
- tmp = addNodesAndJitter(nCurve->last_segment(), 1. / t);
+ bool last = false;
+ if(t == splits-1){
+ last = true;
+ }
+ double time = Geom::nearest_time(original->pointAt((1. / (double)splits) * t), *nCurve->last_segment());
+ tmp = addNodesAndJitter(nCurve->last_segment(), prev, time, last);
}
if (nCurve->get_segment_count() > 1) {
- nCurve->backspace();
+ if(t!= splits){
+ nCurve->backspace();
+ }
nCurve->append_continuous(tmp, 0.001);
} else {
nCurve = tmp->copy();
@@ -237,6 +249,27 @@ void LPERoughen::doEffect(SPCurve *curve)
first = false;
}
if (path_it->closed()) {
+ if(shift_handles_sym && curve_it2 == curve_endit){
+ SPCurve *out = new SPCurve();
+ nCurve = nCurve->create_reverse();
+ Geom::CubicBezier const *cubic_start = dynamic_cast<Geom::CubicBezier const *>(nCurve->first_segment());
+ Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(nCurve->last_segment());
+ Geom::Point oposite = nCurve->first_segment()->initialPoint();
+ if(cubic_start){
+ Geom::Ray ray((*cubic_start)[1], (*cubic_start)[0]);
+ double dist = Geom::distance((*cubic_start)[1], (*cubic_start)[0]);
+ oposite = Geom::Point::polar(ray.angle(),dist) + (*cubic_start)[0];
+ }
+ if(cubic){
+ out->moveto((*cubic)[0]);
+ out->curveto((*cubic)[1], oposite, (*cubic)[3]);
+ } else {
+ out->moveto(nCurve->last_segment()->initialPoint());
+ out->curveto(nCurve->last_segment()->initialPoint(), oposite, nCurve->last_segment()->finalPoint());
+ }
+ nCurve->backspace();
+ nCurve->append_continuous(out, 0.001);
+ }
nCurve->closepath_current();
}
curve->append(nCurve, false);
@@ -245,7 +278,7 @@ void LPERoughen::doEffect(SPCurve *curve)
}
}
-SPCurve *LPERoughen::addNodesAndJitter(const Geom::Curve *A, double t)
+SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point &prev, double t, bool last)
{
SPCurve *out = new SPCurve();
Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(&*A);
@@ -259,38 +292,94 @@ SPCurve *LPERoughen::addNodesAndJitter(const Geom::Curve *A, double t)
point3 = randomize();
point_b3 = randomize();
}
- if (shift_node_handles) {
+ if (shift_handles && !shift_handles_sym) {
point1 = randomize();
point2 = randomize();
point_b1 = randomize();
point_b2 = randomize();
- } else {
+ } else if(shift_handles_sym) {
+ Geom::Ray ray(prev,A->initialPoint());
+ double dist = Geom::distance(prev, A->initialPoint());
+ point1 = Geom::Point::polar(ray.angle(),dist) + A->initialPoint();
+ if(prev==Geom::Point(0,0)){
+ point1 = A->pointAt(t / 3) + randomize();
+ }
+ point2 = A->pointAt((t / 3) * 2) + randomize();
+ Geom::Ray ray2(point2, point3);
+ double dist2 = Geom::distance(point2, point3);
+ point_b1 = Geom::Point::polar(ray2.angle(),dist2) + point3;
+ point1 = point1 - A->pointAt(t / 3);
+ point2 = point2 - A->pointAt((t / 3) * 2);
+ point_b1 = randomize();
+ point_b2 = randomize();
+ }else {
point2 = point3;
point_b1 = point3;
point_b2 = point_b3;
}
- if (cubic) {
+ if(shift_handles_sym && cubic) {
+ std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t);
+ std::vector<Geom::Point> seg1 = div.first.controlPoints(),
+ seg2 = div.second.controlPoints();
+ out->moveto(seg1[0]);
+ Geom::Ray ray(prev,A->initialPoint());
+ double dist = Geom::distance(seg1[1], A->initialPoint());
+ point1 = Geom::Point::polar(ray.angle(),dist) + A->initialPoint();
+ point2 = seg1[2] + point2;
+ point3 = seg1[3] + point3;
+ if(prev==Geom::Point(0,0)){
+ point1 = seg1[1] + randomize();
+ }
+ out->curveto(point1, point2, point3);
+
+ Geom::Ray ray2(point2, point3);
+ double dist2 = Geom::distance(seg2[1], point3);
+ point_b1 = Geom::Point::polar(ray2.angle(),dist2) + point3;
+ point_b2 = seg2[2];
+ out->curveto(point_b1, point_b2, seg2[3]);
+ } else if(shift_handles_sym && !cubic) {
+ out->moveto(A->initialPoint());
+ Geom::Ray ray(prev,A->initialPoint());
+ double dist = Geom::distance(A->pointAt(t / 3) + randomize(), A->initialPoint());
+ point1 = Geom::Point::polar(ray.angle(),dist) + A->initialPoint();
+ point2 = A->pointAt((t / 3) * 2) + point2;
+ point3 = A->pointAt(t) + point3;
+ if(prev==Geom::Point(0,0)){
+ point1 = A->pointAt(t / 3) + randomize();
+ }
+ out->curveto(point1, point2, point3);
+ Geom::Ray ray2(point2, point3);
+ double dist2 = Geom::distance(A->pointAt(t + ((t / 3) * 2)) + point_b2, point3);
+ point_b1 = Geom::Point::polar(ray2.angle(),dist2) + point3;
+ point_b2 = A->pointAt(t + ((t / 3) * 2)) + point_b2;
+ out->curveto(point_b1, point_b2, A->finalPoint());
+ } else if (cubic) {
std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t);
std::vector<Geom::Point> seg1 = div.first.controlPoints(),
seg2 = div.second.controlPoints();
out->moveto(seg1[0]);
out->curveto(seg1[1] + point1, seg1[2] + point2, seg1[3] + point3);
out->curveto(seg2[1] + point_b1, seg2[2], seg2[3]);
- } else if (shift_node_handles) {
+ } else if (shift_handles) {
out->moveto(A->initialPoint());
out->curveto(A->pointAt(t / 3) + point1, A->pointAt((t / 3) * 2) + point2,
A->pointAt(t) + point3);
- out->curveto(A->pointAt(t + (t / 3)) + point_b1, A->pointAt(t + ((t / 3) * 2)),
- A->finalPoint());
+ out->curveto(A->pointAt(t + (t / 3)) + point_b1, A->pointAt(t + ((t / 3) * 2)) + point_b2,
+ A->finalPoint());
} else {
out->moveto(A->initialPoint());
out->lineto(A->pointAt(t) + point3);
out->lineto(A->finalPoint());
}
+ if(last){
+ prev = point_b2;
+ } else {
+ prev = point2;
+ }
return out;
}
-SPCurve *LPERoughen::jitter(const Geom::Curve *A)
+SPCurve *LPERoughen::jitter(Geom::Curve const * A)
{
SPCurve *out = new SPCurve();
Geom::CubicBezier const *cubic = dynamic_cast<Geom::CubicBezier const *>(&*A);
@@ -300,7 +389,7 @@ SPCurve *LPERoughen::jitter(const Geom::Curve *A)
if (shift_nodes) {
point3 = randomize();
}
- if (shift_node_handles) {
+ if (shift_handles) {
point1 = randomize();
point2 = randomize();
} else {
@@ -309,7 +398,7 @@ SPCurve *LPERoughen::jitter(const Geom::Curve *A)
if (cubic) {
out->moveto((*cubic)[0]);
out->curveto((*cubic)[1] + point1, (*cubic)[2] + point2, (*cubic)[3] + point3);
- } else if (shift_node_handles) {
+ } else if (shift_handles) {
out->moveto(A->initialPoint());
out->curveto(A->pointAt(0.3333) + point1, A->pointAt(0.6666) + point2,
A->finalPoint() + point3);
diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h
index 2b285cd40..8241cedca 100644
--- a/src/live_effects/lpe-roughen.h
+++ b/src/live_effects/lpe-roughen.h
@@ -38,8 +38,8 @@ public:
virtual double sign(double randNumber);
virtual Geom::Point randomize();
virtual void doBeforeEffect(SPLPEItem const * lpeitem);
- virtual SPCurve *addNodesAndJitter(const Geom::Curve *A, double t);
- virtual SPCurve *jitter(const Geom::Curve *A);
+ virtual SPCurve const * addNodesAndJitter(Geom::Curve const * A, Geom::Point &prev, double t, bool last);
+ virtual SPCurve *jitter(Geom::Curve const * A);
virtual Geom::Point tPoint(Geom::Point A, Geom::Point B, double t = 0.5);
virtual Gtk::Widget *newWidget();
@@ -51,7 +51,8 @@ private:
RandomParam displace_y;
RandomParam global_randomize;
BoolParam shift_nodes;
- BoolParam shift_node_handles;
+ BoolParam shift_handles;
+ BoolParam shift_handles_sym;
LPERoughen(const LPERoughen &);
LPERoughen &operator=(const LPERoughen &);