summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-08-23 22:58:37 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-08-23 22:58:37 +0000
commit89b565d68326ada49d11d0735ffb6b602c26a54f (patch)
treeb8d264231211485f47e9f72c87f8054c912061da
parentsatellites in curves (diff)
downloadinkscape-89b565d68326ada49d11d0735ffb6b602c26a54f.tar.gz
inkscape-89b565d68326ada49d11d0735ffb6b602c26a54f.zip
Cached some functions
(bzr r13645.1.111)
-rw-r--r--src/helper/geom-pointwise.cpp20
-rw-r--r--src/helper/geom-pointwise.h1
-rw-r--r--src/helper/geom-satellite.cpp4
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp12
-rw-r--r--src/live_effects/parameter/satellitearray.cpp115
5 files changed, 95 insertions, 57 deletions
diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp
index 8ae2125a4..9aa90df01 100644
--- a/src/helper/geom-pointwise.cpp
+++ b/src/helper/geom-pointwise.cpp
@@ -27,7 +27,7 @@ void Pointwise::setPwd2(pwd2sb const &pwd2_in)
_pwd2 = pwd2_in;
}
-std::vector<Satellite> Pointwise::getSatellites(e)
+std::vector<Satellite> Pointwise::getSatellites()
{
return _satellites;
}
@@ -80,10 +80,10 @@ void Pointwise::pwd2Subtract(pwd2sb const &A)
std::vector<Satellite> sats;
pwd2sb pwd2 = _pwd2;
setPwd2(A);
- Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01);
+ Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01);
for (size_t i = 0; i < _satellites.size(); i++) {
- Geom::Path sat_path = pointwise_pv.pathAt(i - counter);
- Geom::PathTime sat_curve_time = sat_path.nearestTime(pointwise_pv.curveAt(i - counter).initialPoint());
+ Geom::Path sat_path = pathv.pathAt(i - counter);
+ Geom::PathTime sat_curve_time = sat_path.nearestTime(pathv.curveAt(i - counter).initialPoint());
Geom::PathTime sat_curve_time_start = sat_path.nearestTime(sat_path.initialPoint());
if (sat_curve_time_start.curve_index < sat_curve_time.curve_index||
!are_near(pwd2[i].at0(), A[i - counter].at0())) {
@@ -101,9 +101,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S)
std::vector<Satellite> sats;
bool reorder = false;
for (size_t i = 0; i < A.size(); i++) {
- Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01);
- Geom::Path sat_path = pointwise_pv.pathAt(i - counter);
- boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i-counter).initialPoint());
+ Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(_pwd2,0.01),0.01);
+ Geom::Path sat_path = pathv.pathAt(i - counter);
+ boost::optional< Geom::PathVectorTime > sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i-counter).initialPoint());
Geom::PathVectorTime sat_curve_time;
if(sat_curve_time_optional) {
sat_curve_time = *sat_curve_time_optional;
@@ -118,9 +118,9 @@ void Pointwise::pwd2Append(pwd2sb const &A, Satellite const &S)
//Check for subpath closed. If a subpath is closed, is not reversed or moved
//to back
size_t old_subpath_index = sat_curve_time.path_index;
- pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01);
- sat_path = pointwise_pv.pathAt(i);
- sat_curve_time_optional = pointwise_pv.nearestTime(pointwise_pv.curveAt(i).initialPoint());
+ pathv = path_from_piecewise(Geom::remove_short_cuts(A,0.01),0.01);
+ sat_path = pathv.pathAt(i);
+ sat_curve_time_optional = pathv.nearestTime(pathv.curveAt(i).initialPoint());
if(sat_curve_time_optional) {
sat_curve_time = *sat_curve_time_optional;
}
diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h
index 9d2993a23..a2324accd 100644
--- a/src/helper/geom-pointwise.h
+++ b/src/helper/geom-pointwise.h
@@ -64,6 +64,7 @@ public:
private:
pwd2sb _pwd2;
+ Geom::PathVector _pathvector;
std::vector<Satellite> _satellites;
};
diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp
index 10afca725..35d21ef32 100644
--- a/src/helper/geom-satellite.cpp
+++ b/src/helper/geom-satellite.cpp
@@ -115,7 +115,7 @@ double arcLengthAt(double const A, Geom::Curve const &curve_in, size_t cache_lim
s = (A * length_part);
} else if (!curve_in.isLineSegment()) {
Geom::Curve *curve = curve_in.portion(0.0, A);
- s = curve->length(0.001);
+ s = curve->length();
}
deque_cache.push_front(std::make_pair(s, std::make_pair(A, d2_in)));
return s;
@@ -261,7 +261,7 @@ void Satellite::setPosition(Geom::Point const p, Geom::Curve const &curve_in, bo
if (!is_time) {
A = arcLengthAt(A, *curve);
}
- this->setAmount(A);
+ amount = A;
}
/**
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index 385e9ce28..3fa011b38 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -94,7 +94,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem)
continue;
}
Geom::Path::const_iterator curve_it1 = path_it->begin();
- Geom::Path::const_iterator curve_endit = path_it->end_closed();
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
int counter = 0;
size_t steps = chamfer_steps;
while (curve_it1 != curve_endit) {
@@ -121,8 +121,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem)
}
}
pointwise = new Pointwise();
- pointwise->setPathVector(pathv);
- pointwise->setSatellites(satellites, false);
+ pointwise->setPwd2(paths_to_pw(pathv));
+ pointwise->setSatellites(satellites);
//pointwise->setStart();
satellites_param.setPointwise(pointwise);
} else {
@@ -260,10 +260,10 @@ void LPEFilletChamfer::updateAmount()
power = radius / 100;
}
std::vector<Satellite> satellites = pointwise->getSatellites();
- Geom::PathVector const pathv = pointwise->getPathVector();
//todo 2GEOM I want to substiturte all Piecewise<D2<SBasis> > whith a PathVector
//but is very dificult know the index of a curve inside a pathvector with current API
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2();
+ Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01);
for (std::vector<Satellite>::iterator it = satellites.begin();
it != satellites.end(); ++it) {
Geom::Path sat_path = pathv.pathAt(it - satellites.begin());
@@ -367,10 +367,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
pathv_to_linear_and_cubic_beziers(c->get_pathvector());
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = paths_to_pw(pathv);
pwd2 = remove_short_cuts(pwd2, 0.01);
- std::vector<Satellite> sats = normalizeSatellites(pathv, satellites_param.data());
+ std::vector<Satellite> sats = satellites_param.data();
if(sats.empty()) {
doOnApply(lpeItem);
- sats = normalizeSatellites(pathv, satellites_param.data());
+ sats = satellites_param.data();
}
if (hide_knots) {
satellites_param.setHelperSize(0);
diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp
index ba1338daa..6c3123f12 100644
--- a/src/live_effects/parameter/satellitearray.cpp
+++ b/src/live_effects/parameter/satellitearray.cpp
@@ -87,38 +87,37 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror)
continue;
}
double pos = 0;
- if (pathv.size() <= i) {
+ if (pwd2.size() <= i) {
break;
}
- Geom::Curve &curve = const_cast<Geom::Curve &>(pathv.curveAt(i));
+ Geom::Curve *curve_in = pathv.curveAt(i).duplicate();
bool overflow = false;
- double size_out = _vector[i].arcDistance(pathv.curveAt(i));
- double lenght_out = pathv.curveAt(i).length( Geom::EPSILON);
+ double size_out = _vector[i].arcDistance(*curve_in);
+ double lenght_out = curve_in->length();
double lenght_in = 0;
Geom::Path sat_path = pathv.pathAt(i);
- boost::optional<size_t> d2_prev_index = boost::none;
+ boost::optional<size_t> curve_prev_index = boost::none;
size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2);
size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2);
if (sat_path.closed() && sat_curve_time == first) {
- //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2);
- d2_prev_index = sat_curve_time + sat_path.size() - 1;
+ curve_prev_index = sat_curve_time + sat_path.size() - 1;
} else if(!sat_path.closed() || sat_curve_time != first) {
- d2_prev_index = sat_curve_time - 1;
+ curve_prev_index = sat_curve_time - 1;
}
- if (d2_prev_index) {
- lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON);
+ if (curve_prev_index) {
+ lenght_in = pathv.curveAt(*curve_prev_index).length();
}
if (mirror == true) {
- if (d2_prev_index) {
- curve = pathv.curveAt(*d2_prev_index);
- pos = _vector[i].time(size_out, true, curve);
+ if (curve_prev_index) {
+ curve_in = const_cast<Geom::Curve *>(&pathv.curveAt(*curve_prev_index));
+ pos = _vector[i].time(size_out, true, *curve_in);
if (lenght_out < size_out) {
overflow = true;
}
}
} else {
- pos = _vector[i].time(curve);
+ pos = _vector[i].time(*curve_in);
if (lenght_in < size_out) {
overflow = true;
}
@@ -126,8 +125,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror)
if (pos <= 0 || pos >= 1) {
continue;
}
- Geom::Point point_a = curve.pointAt(pos);
- Geom::Point deriv_a = unit_vector(derivative(curve.toSBasis()).valueAt(pos));
+ Geom::Point point_a = curve_in->pointAt(pos);
+ Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos));
Geom::Rotate rot(Geom::Rotate::from_degrees(-90));
deriv_a = deriv_a * rot;
Geom::Point point_c = point_a - deriv_a * _helper_size;
@@ -142,7 +141,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror)
} else {
aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270));
}
- aff *= Geom::Translate(curve.pointAt(pos));
+ aff *= Geom::Translate(curve_in->pointAt(pos));
pathv *= aff;
_hp.push_back(pathv[0]);
_hp.push_back(pathv[1]);
@@ -172,7 +171,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror)
} else {
aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270));
}
- aff *= Geom::Translate(curve.pointAt(pos));
+ aff *= Geom::Translate(curve_in->pointAt(pos));
pathv *= aff;
_hp.push_back(pathv[0]);
}
@@ -296,10 +295,29 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p,
Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01);
if (_index >= _pparam->_vector.size() ) {
Geom::Path sat_path = pathv.pathAt(index);
- if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) {
- satellite.setPosition(s, sat_path.back(), true);
- } else {
- satellite.setPosition(s, pathv.curveAt(index-1), true);
+ boost::optional<size_t> curve_prev_index = boost::none;
+ size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2);
+ size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2);
+ if (sat_path.closed() && sat_curve_time == first) {
+ curve_prev_index = sat_curve_time + sat_path.size() - 1;
+ } else if(!sat_path.closed() || sat_curve_time != first) {
+ curve_prev_index = sat_curve_time - 1;
+ }
+ if (curve_prev_index) {
+ Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index);
+ double mirror_time = Geom::nearest_time(s, curve_in);
+ double time_start = 0;
+ std::vector<Satellite> sats = pointwise->getSatellites();
+ time_start = sats[*curve_prev_index].time(curve_in);
+ if (time_start > mirror_time) {
+ mirror_time = time_start;
+ }
+ double size = arcLengthAt(mirror_time, curve_in);
+ double amount = curve_in.length() - size;
+ if (satellite.is_time) {
+ amount = timeAtArcLength(amount, pathv.curveAt(index));
+ }
+ satellite.amount = amount;
}
} else {
satellite.setPosition(s, pathv.curveAt(index));
@@ -336,11 +354,32 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const
}
this->knot->show();
if (_index >= _pparam->_vector.size()) {
+ tmp_point = satellite.getPosition(pathv.curveAt(index));
Geom::Path sat_path = pathv.pathAt(index);
- if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) {
- tmp_point = satellite.getPosition(sat_path.back(), true);
- } else {
- tmp_point = satellite.getPosition(pathv.curveAt(index - 1), true);
+ boost::optional<size_t> curve_prev_index = boost::none;
+ size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2);
+ size_t first = Geom::nearest_time(sat_path.initialPoint(), pwd2);
+ if (sat_path.closed() && sat_curve_time == first) {
+ curve_prev_index = sat_curve_time + sat_path.size() - 1;
+ } else if(!sat_path.closed() || sat_curve_time != first) {
+ curve_prev_index = sat_curve_time - 1;
+ }
+ if (curve_prev_index) {
+ Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index);
+ double s = satellite.arcDistance(pathv.curveAt(index));
+ double t = satellite.time(s, true, curve_in);
+ if (t > 1) {
+ t = 1;
+ }
+ if (t < 0) {
+ t = 0;
+ }
+ double time_start = 0;
+ time_start = pointwise->getSatellites()[*curve_prev_index].time(curve_in);
+ if (time_start > t) {
+ t = time_start;
+ }
+ tmp_point = (curve_in).pointAt(t);
}
} else {
tmp_point = satellite.getPosition(pathv.curveAt(index));
@@ -410,29 +449,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state)
Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01);
double amount = _pparam->_vector.at(index).amount;
Geom::Path sat_path = pathv.pathAt(index);
- boost::optional<size_t> d2_prev_index = boost::none;
+ boost::optional<size_t> curve_prev_index = boost::none;
size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2);
size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2);
if (sat_path.closed() && sat_curve_time == first) {
- sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2);
- d2_prev_index = sat_curve_time + sat_path.size() - 1;
+ curve_prev_index = sat_curve_time + sat_path.size() - 1;
} else if(!sat_path.closed() || sat_curve_time != first) {
- d2_prev_index = sat_curve_time - 1;
+ curve_prev_index = sat_curve_time - 1;
}
-
if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) {
- if (d2_prev_index) {
- amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*d2_prev_index), pathv.curveAt(index),_pparam->_vector.at(*d2_prev_index));
+ if (curve_prev_index) {
+ amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*curve_prev_index), pathv.curveAt(index), _pparam->_vector.at(*curve_prev_index));
} else {
amount = 0.0;
}
}
bool aprox = false;
- Geom::Curve const &curve_out = pathv.curveAt(index);
- if (d2_prev_index) {
- Geom::Curve const &curve_in = pathv.curveAt(*d2_prev_index);
- aprox = (curve_in.degreesOfFreedom() != 2 ||
- curve_out.degreesOfFreedom() != 2) &&
+ Geom::D2<Geom::SBasis> d2_out = _pparam->_last_pointwise->getPwd2()[index];
+ if (curve_prev_index) {
+ Geom::D2<Geom::SBasis> d2_in =
+ _pparam->_last_pointwise->getPwd2()[*curve_prev_index];
+ aprox = ((d2_in)[0].degreesOfFreedom() != 2 ||
+ d2_out[0].degreesOfFreedom() != 2) &&
!_pparam->_use_distance
? true
: false;
@@ -463,7 +501,6 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite)
size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2);
size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2);
if (sat_path.closed() && sat_curve_time == first) {
- //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2);
prev = sat_curve_time + sat_path.size() - 1;
} else if(!sat_path.closed() || sat_curve_time != first) {
prev = sat_curve_time - 1;