diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-02-28 12:13:49 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-02-28 12:13:49 +0000 |
| commit | 43c5af94d24cd408f7b369545e96cf9192f6ba90 (patch) | |
| tree | e8fca10d38d579e1a57def4361fd2a56b406b5c6 /src | |
| parent | update to trunk (diff) | |
| download | inkscape-43c5af94d24cd408f7b369545e96cf9192f6ba90.tar.gz inkscape-43c5af94d24cd408f7b369545e96cf9192f6ba90.zip | |
improving code
(bzr r13645.1.24)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/satellite.cpp | 123 | ||||
| -rw-r--r-- | src/2geom/satellite.h | 10 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 10 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 8 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 8 |
5 files changed, 56 insertions, 103 deletions
diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 9a2fa0a10..5b362d87f 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -45,119 +45,86 @@ Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool Satellite::~Satellite() {}; -void -Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in) +double +Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) { if(!d2_in.isFinite() || d2_in.isZero()){ _time = 0; _size = 0; - return; + return 0; } + double t = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - _time = Geom::nearest_point(p, d2_in); - if (d2_in[0].degreesOfFreedom() != 2) { + if (A > lenghtPart) { + t = 1; + } else if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise<Geom::D2<Geom::SBasis> > u; u.push_cut(0); u.push(d2_in, 1); - u = Geom::portion(u, 0.0, _time); - _size = Geom::length(u, 0.001); + std::vector<double> t_roots = roots(arcLengthSb(u) - A); + if (t_roots.size() > 0) { + t = t_roots[0]; + } } else { - _size = (_time * lenghtPart); + //to be sure + if (lenghtPart != 0) { + t = A / lenghtPart; + } } - if(_time > 0.998){ - _time = 1; + if(t > 0.998){ + t = 1; } + return t; } double -Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in) +Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) { if(!d2_in.isFinite() || d2_in.isZero()){ - return 1; + _time = 0; + _size = 0; + return 0; } - double t = 0; + double s = 0; double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if(_size == 0){ - return 1; - } - double size = lenghtPart - _size; if (d2_in[0].degreesOfFreedom() != 2) { Geom::Piecewise<Geom::D2<Geom::SBasis> > u; u.push_cut(0); u.push(d2_in, 1); - std::vector<double> t_roots = roots(arcLengthSb(u) - size); - if (t_roots.size() > 0) { - t = t_roots[0]; - } + u = Geom::portion(u, 0.0, A); + s = Geom::length(u, 0.001); } else { - if (size < lenghtPart && lenghtPart != 0) { - t = size / lenghtPart; - } + s = (A * lenghtPart); } - if(_time > 0.999){ - _time = 1; - } - return t; + return s; } -void -Satellite::updateSizeTime(Geom::D2<Geom::SBasis> d2_in) +double +Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in) { - if(!d2_in.isFinite() || d2_in.isZero()){ - _time = 0; - _size = 0; - return; + double s = getSize(); + if(s == 0){ + return 1; } double lenghtPart = Geom::length(d2_in, Geom::EPSILON); - if(!_isTime){ - if (_size != 0) { - if(lenghtPart <= _size){ - _time = 1; - _size = lenghtPart; - } else if (d2_in[0].degreesOfFreedom() != 2) { - Piecewise<D2<SBasis> > u; - u.push_cut(0); - u.push(d2_in, 1); - std::vector<double> t_roots = roots(arcLengthSb(u) - _size); - if (t_roots.size() > 0) { - _time = t_roots[0]; - } - } else { - if (_size < lenghtPart && lenghtPart != 0) { - _time = _size / lenghtPart; - } - } - } else { - _time = 0; - } - } else { - if (_time != 0) { - if (d2_in[0].degreesOfFreedom() != 2) { - Piecewise<D2<SBasis> > u; - u.push_cut(0); - u.push(d2_in, 1); - u = portion(u, 0, _time); - _size = length(u, 0.001); - } else { - lenghtPart = length(d2_in, EPSILON); - _size = _time * lenghtPart; - } - } else { - _size = 0; - } - } - if(_time > 0.999){ - _time = 1; - } + double size = lenghtPart - s; + return toTime(size, d2_in); } Geom::Point Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in){ - if(!d2_in.isFinite() || d2_in.isZero()){ - return Geom::Point(9999999999.0,9999999999.0); + double t = getTime(); + if(!_isTime){ + t = toTime(getSize(), d2_in); } - updateSizeTime(d2_in); - return d2_in.valueAt(_time); + return d2_in.valueAt(t); +} + +void +Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in) +{ + setTime(Geom::nearest_point(p, d2_in)); + setSize(toSize(getTime(),d2_in)); } } // end namespace Geom diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 105297f48..dd8e4d9d0 100644 --- a/src/2geom/satellite.h +++ b/src/2geom/satellite.h @@ -79,7 +79,6 @@ class Satellite { _hidden = A; } - void setTime(double A) { _time = A; @@ -131,18 +130,13 @@ class Satellite return _time; } - void updateSizeTime(Geom::D2<Geom::SBasis> d2_in); - void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> curve); Geom::Point getPosition(Geom::D2<Geom::SBasis> curve); - static const std::map<SatelliteType,gchar const *> SatelliteTypeToGcharMap; - - static const std::map<gchar const *,SatelliteType> GcharMapToSatelliteType; - double getOpositeTime(Geom::D2<Geom::SBasis> SBasisCurve); - + double toSize(double A,Geom::D2<Geom::SBasis> d2_in); + double toTime(double A,Geom::D2<Geom::SBasis> d2_in); private: SatelliteType _satellitetype; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2354aa5ed..39acdca80 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,6 +16,7 @@ #include "live_effects/lpe-fillet-chamfer.h" +#include "live_effects/lpeobject.h" #include <sp-shape.h> #include <sp-path.h> #include <2geom/pointwise.h> @@ -120,15 +121,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeItem); - if (splpeitem) { - // This writes all parameters to SVG. Is this sufficiently efficient or should we only - // write the ones that were changed? - Inkscape::LivePathEffect::Effect *lpe = splpeitem->getCurrentLPE(); - if (lpe) { - LivePathEffectObject *lpeobj = lpe->getLPEObj(); - lpeobj->updateRepr(); - } - } SPShape * shape = dynamic_cast<SPShape *>(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 473b561d2..6dad9fcc8 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -56,10 +56,10 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ sat->setSatelliteType(strarray[0]); - sat->setIsTime(helperfns_read_bool(strarray[1], true)); - sat->setActive(helperfns_read_bool(strarray[2], true)); - sat->setHasMirror(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[4], false)); + sat->setIsTime(strncmp(strarray[1],"1",1) == 0); + sat->setActive(strncmp(strarray[2],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); + sat->setHidden(strncmp(strarray[4],"1",1) == 0); double time,size; sp_svg_number_read_d(strarray[5], &size); sp_svg_number_read_d(strarray[6], &time); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index e9775da24..ff406d792 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -117,13 +117,13 @@ protected: str << ","; str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << g_strdup(nVector.second.getIsTime() ? "true" : "false"); + str << nVector.second.getIsTime(); str << "*"; - str << g_strdup(nVector.second.getActive() ? "true" : "false"); + str << nVector.second.getActive(); str << "*"; - str << g_strdup(nVector.second.getHasMirror() ? "true" : "false"); + str << nVector.second.getHasMirror(); str << "*"; - str << g_strdup(nVector.second.getHidden() ? "true" : "false"); + str << nVector.second.getHidden(); str << "*"; str << nVector.second.getSize(); str << "*"; |
