this functions takes the coordinate value as a floating point value in meters; it has to find the appropriate scaling to represent this value with appropriate precision in an integer variable
143 const bool debug=
false;
145 this->
coo=
static_cast<int>(nearbyint(
value));
154 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
155 "v: " << helper::MyOutputFormat() << v <<
"\n" 156 "log10(v): " << std::log10(v) <<
"\n" 157 "floor(log10(v)): " << std::floor(std::log10(v)));
158 int nlead=1+
static_cast<int>(std::floor(std::log10(v)));
161 int nzero=ntrail-nsig;
162 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
163 "nlead: " << nlead <<
164 " ntrail: " << ntrail <<
169 DATRW_debug(debug,
"ScalCoo::set(const double& v)",
170 "nlead: " << nlead <<
171 " ntrail: " << ntrail <<
175 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
177 int s=std::pow(10,ntrail);
178 s = s > 10000 ? 10000 : s;
180 "ERROR (ScalCoo::set): scale too large");
182 this->
coo=
static_cast<int>(nearbyint(
value*s));
184 double truevalue=
value*s;
185 double roundedvalue=nearbyint(truevalue);
186 double truncationerror=fabs(1.-(truevalue/roundedvalue));
187 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
189 <<
" truevalue: " << truevalue
190 <<
" roundedvalue: " << roundedvalue
191 <<
" truncationerror: " << truncationerror);
193 "WARNING (ScalCoo::set) " 194 "truncation error > 0.1%\n" 196 << helper::MyOutputFormat() <<
value 197 <<
" will be truncated!" 199 <<
" scaled value: " << truevalue
200 <<
" rounded scaled value: " 205 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
207 int s=std::pow(10,nlead-nsig);
208 s = s > 10000 ? 10000 : s;
210 "ERROR (ScalCoo::set): scale too large");
212 this->
coo=
static_cast<int>(nearbyint(
value/s));
217 DATRW_debug(debug,
"ScalCoo::set(const double& value)",
219 <<
" value: " <<
value 220 <<
" this->coo: " << this->
coo 221 <<
" this->scale: " << this->
scale);
#define DATRW_assert(C, M)
Check an assertion and report by throwing an exception.
unsigned int coodigits
maximum number of significant digits to be used
short scale
scale like scalco
short scalco
preferred scalco value
static double effectivezero
lower limit of values
datrw::su::options::SpatialSampling Mcontrol
control parameters
int ntrailingdigits(double v, const bool &debug)
return number of trailing digits (after decimal point)
int nsignificantdigits(double v, const bool &debug)
return number of significant digits
int smallestpower(const short &desiredscale=datrw::su::subformat::def::scalco) const
smallest possible power larger or equal desired
#define DATRW_debug(C, N, M)
produce debug output
void scaletopower(const int &p)
scale to given scaling factor as defined by decimal power
double value() const
return coordinate value
#define DATRW_report_assert(C, M)
Check an assertion and report only.