Skip to content

Commit

Permalink
Use std::max/std::min instead of MAX/MIN macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
zamazan4ik committed May 20, 2018
1 parent c34e145 commit 14ae0b8
Show file tree
Hide file tree
Showing 60 changed files with 401 additions and 318 deletions.
3 changes: 2 additions & 1 deletion src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <unistd.h>
#endif // _WIN32

#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
Expand Down Expand Up @@ -2122,7 +2123,7 @@ bool TessBaseAPI::GetTextDirection(int* out_offset, float* out_slope) {
// Shift the baseline down so it passes through the nearest bottom-corner
// of the textline's bounding box. This is the difference between the y
// at the lowest (max) edge of the box and the actual box bottom.
*out_offset += bottom - MAX(left_y, right_y);
*out_offset += bottom - std::max(left_y, right_y);
// Switch back to bottom-up tesseract coordinates. Requires negation of
// the slope and height - offset for the offset.
*out_slope = -*out_slope;
Expand Down
5 changes: 3 additions & 2 deletions src/ccmain/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "config_auto.h"
#endif

#include <algorithm>
#include <string.h>
#include <cmath>
#ifdef __UNIX__
Expand Down Expand Up @@ -783,7 +784,7 @@ static void EvaluateWordSpan(const PointerVector<WERD_RES>& words,
*bad = true;
} else {
*rating += choice->rating();
*certainty = MIN(*certainty, choice->certainty());
*certainty = std::min(*certainty, choice->certainty());
if (!Dict::valid_word_permuter(choice->permuter(), false))
*valid_permuter = false;
}
Expand Down Expand Up @@ -818,7 +819,7 @@ static int SelectBestWords(double rating_ratio,
int n_right = -INT32_MAX;
int next_n_left = INT32_MAX;
WordGap(*new_words, n, &n_right, &next_n_left);
if (MAX(b_right, n_right) < MIN(next_b_left, next_n_left)) {
if (std::max(b_right, n_right) < std::min(next_b_left, next_n_left)) {
// The word breaks overlap. [start_b,b] and [start_n, n] match.
break;
}
Expand Down
17 changes: 9 additions & 8 deletions src/ccmain/equationdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <limits.h>
#endif

#include <algorithm>
#include <float.h>
#include <limits>

Expand Down Expand Up @@ -336,11 +337,11 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) {
const bool xoverlap = blob_box.major_x_overlap(nextblob_box),
yoverlap = blob_box.y_overlap(nextblob_box);
const float widthR = static_cast<float>(
MIN(nextblob_box.width(), blob_box.width())) /
MAX(nextblob_box.width(), blob_box.width());
std::min(nextblob_box.width(), blob_box.width())) /
std::max(nextblob_box.width(), blob_box.width());
const float heightR = static_cast<float>(
MIN(nextblob_box.height(), blob_box.height())) /
MAX(nextblob_box.height(), blob_box.height());
std::min(nextblob_box.height(), blob_box.height())) /
std::max(nextblob_box.height(), blob_box.height());

if (xoverlap && yoverlap && widthR > kWidthR && heightR > kHeightR) {
// Found one, set nextblob type and recompute blob_box.
Expand Down Expand Up @@ -882,7 +883,7 @@ int EquationDetect::EstimateTextPartLineSpacing() {
if (current_box.major_x_overlap(prev_box) &&
!current_box.y_overlap(prev_box)) {
int gap = current_box.y_gap(prev_box);
if (gap < MIN(current_box.height(), prev_box.height())) {
if (gap < std::min(current_box.height(), prev_box.height())) {
// The gap should be smaller than the height of the bounding boxes.
ygaps.push_back(gap);
}
Expand Down Expand Up @@ -955,7 +956,7 @@ bool EquationDetect::IsInline(const bool search_bottom,
while ((neighbor = search.NextVerticalSearch(search_bottom)) != nullptr) {
const TBOX& neighbor_box(neighbor->bounding_box());
if (part_box.y_gap(neighbor_box) > kYGapRatioTh *
MIN(part_box.height(), neighbor_box.height())) {
std::min(part_box.height(), neighbor_box.height())) {
// Finished searching.
break;
}
Expand All @@ -971,8 +972,8 @@ bool EquationDetect::IsInline(const bool search_bottom,
if (part_box.x_overlap(neighbor_box) && // Location feature.
part_box.y_gap(neighbor_box) <= kYGapTh && // Line spacing.
// Geo feature.
static_cast<float>(MIN(part_box.height(), neighbor_box.height())) /
MAX(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
static_cast<float>(std::min(part_box.height(), neighbor_box.height())) /
std::max(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
return true;
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/ccmain/fixxht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*
**********************************************************************/

#include <string.h>
#include <ctype.h>
#include "params.h"
#include "float2int.h"
#include "tesseractclass.h"
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include "params.h"
#include "float2int.h"
#include "tesseractclass.h"

namespace tesseract {

Expand Down Expand Up @@ -123,7 +124,7 @@ float Tesseract::ComputeCompatibleXheight(WERD_RES *word_res,
// Chars with a wild top range would mess up the result so ignore them.
if (max_top - min_top > kMaxCharTopRange)
continue;
int misfit_dist = MAX((min_top - x_ht_acceptance_tolerance) - top,
int misfit_dist = std::max((min_top - x_ht_acceptance_tolerance) - top,
top - (max_top + x_ht_acceptance_tolerance));
int height = top - kBlnBaselineOffset;
if (debug_x_ht_level >= 2) {
Expand Down
6 changes: 4 additions & 2 deletions src/ccmain/linerec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "pageres.h"
#include "tprintf.h"

#include <algorithm>

namespace tesseract {

// Scale factor to make certainty more comparable to Tesseract.
Expand Down Expand Up @@ -279,13 +281,13 @@ void Tesseract::SearchWords(PointerVector<WERD_RES>* words) {
word->tess_would_adapt = false;
word->done = true;
word->tesseract = this;
float word_certainty = MIN(word->space_certainty,
float word_certainty = std::min(word->space_certainty,
word->best_choice->certainty());
word_certainty *= kCertaintyScale;
if (getDict().stopper_debug_level >= 1) {
tprintf("Best choice certainty=%g, space=%g, scaled=%g, final=%g\n",
word->best_choice->certainty(), word->space_certainty,
MIN(word->space_certainty, word->best_choice->certainty()) *
std::min(word->space_certainty, word->best_choice->certainty()) *
kCertaintyScale,
word_certainty);
word->best_choice->print();
Expand Down
4 changes: 3 additions & 1 deletion src/ccmain/osdetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "tesseractclass.h"
#include "textord.h"

#include <algorithm>

const int kMinCharactersToTry = 50;
const int kMaxCharactersToTry = 5 * kMinCharactersToTry;

Expand Down Expand Up @@ -282,7 +284,7 @@ int os_detect_blobs(const GenericVector<int>* allowed_scripts,
ScriptDetector s(allowed_scripts, osr, tess);

BLOBNBOX_C_IT filtered_it(blob_list);
int real_max = MIN(filtered_it.length(), kMaxCharactersToTry);
int real_max = std::min(filtered_it.length(), kMaxCharactersToTry);
// tprintf("Total blobs found = %d\n", blobs_total);
// tprintf("Number of blobs post-filtering = %d\n", filtered_it.length());
// tprintf("Number of blobs to try = %d\n", real_max);
Expand Down
20 changes: 11 additions & 9 deletions src/ccmain/pageiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "pageres.h"
#include "tesseractclass.h"

#include <algorithm>

namespace tesseract {

PageIterator::PageIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale,
Expand Down Expand Up @@ -421,9 +423,9 @@ Pix* PageIterator::GetBinaryImage(PageIteratorLevel level) const {
int mask_x = left - mask_box.left();
int mask_y = top - (tesseract_->ImageHeight() - mask_box.top());
// AND the mask and pix, putting the result in pix.
pixRasterop(pix, MAX(0, -mask_x), MAX(0, -mask_y), pixGetWidth(pix),
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, MAX(0, mask_x),
MAX(0, mask_y));
pixRasterop(pix, std::max(0, -mask_x), std::max(0, -mask_y), pixGetWidth(pix),
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, std::max(0, mask_x),
std::max(0, mask_y));
pixDestroy(&mask);
}
return pix;
Expand All @@ -450,10 +452,10 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
return GetBinaryImage(level);

// Expand the box.
*left = MAX(*left - padding, 0);
*top = MAX(*top - padding, 0);
right = MIN(right + padding, rect_width_);
bottom = MIN(bottom + padding, rect_height_);
*left = std::max(*left - padding, 0);
*top = std::max(*top - padding, 0);
right = std::min(right + padding, rect_width_);
bottom = std::min(bottom + padding, rect_height_);
Box* box = boxCreate(*left, *top, right - *left, bottom - *top);
Pix* grey_pix = pixClipRectangle(original_img, box, nullptr);
boxDestroy(&box);
Expand All @@ -467,8 +469,8 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
int width = pixGetWidth(grey_pix);
int height = pixGetHeight(grey_pix);
Pix* resized_mask = pixCreate(width, height, 1);
pixRasterop(resized_mask, MAX(0, -mask_x), MAX(0, -mask_y), width, height,
PIX_SRC, mask, MAX(0, mask_x), MAX(0, mask_y));
pixRasterop(resized_mask, std::max(0, -mask_x), std::max(0, -mask_y), width, height,
PIX_SRC, mask, std::max(0, mask_x), std::max(0, mask_y));
pixDestroy(&mask);
pixDilateBrick(resized_mask, resized_mask, 2 * padding + 1,
2 * padding + 1);
Expand Down
3 changes: 2 additions & 1 deletion src/ccmain/paragraphs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
**********************************************************************/

#include <algorithm>
#include <ctype.h>
#include <memory> // std::unique_ptr

Expand Down Expand Up @@ -2415,7 +2416,7 @@ void InitializeRowInfo(bool after_recognition,
info->pix_ldistance = row->lmargin();
info->pix_rdistance = row->rmargin();
info->average_interword_space =
row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
row->space() > 0 ? row->space() : std::max(static_cast<int>(row->x_height()), 1);
info->pix_xheight = row->x_height();
info->has_leaders = false;
info->has_drop_cap = row->has_drop_cap();
Expand Down
12 changes: 7 additions & 5 deletions src/ccstruct/blobbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "helpers.h"
#include "normalis.h"

#include <algorithm>

#define PROJECTION_MARGIN 10 //arbitrary
#define EXTERN

Expand Down Expand Up @@ -194,14 +196,14 @@ void BLOBNBOX::NeighbourGaps(int gaps[BND_COUNT]) const {
// and avoid reporting the other gap as a ridiculously large number
void BLOBNBOX::MinMaxGapsClipped(int* h_min, int* h_max,
int* v_min, int* v_max) const {
int max_dimension = MAX(box.width(), box.height());
int max_dimension = std::max(box.width(), box.height());
int gaps[BND_COUNT];
NeighbourGaps(gaps);
*h_min = MIN(gaps[BND_LEFT], gaps[BND_RIGHT]);
*h_max = MAX(gaps[BND_LEFT], gaps[BND_RIGHT]);
*h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
*h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
*v_min = MIN(gaps[BND_ABOVE], gaps[BND_BELOW]);
*v_max = MAX(gaps[BND_ABOVE], gaps[BND_BELOW]);
*v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
*v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);
if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
}

Expand Down
32 changes: 17 additions & 15 deletions src/ccstruct/blobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#include "structures.h"
#include "werd.h"

#include <algorithm>

using tesseract::CCStruct;

// A Vector representing the "vertical" direction when measuring the
Expand Down Expand Up @@ -587,10 +589,10 @@ static void SegmentLLSQ(const FCOORD& pt1, const FCOORD& pt2,
LLSQ* accumulator) {
FCOORD step(pt2);
step -= pt1;
int xstart = IntCastRounded(MIN(pt1.x(), pt2.x()));
int xend = IntCastRounded(MAX(pt1.x(), pt2.x()));
int ystart = IntCastRounded(MIN(pt1.y(), pt2.y()));
int yend = IntCastRounded(MAX(pt1.y(), pt2.y()));
int xstart = IntCastRounded(std::min(pt1.x(), pt2.x()));
int xend = IntCastRounded(std::max(pt1.x(), pt2.x()));
int ystart = IntCastRounded(std::min(pt1.y(), pt2.y()));
int yend = IntCastRounded(std::max(pt1.y(), pt2.y()));
if (xstart == xend && ystart == yend) return; // Nothing to do.
double weight = step.length() / (xend - xstart + yend - ystart);
// Compute and save the y-position at the middle of each x-step.
Expand All @@ -616,14 +618,14 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
GenericVector<GenericVector<int> >* y_coords) {
FCOORD step(pt2);
step -= pt1;
int start = ClipToRange(IntCastRounded(MIN(pt1.x(), pt2.x())), 0, x_limit);
int end = ClipToRange(IntCastRounded(MAX(pt1.x(), pt2.x())), 0, x_limit);
int start = ClipToRange(IntCastRounded(std::min(pt1.x(), pt2.x())), 0, x_limit);
int end = ClipToRange(IntCastRounded(std::max(pt1.x(), pt2.x())), 0, x_limit);
for (int x = start; x < end; ++x) {
int y = IntCastRounded(pt1.y() + step.y() * (x + 0.5 - pt1.x()) / step.x());
(*y_coords)[x].push_back(y);
}
start = ClipToRange(IntCastRounded(MIN(pt1.y(), pt2.y())), 0, y_limit);
end = ClipToRange(IntCastRounded(MAX(pt1.y(), pt2.y())), 0, y_limit);
start = ClipToRange(IntCastRounded(std::min(pt1.y(), pt2.y())), 0, y_limit);
end = ClipToRange(IntCastRounded(std::max(pt1.y(), pt2.y())), 0, y_limit);
for (int y = start; y < end; ++y) {
int x = IntCastRounded(pt1.x() + step.x() * (y + 0.5 - pt1.y()) / step.y());
(*x_coords)[y].push_back(x);
Expand All @@ -636,24 +638,24 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
static void SegmentBBox(const FCOORD& pt1, const FCOORD& pt2, TBOX* bbox) {
FCOORD step(pt2);
step -= pt1;
int x1 = IntCastRounded(MIN(pt1.x(), pt2.x()));
int x2 = IntCastRounded(MAX(pt1.x(), pt2.x()));
int x1 = IntCastRounded(std::min(pt1.x(), pt2.x()));
int x2 = IntCastRounded(std::max(pt1.x(), pt2.x()));
if (x2 > x1) {
int y1 = IntCastRounded(pt1.y() + step.y() * (x1 + 0.5 - pt1.x()) /
step.x());
int y2 = IntCastRounded(pt1.y() + step.y() * (x2 - 0.5 - pt1.x()) /
step.x());
TBOX point(x1, MIN(y1, y2), x2, MAX(y1, y2));
TBOX point(x1, std::min(y1, y2), x2, std::max(y1, y2));
*bbox += point;
}
int y1 = IntCastRounded(MIN(pt1.y(), pt2.y()));
int y2 = IntCastRounded(MAX(pt1.y(), pt2.y()));
int y1 = IntCastRounded(std::min(pt1.y(), pt2.y()));
int y2 = IntCastRounded(std::max(pt1.y(), pt2.y()));
if (y2 > y1) {
int x1 = IntCastRounded(pt1.x() + step.x() * (y1 + 0.5 - pt1.y()) /
step.y());
int x2 = IntCastRounded(pt1.x() + step.x() * (y2 - 0.5 - pt1.y()) /
step.y());
TBOX point(MIN(x1, x2), y1, MAX(x1, x2), y2);
TBOX point(std::min(x1, x2), y1, std::max(x1, x2), y2);
*bbox += point;
}
}
Expand Down Expand Up @@ -956,7 +958,7 @@ bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location) {
int min_prod2, max_prod2;
outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
int mid_gap = abs(mid_prod2 - mid_prod1);
int overlap = MIN(max_prod1, max_prod2) - MAX(min_prod1, min_prod2);
int overlap = std::min(max_prod1, max_prod2) - std::max(min_prod1, min_prod2);
if (mid_gap - overlap / 4 > max_gap) {
max_gap = mid_gap - overlap / 4;
*location = mid_pt1;
Expand Down
5 changes: 3 additions & 2 deletions src/ccstruct/coutln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
**********************************************************************/

#include <algorithm>
#include <string.h>
#ifdef __UNIX__
#include <assert.h>
Expand Down Expand Up @@ -750,7 +751,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
if (pt1.y == pt2.y && abs(gradient.y()) * 2 >= abs(gradient.x())) {
// Horizontal step. diff_sign == 1 indicates black above.
int diff_sign = (pt1.x > pt2.x) == negative ? 1 : -1;
int x = MIN(pt1.x, pt2.x);
int x = std::min(pt1.x, pt2.x);
int y = height - pt1.y;
int best_sum = 0;
int best_y = y;
Expand All @@ -773,7 +774,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
// Vertical step. diff_sign == 1 indicates black on the left.
int diff_sign = (pt1.y > pt2.y) == negative ? 1 : -1;
int x = pt1.x;
int y = height - MAX(pt1.y, pt2.y);
int y = height - std::max(pt1.y, pt2.y);
const l_uint32* line = pixGetData(pix) + y * wpl;
int best_sum = 0;
int best_x = x;
Expand Down
6 changes: 4 additions & 2 deletions src/ccstruct/detlinefit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "ndminx.h"
#include "tprintf.h"

#include <algorithm>

namespace tesseract {

// The number of points to consider at each end.
Expand Down Expand Up @@ -77,14 +79,14 @@ double DetLineFit::Fit(int skip_first, int skip_last,
ICOORD* starts[kNumEndPoints];
if (skip_first >= pt_count) skip_first = pt_count - 1;
int start_count = 0;
int end_i = MIN(skip_first + kNumEndPoints, pt_count);
int end_i = std::min(skip_first + kNumEndPoints, pt_count);
for (int i = skip_first; i < end_i; ++i) {
starts[start_count++] = &pts_[i].pt;
}
ICOORD* ends[kNumEndPoints];
if (skip_last >= pt_count) skip_last = pt_count - 1;
int end_count = 0;
end_i = MAX(0, pt_count - kNumEndPoints - skip_last);
end_i = std::max(0, pt_count - kNumEndPoints - skip_last);
for (int i = pt_count - 1 - skip_last; i >= end_i; --i) {
ends[end_count++] = &pts_[i].pt;
}
Expand Down
Loading

0 comments on commit 14ae0b8

Please sign in to comment.