Skip to content

Commit d54d748

Browse files
committed
Use std::max/std::min instead of MAX/MIN macros.
1 parent c34e145 commit d54d748

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+404
-320
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ endif()
6767
if (WIN32)
6868
if (MSVC)
6969
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
70+
add_definitions(-DNOMINMAX)
7071

7172
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /openmp /utf-8")
7273
endif()

src/api/baseapi.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <unistd.h>
4343
#endif // _WIN32
4444

45+
#include <algorithm>
4546
#include <fstream>
4647
#include <iostream>
4748
#include <iterator>
@@ -2122,7 +2123,7 @@ bool TessBaseAPI::GetTextDirection(int* out_offset, float* out_slope) {
21222123
// Shift the baseline down so it passes through the nearest bottom-corner
21232124
// of the textline's bounding box. This is the difference between the y
21242125
// at the lowest (max) edge of the box and the actual box bottom.
2125-
*out_offset += bottom - MAX(left_y, right_y);
2126+
*out_offset += bottom - std::max(left_y, right_y);
21262127
// Switch back to bottom-up tesseract coordinates. Requires negation of
21272128
// the slope and height - offset for the offset.
21282129
*out_slope = -*out_slope;

src/ccmain/control.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "config_auto.h"
2424
#endif
2525

26+
#include <algorithm>
2627
#include <string.h>
2728
#include <cmath>
2829
#ifdef __UNIX__
@@ -783,7 +784,7 @@ static void EvaluateWordSpan(const PointerVector<WERD_RES>& words,
783784
*bad = true;
784785
} else {
785786
*rating += choice->rating();
786-
*certainty = MIN(*certainty, choice->certainty());
787+
*certainty = std::min(*certainty, choice->certainty());
787788
if (!Dict::valid_word_permuter(choice->permuter(), false))
788789
*valid_permuter = false;
789790
}
@@ -818,7 +819,7 @@ static int SelectBestWords(double rating_ratio,
818819
int n_right = -INT32_MAX;
819820
int next_n_left = INT32_MAX;
820821
WordGap(*new_words, n, &n_right, &next_n_left);
821-
if (MAX(b_right, n_right) < MIN(next_b_left, next_n_left)) {
822+
if (std::max(b_right, n_right) < std::min(next_b_left, next_n_left)) {
822823
// The word breaks overlap. [start_b,b] and [start_n, n] match.
823824
break;
824825
}

src/ccmain/equationdetect.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <limits.h>
2222
#endif
2323

24+
#include <algorithm>
2425
#include <float.h>
2526
#include <limits>
2627

@@ -336,11 +337,11 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) {
336337
const bool xoverlap = blob_box.major_x_overlap(nextblob_box),
337338
yoverlap = blob_box.y_overlap(nextblob_box);
338339
const float widthR = static_cast<float>(
339-
MIN(nextblob_box.width(), blob_box.width())) /
340-
MAX(nextblob_box.width(), blob_box.width());
340+
std::min(nextblob_box.width(), blob_box.width())) /
341+
std::max(nextblob_box.width(), blob_box.width());
341342
const float heightR = static_cast<float>(
342-
MIN(nextblob_box.height(), blob_box.height())) /
343-
MAX(nextblob_box.height(), blob_box.height());
343+
std::min(nextblob_box.height(), blob_box.height())) /
344+
std::max(nextblob_box.height(), blob_box.height());
344345

345346
if (xoverlap && yoverlap && widthR > kWidthR && heightR > kHeightR) {
346347
// Found one, set nextblob type and recompute blob_box.
@@ -685,7 +686,7 @@ void EquationDetect::SplitCPHor(ColPartition* part,
685686
}
686687

687688
// The right side of the previous blobs.
688-
previous_right = MAX(previous_right, box.right());
689+
previous_right = std::max(previous_right, static_cast<int>(box.right()));
689690
}
690691
}
691692

