25 #ifndef TESSERACT_CCUTIL_HELPERS_H_ 26 #define TESSERACT_CCUTIL_HELPERS_H_ 64 seed_ *= 6364136223846793005ULL;
65 seed_ += 1442695040888963407ULL;
76 int last_index =
static_cast<int>(strlen(str)) - 1;
77 while (last_index >= 0 &&
78 (str[last_index] ==
'\n' || str[last_index] ==
'\r')) {
79 str[last_index--] =
'\0';
85 if (fgetc(file) !=
'\n') fseek(file, -1, SEEK_CUR);
90 template<
typename T>
inline void Swap(T* p1, T* p2) {
98 float diff = *((
float *) arg1) - *((
float *) arg2);
101 }
else if (diff < 0) {
110 return block_size * ((n + block_size - 1) / block_size);
115 inline T
ClipToRange(
const T& x,
const T& lower_bound,
const T& upper_bound) {
124 template<
typename T1,
typename T2>
125 inline void UpdateRange(
const T1& x, T2* lower_bound, T2* upper_bound) {
126 if (x < *lower_bound)
128 if (x > *upper_bound)
133 template<
typename T1,
typename T2>
135 T2* lower_bound, T2* upper_bound) {
136 if (x_lo < *lower_bound)
138 if (x_hi > *upper_bound)
147 T* lower2, T* upper2) {
148 if (lower1 > *lower2)
150 if (upper1 < *upper2)
158 return (a % b + b) % b;
168 return a >= 0 ? (a + b / 2) / b : (a - b / 2) / b;
173 return x >= 0.0 ?
static_cast<int>(x + 0.5) : -
static_cast<int>(-x + 0.5);
178 char *cptr =
reinterpret_cast<char *
>(ptr);
179 int halfsize = num_bytes / 2;
180 for (
int i = 0; i < halfsize; ++i) {
182 cptr[i] = cptr[num_bytes - 1 - i];
183 cptr[num_bytes - 1 - i] = tmp;
203 #endif // TESSERACT_CCUTIL_HELPERS_H_
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
int IntCastRounded(double x)
void Reverse32(void *ptr)
double SignedRand(double range)
void IntersectRange(const T &lower1, const T &upper1, T *lower2, T *upper2)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
int RoundUp(int n, int block_size)
void set_seed(uinT64 seed)
int sort_floats(const void *arg1, const void *arg2)
unsigned long long int uinT64
void Reverse64(void *ptr)
void Reverse16(void *ptr)
int DivRounded(int a, int b)
double UnsignedRand(double range)
void ReverseN(void *ptr, int num_bytes)
void chomp_string(char *str)
void SkipNewline(FILE *file)