mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 11:39:16 +02:00
Code cleanup
This commit is contained in:
@ -1,16 +0,0 @@
|
||||
#include <cctype>
|
||||
#include "str2int.h"
|
||||
|
||||
int str2int(const char *str, int len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (const char *sp = str; sp < str + len; sp++) {
|
||||
if (::isdigit(*sp))
|
||||
res = res * 10 + *sp - '0';
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#ifndef MISC_H
|
||||
#define MISC_H
|
||||
|
||||
int str2int(const char *str, int len);
|
||||
|
||||
#endif // MISC_H
|
50
src/common/util.cpp
Normal file
50
src/common/util.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include "util.h"
|
||||
|
||||
|
||||
int str2int(const char *str, int len)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
for (const char *sp = str; sp < str + len; sp++) {
|
||||
if (::isdigit(*sp))
|
||||
res = res * 10 + *sp - '0';
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
double niceNum(double x, int round)
|
||||
{
|
||||
int expv;
|
||||
double f;
|
||||
double nf;
|
||||
|
||||
expv = (int)floor(log10(x));
|
||||
f = x / pow(10.0, expv);
|
||||
|
||||
if (round) {
|
||||
if (f < 1.5)
|
||||
nf = 1.0;
|
||||
else if (f < 3.0)
|
||||
nf = 2.0;
|
||||
else if (f < 7.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
} else {
|
||||
if (f <= 1.0)
|
||||
nf = 1.0;
|
||||
else if (f <= 2.0)
|
||||
nf = 2.0;
|
||||
else if (f <= 5.0)
|
||||
nf = 5.0;
|
||||
else
|
||||
nf = 10.0;
|
||||
}
|
||||
|
||||
return nf * pow(10.0, expv);
|
||||
}
|
7
src/common/util.h
Normal file
7
src/common/util.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
int str2int(const char *str, int len);
|
||||
double niceNum(double x, int round);
|
||||
|
||||
#endif // UTIL_H
|
Reference in New Issue
Block a user