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/2geom | |
| parent | update to trunk (diff) | |
| download | inkscape-43c5af94d24cd408f7b369545e96cf9192f6ba90.tar.gz inkscape-43c5af94d24cd408f7b369545e96cf9192f6ba90.zip | |
improving code
(bzr r13645.1.24)
Diffstat (limited to 'src/2geom')
| -rw-r--r-- | src/2geom/satellite.cpp | 123 | ||||
| -rw-r--r-- | src/2geom/satellite.h | 10 |
2 files changed, 47 insertions, 86 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; |