@@ -725,7 +726,7 @@ void EquationDetect::SplitCPHorLite(ColPartition* part,
725726
union_box += box;
726727
}
727728
// The right side of the previous blobs.
728-
previous_right = MAX(previous_right, box.right());
729+
previous_right = std::max(previous_right, static_cast<int>(box.right()));
729730
}
730731

731732
// Add the last piece.
@@ -882,7 +883,7 @@ int EquationDetect::EstimateTextPartLineSpacing() {
882883
if (current_box.major_x_overlap(prev_box) &&
883884
!current_box.y_overlap(prev_box)) {
884885
int gap = current_box.y_gap(prev_box);
885-
if (gap < MIN(current_box.height(), prev_box.height())) {
886+
if (gap < std::min(current_box.height(), prev_box.height())) {
886887
// The gap should be smaller than the height of the bounding boxes.
887888
ygaps.push_back(gap);
888889
}
@@ -955,7 +956,7 @@ bool EquationDetect::IsInline(const bool search_bottom,
955956
while ((neighbor = search.NextVerticalSearch(search_bottom)) != nullptr) {
956957
const TBOX& neighbor_box(neighbor->bounding_box());
957958
if (part_box.y_gap(neighbor_box) > kYGapRatioTh *
958-
MIN(part_box.height(), neighbor_box.height())) {
959+
std::min(part_box.height(), neighbor_box.height())) {
959960
// Finished searching.
960961
break;
961962
}
@@ -971,8 +972,8 @@ bool EquationDetect::IsInline(const bool search_bottom,
971972
if (part_box.x_overlap(neighbor_box) && // Location feature.
972973
part_box.y_gap(neighbor_box) <= kYGapTh && // Line spacing.
973974
// Geo feature.
974-
static_cast<float>(MIN(part_box.height(), neighbor_box.height())) /
975-
MAX(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
975+
static_cast<float>(std::min(part_box.height(), neighbor_box.height())) /
976+
std::max(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
976977
return true;
977978
}
978979
}

src/ccmain/fixxht.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
*
1818
**********************************************************************/
1919

20-
#include <string.h>
21-
#include <ctype.h>
22-
#include "params.h"
23-
#include "float2int.h"
24-
#include "tesseractclass.h"
20+
#include <algorithm>
21+
#include <string.h>
22+
#include <ctype.h>
23+
#include "params.h"
24+
#include "float2int.h"
25+
#include "tesseractclass.h"
2526

2627
namespace tesseract {
2728

@@ -123,7 +124,7 @@ float Tesseract::ComputeCompatibleXheight(WERD_RES *word_res,
123124
// Chars with a wild top range would mess up the result so ignore them.
124125
if (max_top - min_top > kMaxCharTopRange)
125126
continue;
126-
int misfit_dist = MAX((min_top - x_ht_acceptance_tolerance) - top,
127+
int misfit_dist = std::max((min_top - x_ht_acceptance_tolerance) - top,
127128
top - (max_top + x_ht_acceptance_tolerance));
128129
int height = top - kBlnBaselineOffset;
129130
if (debug_x_ht_level >= 2) {

src/ccmain/linerec.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "pageres.h"
3030
#include "tprintf.h"
3131

32+
#include <algorithm>
33+
3234
namespace tesseract {
3335

3436
// Scale factor to make certainty more comparable to Tesseract.
@@ -279,13 +281,13 @@ void Tesseract::SearchWords(PointerVector<WERD_RES>* words) {
279281
word->tess_would_adapt = false;
280282
word->done = true;
281283
word->tesseract = this;
282-
float word_certainty = MIN(word->space_certainty,
284+
float word_certainty = std::min(word->space_certainty,
283285
word->best_choice->certainty());
284286
word_certainty *= kCertaintyScale;
285287
if (getDict().stopper_debug_level >= 1) {
286288
tprintf("Best choice certainty=%g, space=%g, scaled=%g, final=%g\n",
287289
word->best_choice->certainty(), word->space_certainty,
288-
MIN(word->space_certainty, word->best_choice->certainty()) *
290+
std::min(word->space_certainty, word->best_choice->certainty()) *
289291
kCertaintyScale,
290292
word_certainty);
291293
word->best_choice->print();

src/ccmain/osdetect.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "tesseractclass.h"
3434
#include "textord.h"
3535

36+
#include <algorithm>
37+
3638
const int kMinCharactersToTry = 50;
3739
const int kMaxCharactersToTry = 5 * kMinCharactersToTry;
3840

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

284286
BLOBNBOX_C_IT filtered_it(blob_list);
285-
int real_max = MIN(filtered_it.length(), kMaxCharactersToTry);
287+
int real_max = std::min(filtered_it.length(), kMaxCharactersToTry);
286288
// tprintf("Total blobs found = %d\n", blobs_total);
287289
// tprintf("Number of blobs post-filtering = %d\n", filtered_it.length());
288290
// tprintf("Number of blobs to try = %d\n", real_max);

src/ccmain/pageiterator.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "pageres.h"
2525
#include "tesseractclass.h"
2626

27+
#include <algorithm>
28+
2729
namespace tesseract {
2830

2931
PageIterator::PageIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale,
@@ -421,9 +423,9 @@ Pix* PageIterator::GetBinaryImage(PageIteratorLevel level) const {
421423
int mask_x = left - mask_box.left();
422424
int mask_y = top - (tesseract_->ImageHeight() - mask_box.top());
423425
// AND the mask and pix, putting the result in pix.
424-
pixRasterop(pix, MAX(0, -mask_x), MAX(0, -mask_y), pixGetWidth(pix),
425-
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, MAX(0, mask_x),
426-
MAX(0, mask_y));
426+
pixRasterop(pix, std::max(0, -mask_x), std::max(0, -mask_y), pixGetWidth(pix),
427+
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, std::max(0, mask_x),
428+
std::max(0, mask_y));
427429
pixDestroy(&mask);
428430
}
429431
return pix;
@@ -450,10 +452,10 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
450452
return GetBinaryImage(level);
451453

452454
// Expand the box.
453-
*left = MAX(*left - padding, 0);
454-
*top = MAX(*top - padding, 0);
455-
right = MIN(right + padding, rect_width_);
456-
bottom = MIN(bottom + padding, rect_height_);
455+
*left = std::max(*left - padding, 0);
456+
*top = std::max(*top - padding, 0);
457+
right = std::min(right + padding, rect_width_);
458+
bottom = std::min(bottom + padding, rect_height_);
457459
Box* box = boxCreate(*left, *top, right - *left, bottom - *top);
458460
Pix* grey_pix = pixClipRectangle(original_img, box, nullptr);
459461
boxDestroy(&box);
@@ -467,8 +469,8 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
467469
int width = pixGetWidth(grey_pix);
468470
int height = pixGetHeight(grey_pix);
469471
Pix* resized_mask = pixCreate(width, height, 1);
470-
pixRasterop(resized_mask, MAX(0, -mask_x), MAX(0, -mask_y), width, height,
471-
PIX_SRC, mask, MAX(0, mask_x), MAX(0, mask_y));
472+
pixRasterop(resized_mask, std::max(0, -mask_x), std::max(0, -mask_y), width, height,
473+
PIX_SRC, mask, std::max(0, mask_x), std::max(0, mask_y));
472474
pixDestroy(&mask);
473475
pixDilateBrick(resized_mask, resized_mask, 2 * padding + 1,
474476
2 * padding + 1);

src/ccmain/paragraphs.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
**********************************************************************/
1919

20+
#include <algorithm>
2021
#include <ctype.h>
2122
#include <memory> // std::unique_ptr
2223

@@ -2415,7 +2416,7 @@ void InitializeRowInfo(bool after_recognition,
24152416
info->pix_ldistance = row->lmargin();
24162417
info->pix_rdistance = row->rmargin();
24172418
info->average_interword_space =
2418-
row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
2419+
row->space() > 0 ? row->space() : std::max(static_cast<int>(row->x_height()), 1);
24192420
info->pix_xheight = row->x_height();
24202421
info->has_leaders = false;
24212422
info->has_drop_cap = row->has_drop_cap();

src/ccstruct/blobbox.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "helpers.h"
2929
#include "normalis.h"
3030

31+
#include <algorithm>
32+
3133
#define PROJECTION_MARGIN 10 //arbitrary
3234
#define EXTERN
3335

@@ -194,14 +196,14 @@ void BLOBNBOX::NeighbourGaps(int gaps[BND_COUNT]) const {
194196
// and avoid reporting the other gap as a ridiculously large number
195197
void BLOBNBOX::MinMaxGapsClipped(int* h_min, int* h_max,
196198
int* v_min, int* v_max) const {
197-
int max_dimension = MAX(box.width(), box.height());
199+
int max_dimension = std::max(box.width(), box.height());
198200
int gaps[BND_COUNT];
199201
NeighbourGaps(gaps);
200-
*h_min = MIN(gaps[BND_LEFT], gaps[BND_RIGHT]);
201-
*h_max = MAX(gaps[BND_LEFT], gaps[BND_RIGHT]);
202+
*h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
203+
*h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
202204
if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
203-
*v_min = MIN(gaps[BND_ABOVE], gaps[BND_BELOW]);
204-
*v_max = MAX(gaps[BND_ABOVE], gaps[BND_BELOW]);
205+
*v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
206+
*v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);
205207
if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
206208
}
207209

src/ccstruct/blobs.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
#include "structures.h"
4848
#include "werd.h"
4949

50+
#include <algorithm>
51+
5052
using tesseract::CCStruct;
5153

5254
// A Vector representing the "vertical" direction when measuring the
@@ -587,10 +589,10 @@ static void SegmentLLSQ(const FCOORD& pt1, const FCOORD& pt2,
587589
LLSQ* accumulator) {
588590
FCOORD step(pt2);
589591
step -= pt1;
590-
int xstart = IntCastRounded(MIN(pt1.x(), pt2.x()));
591-
int xend = IntCastRounded(MAX(pt1.x(), pt2.x()));
592-
int ystart = IntCastRounded(MIN(pt1.y(), pt2.y()));
593-
int yend = IntCastRounded(MAX(pt1.y(), pt2.y()));
592+
int xstart = IntCastRounded(std::min(pt1.x(), pt2.x()));
593+
int xend = IntCastRounded(std::max(pt1.x(), pt2.x()));
594+
int ystart = IntCastRounded(std::min(pt1.y(), pt2.y()));
595+
int yend = IntCastRounded(std::max(pt1.y(), pt2.y()));
594596
if (xstart == xend && ystart == yend) return; // Nothing to do.
595597
double weight = step.length() / (xend - xstart + yend - ystart);
596598
// Compute and save the y-position at the middle of each x-step.
@@ -616,14 +618,14 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
616618
GenericVector<GenericVector<int> >* y_coords) {
617619
FCOORD step(pt2);
618620
step -= pt1;
619-
int start = ClipToRange(IntCastRounded(MIN(pt1.x(), pt2.x())), 0, x_limit);
620-
int end = ClipToRange(IntCastRounded(MAX(pt1.x(), pt2.x())), 0, x_limit);
621+
int start = ClipToRange(IntCastRounded(std::min(pt1.x(), pt2.x())), 0, x_limit);
622+
int end = ClipToRange(IntCastRounded(std::max(pt1.x(), pt2.x())), 0, x_limit);
621623
for (int x = start; x < end; ++x) {
622624
int y = IntCastRounded(pt1.y() + step.y() * (x + 0.5 - pt1.x()) / step.x());
623625
(*y_coords)[x].push_back(y);
624626
}
625-
start = ClipToRange(IntCastRounded(MIN(pt1.y(), pt2.y())), 0, y_limit);
626-
end = ClipToRange(IntCastRounded(MAX(pt1.y(), pt2.y())), 0, y_limit);
627+
start = ClipToRange(IntCastRounded(std::min(pt1.y(), pt2.y())), 0, y_limit);
628+
end = ClipToRange(IntCastRounded(std::max(pt1.y(), pt2.y())), 0, y_limit);
627629
for (int y = start; y < end; ++y) {
628630
int x = IntCastRounded(pt1.x() + step.x() * (y + 0.5 - pt1.y()) / step.y());
629631
(*x_coords)[y].push_back(x);
@@ -636,24 +638,24 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
636638
static void SegmentBBox(const FCOORD& pt1, const FCOORD& pt2, TBOX* bbox) {
637639
FCOORD step(pt2);
638640
step -= pt1;
639-
int x1 = IntCastRounded(MIN(pt1.x(), pt2.x()));
640-
int x2 = IntCastRounded(MAX(pt1.x(), pt2.x()));
641+
int x1 = IntCastRounded(std::min(pt1.x(), pt2.x()));
642+
int x2 = IntCastRounded(std::max(pt1.x(), pt2.x()));
641643
if (x2 > x1) {
642644
int y1 = IntCastRounded(pt1.y() + step.y() * (x1 + 0.5 - pt1.x()) /
643645
step.x());
644646
int y2 = IntCastRounded(pt1.y() + step.y() * (x2 - 0.5 - pt1.x()) /
645647
step.x());
646-
TBOX point(x1, MIN(y1, y2), x2, MAX(y1, y2));
648+
TBOX point(x1, std::min(y1, y2), x2, std::max(y1, y2));
647649
*bbox += point;
648650
}
649-
int y1 = IntCastRounded(MIN(pt1.y(), pt2.y()));
650-
int y2 = IntCastRounded(MAX(pt1.y(), pt2.y()));
651+
int y1 = IntCastRounded(std::min(pt1.y(), pt2.y()));
652+
int y2 = IntCastRounded(std::max(pt1.y(), pt2.y()));
651653
if (y2 > y1) {
652654
int x1 = IntCastRounded(pt1.x() + step.x() * (y1 + 0.5 - pt1.y()) /
653655
step.y());
654656
int x2 = IntCastRounded(pt1.x() + step.x() * (y2 - 0.5 - pt1.y()) /
655657
step.y());
656-
TBOX point(MIN(x1, x2), y1, MAX(x1, x2), y2);
658+
TBOX point(std::min(x1, x2), y1, std::max(x1, x2), y2);
657659
*bbox += point;
658660
}
659661
}
@@ -956,7 +958,7 @@ bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location) {
956958
int min_prod2, max_prod2;
957959
outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
958960
int mid_gap = abs(mid_prod2 - mid_prod1);
959-
int overlap = MIN(max_prod1, max_prod2) - MAX(min_prod1, min_prod2);
961+
int overlap = std::min(max_prod1, max_prod2) - std::max(min_prod1, min_prod2);
960962
if (mid_gap - overlap / 4 > max_gap) {
961963
max_gap = mid_gap - overlap / 4;
962964
*location = mid_pt1;

src/ccstruct/coutln.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
**********************************************************************/
1919

20+
#include <algorithm>
2021
#include <string.h>
2122
#ifdef __UNIX__
2223
#include <assert.h>
@@ -750,7 +751,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
750751
if (pt1.y == pt2.y && abs(gradient.y()) * 2 >= abs(gradient.x())) {
751752
// Horizontal step. diff_sign == 1 indicates black above.
752753
int diff_sign = (pt1.x > pt2.x) == negative ? 1 : -1;
753-
int x = MIN(pt1.x, pt2.x);
754+
int x = std::min(pt1.x, pt2.x);
754755
int y = height - pt1.y;
755756
int best_sum = 0;
756757
int best_y = y;
@@ -773,7 +774,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
773774
// Vertical step. diff_sign == 1 indicates black on the left.
774775
int diff_sign = (pt1.y > pt2.y) == negative ? 1 : -1;
775776
int x = pt1.x;
776-
int y = height - MAX(pt1.y, pt2.y);
777+
int y = height - std::max(pt1.y, pt2.y);
777778
const l_uint32* line = pixGetData(pix) + y * wpl;
778779
int best_sum = 0;
779780
int best_x = x;

0 commit comments

Comments
 (0)