summaryrefslogtreecommitdiffstats
path: root/src/2geom/satellite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2geom/satellite.cpp')
-rw-r--r--src/2geom/satellite.cpp89
1 files changed, 80 insertions, 9 deletions
diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp
index b8ddd040b..9a2fa0a10 100644
--- a/src/2geom/satellite.cpp
+++ b/src/2geom/satellite.cpp
@@ -46,7 +46,14 @@ Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool
Satellite::~Satellite() {};
void
-Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in){
+Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in)
+{
+ if(!d2_in.isFinite() || d2_in.isZero()){
+ _time = 0;
+ _size = 0;
+ return;
+ }
+ double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
_time = Geom::nearest_point(p, d2_in);
if (d2_in[0].degreesOfFreedom() != 2) {
Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
@@ -55,23 +62,24 @@ Satellite::setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in){
u = Geom::portion(u, 0.0, _time);
_size = Geom::length(u, 0.001);
} else {
- double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
_size = (_time * lenghtPart);
}
+ if(_time > 0.998){
+ _time = 1;
+ }
}
-Geom::Point
-Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in){
- return d2_in.valueAt(_time);
-}
-
double
-Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in){
+Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in)
+{
+ if(!d2_in.isFinite() || d2_in.isZero()){
+ return 1;
+ }
double t = 0;
+ double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
if(_size == 0){
return 1;
}
- double lenghtPart = Geom::length(d2_in, Geom::EPSILON);
double size = lenghtPart - _size;
if (d2_in[0].degreesOfFreedom() != 2) {
Geom::Piecewise<Geom::D2<Geom::SBasis> > u;
@@ -86,9 +94,72 @@ Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in){
t = size / lenghtPart;
}
}
+ if(_time > 0.999){
+ _time = 1;
+ }
return t;
}
+void
+Satellite::updateSizeTime(Geom::D2<Geom::SBasis> d2_in)
+{
+ if(!d2_in.isFinite() || d2_in.isZero()){
+ _time = 0;
+ _size = 0;
+ return;
+ }
+ 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;
+ }
+}
+
+Geom::Point
+Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in){
+ if(!d2_in.isFinite() || d2_in.isZero()){
+ return Geom::Point(9999999999.0,9999999999.0);
+ }
+ updateSizeTime(d2_in);
+ return d2_in.valueAt(_time);
+}
+
} // end namespace Geom
/*