diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 6620aa52f4..0bda34d2b0 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -2429,7 +2429,7 @@ void TessBaseAPI::GetBlockTextOrientations(int** block_orientation, float re_theta = re_rotation.angle(); FCOORD classify_rotation = block_it.data()->classify_rotation(); float classify_theta = classify_rotation.angle(); - double rot_theta = - (re_theta - classify_theta) * 2.0 / PI; + double rot_theta = - (re_theta - classify_theta) * 2.0 / M_PI; if (rot_theta < 0) rot_theta += 4; int num_rotations = static_cast(rot_theta + 0.5); (*block_orientation)[i] = num_rotations; diff --git a/src/classify/cluster.cpp b/src/classify/cluster.cpp index bc0ce2685c..32be422078 100644 --- a/src/classify/cluster.cpp +++ b/src/classify/cluster.cpp @@ -1509,7 +1509,7 @@ PROTOTYPE *NewSphericalProto(uint16_t N, Proto->Variance.Spherical = MINVARIANCE; Proto->Magnitude.Spherical = - 1.0 / sqrt ((double) (2.0 * PI * Proto->Variance.Spherical)); + 1.0 / sqrt(2.0 * M_PI * Proto->Variance.Spherical); Proto->TotalMagnitude = (float)pow((double)Proto->Magnitude.Spherical, (double) N); Proto->Weight.Spherical = 1.0 / Proto->Variance.Spherical; @@ -1550,7 +1550,7 @@ PROTOTYPE *NewEllipticalProto(int16_t N, Proto->Variance.Elliptical[i] = MINVARIANCE; Proto->Magnitude.Elliptical[i] = - 1.0 / sqrt ((double) (2.0 * PI * Proto->Variance.Elliptical[i])); + 1.0 / sqrt(2.0 * M_PI * Proto->Variance.Elliptical[i]); Proto->Weight.Elliptical[i] = 1.0 / Proto->Variance.Elliptical[i]; Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i]; } diff --git a/src/classify/clusttool.cpp b/src/classify/clusttool.cpp index 632b787c9e..d61aa6c285 100644 --- a/src/classify/clusttool.cpp +++ b/src/classify/clusttool.cpp @@ -13,7 +13,7 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ + *****************************************************************************/ //--------------------------Include Files---------------------------------- #include "clusttool.h" @@ -160,7 +160,7 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) { if (ReadNFloats(fp, 1, &(Proto->Variance.Spherical)) == nullptr) DoError(ILLEGALVARIANCESPEC, "Illegal prototype variance"); Proto->Magnitude.Spherical = - 1.0 / sqrt((double)(2.0 * PI * Proto->Variance.Spherical)); + 1.0 / sqrt(2.0 * M_PI * Proto->Variance.Spherical); Proto->TotalMagnitude = pow(Proto->Magnitude.Spherical, (float)N); Proto->LogMagnitude = log((double)Proto->TotalMagnitude); Proto->Weight.Spherical = 1.0 / Proto->Variance.Spherical; @@ -175,7 +175,7 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) { Proto->TotalMagnitude = 1.0; for (i = 0; i < N; i++) { Proto->Magnitude.Elliptical[i] = - 1.0 / sqrt((double)(2.0 * PI * Proto->Variance.Elliptical[i])); + 1.0 / sqrt(2.0 * M_PI * Proto->Variance.Elliptical[i]); Proto->Weight.Elliptical[i] = 1.0 / Proto->Variance.Elliptical[i]; Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i]; } diff --git a/src/classify/fpoint.cpp b/src/classify/fpoint.cpp index 9d4a4203d0..f6613e7880 100644 --- a/src/classify/fpoint.cpp +++ b/src/classify/fpoint.cpp @@ -45,7 +45,7 @@ float DistanceBetween(FPOINT A, FPOINT B) { * @note History: Wed Mar 28 14:27:25 1990, DSJ, Created. */ float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale) { - float NumRadsInCircle = 2.0 * PI; + float NumRadsInCircle = 2.0 * M_PI; float Angle = AngleFrom (*Point1, *Point2); if (Angle < 0.0) diff --git a/src/classify/intfeaturespace.cpp b/src/classify/intfeaturespace.cpp index cf1a14e0bd..febab9a029 100644 --- a/src/classify/intfeaturespace.cpp +++ b/src/classify/intfeaturespace.cpp @@ -107,8 +107,8 @@ int IntFeatureSpace::XYToFeatureIndex(int x, int y) const { x -= feature.X; y -= feature.Y; if (x != 0 || y != 0) { - double angle = atan2(static_cast(y), static_cast(x)) + PI; - angle *= kIntFeatureExtent / (2.0 * PI); + double angle = atan2(static_cast(y), static_cast(x)) + M_PI; + angle *= kIntFeatureExtent / (2.0 * M_PI); feature.Theta = static_cast(angle + 0.5); index = Index(feature); if (index < 0) { diff --git a/src/classify/intfx.cpp b/src/classify/intfx.cpp index 885ff8512c..8437eab60a 100644 --- a/src/classify/intfx.cpp +++ b/src/classify/intfx.cpp @@ -17,7 +17,7 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ + *****************************************************************************/ /**---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------**/ @@ -25,7 +25,6 @@ #include "allheaders.h" #include "ccutil.h" #include "classify.h" -#include "const.h" #include "helpers.h" #include "intmatcher.h" #include "linlsq.h" @@ -56,8 +55,8 @@ void InitIntegerFX() { atan_table_mutex.Lock(); if (!atan_table_init) { for (int i = 0; i < INT_CHAR_NORM_RANGE; ++i) { - cos_table[i] = cos(i * 2 * PI / INT_CHAR_NORM_RANGE + PI); - sin_table[i] = sin(i * 2 * PI / INT_CHAR_NORM_RANGE + PI); + cos_table[i] = cos(i * 2 * M_PI / INT_CHAR_NORM_RANGE + M_PI); + sin_table[i] = sin(i * 2 * M_PI / INT_CHAR_NORM_RANGE + M_PI); } atan_table_init = true; } diff --git a/src/classify/intproto.cpp b/src/classify/intproto.cpp index 72750f88ab..6b71df2cbd 100644 --- a/src/classify/intproto.cpp +++ b/src/classify/intproto.cpp @@ -405,7 +405,7 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId, Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0, debug); - Angle *= 2.0 * PI; + Angle *= 2.0 * M_PI; Length = Proto->Length; X = Proto->X + X_SHIFT; @@ -1570,7 +1570,7 @@ void InitTableFiller (float EndPad, float SidePad, if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) { /* rising diagonal proto */ - Angle *= 2.0 * PI; + Angle *= 2.0 * M_PI; Cos = fabs(cos(Angle)); Sin = fabs(sin(Angle)); @@ -1620,7 +1620,7 @@ void InitTableFiller (float EndPad, float SidePad, Filler->Switch[2].X = Bucket8For(End.x, XS, NB); } else { /* falling diagonal proto */ - Angle *= 2.0 * PI; + Angle *= 2.0 * M_PI; Cos = fabs(cos(Angle)); Sin = fabs(sin(Angle)); @@ -1700,8 +1700,8 @@ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature, Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE; // The -PI has no significant effect here, but the value of Theta is computed // using BinaryAnglePlusPi in intfx.cpp. - Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * PI - PI); - Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * PI - PI); + Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI); + Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI); window->SetCursor(X, Y); window->DrawTo(X + Dx, Y + Dy); @@ -1767,8 +1767,8 @@ void RenderIntProto(ScrollView *window, Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE; // The -PI has no significant effect here, but the value of Theta is computed // using BinaryAnglePlusPi in intfx.cpp. - Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * PI - PI); - Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * PI - PI); + Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI); + Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI); window->SetCursor(X - Dx, Y - Dy); window->DrawTo(X + Dx, Y + Dy); diff --git a/src/classify/mfx.cpp b/src/classify/mfx.cpp index 5b1905eaf3..fbcea8a1b1 100644 --- a/src/classify/mfx.cpp +++ b/src/classify/mfx.cpp @@ -14,14 +14,13 @@ ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. - ******************************************************************************/ + *****************************************************************************/ /*---------------------------------------------------------------------------- Include Files and Type Defines ----------------------------------------------------------------------------*/ #include "mfdefs.h" #include "mfoutline.h" #include "clusttool.h" //NEEDED -#include "const.h" #include "intfx.h" #include "normalis.h" #include "params.h" @@ -42,7 +41,7 @@ double_VAR(classify_max_slope, 2.414213562, Macros ----------------------------------------------------------------------------*/ /* miscellaneous macros */ -#define NormalizeAngle(A) ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) ) +#define NormalizeAngle(A) ((((A) < 0) ? ((A) + 2 * M_PI) : (A)) / (2 * M_PI)) /*---------------------------------------------------------------------------- Private Function Prototypes diff --git a/src/classify/protos.cpp b/src/classify/protos.cpp index 0483f96e9e..5b29e9db40 100644 --- a/src/classify/protos.cpp +++ b/src/classify/protos.cpp @@ -1,5 +1,5 @@ /* -*-C-*- - ******************************************************************************** + ****************************************************************************** * * File: protos.cpp (Formerly protos.c) * Description: @@ -21,7 +21,7 @@ ** See the License for the specific language governing permissions and ** limitations under the License. * - *********************************************************************************/ + *****************************************************************************/ /*---------------------------------------------------------------------- I n c l u d e s ----------------------------------------------------------------------*/ @@ -196,7 +196,7 @@ void CopyProto(PROTO Src, PROTO Dest) { void FillABC(PROTO Proto) { float Slope, Intercept, Normalizer; - Slope = tan (Proto->Angle * 2.0 * PI); + Slope = tan(Proto->Angle * 2.0 * M_PI); Intercept = Proto->Y - Slope * Proto->X; Normalizer = 1.0 / sqrt (Slope * Slope + 1.0); Proto->A = Slope * Normalizer; diff --git a/src/classify/trainingsample.cpp b/src/classify/trainingsample.cpp index e89abad607..688de335f8 100644 --- a/src/classify/trainingsample.cpp +++ b/src/classify/trainingsample.cpp @@ -297,8 +297,8 @@ Pix* TrainingSample::RenderToPix(const UNICHARSET* unicharset) const { for (int f = 0; f < num_features_; ++f) { int start_x = features_[f].X; int start_y = kIntFeatureExtent - features_[f].Y; - double dx = cos((features_[f].Theta / 256.0) * 2.0 * PI - PI); - double dy = -sin((features_[f].Theta / 256.0) * 2.0 * PI - PI); + double dx = cos((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI); + double dy = -sin((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI); for (int i = 0; i <= 5; ++i) { int x = static_cast(start_x + dx * i); int y = static_cast(start_y + dy * i); diff --git a/src/cutil/const.h b/src/cutil/const.h index 33f8fa443c..ca00e60be6 100644 --- a/src/cutil/const.h +++ b/src/cutil/const.h @@ -16,8 +16,6 @@ /*This file contains constants which are global to the entire system*/ #define SPLINESIZE 23 // max spline parts to a line -#define PI 3.14159265359 // pi - #define EDGEPTFLAGS 4 // concavity,length etc. #endif diff --git a/src/training/commontraining.cpp b/src/training/commontraining.cpp index c244591c20..f6bb7e0e55 100644 --- a/src/training/commontraining.cpp +++ b/src/training/commontraining.cpp @@ -776,7 +776,7 @@ void Normalize ( float Intercept; float Normalizer; - Slope = tan (Values [2] * 2 * PI); + Slope = tan(Values [2] * 2 * M_PI); Intercept = Values [1] - Slope * Values [0]; Normalizer = 1 / sqrt (Slope * Slope + 1.0); diff --git a/src/training/mergenf.cpp b/src/training/mergenf.cpp index 30d9e641c8..54d1892b82 100644 --- a/src/training/mergenf.cpp +++ b/src/training/mergenf.cpp @@ -2,7 +2,6 @@ ** Filename: MergeNF.c ** Purpose: Program for merging similar nano-feature protos ** Author: Dan Johnson -** History: Wed Nov 21 09:55:23 1990, DSJ, Created. ** ** (c) Copyright Hewlett-Packard Company, 1988. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -59,8 +58,6 @@ double_VAR(training_angle_pad, 45.0, "Angle pad ..."); * Globals: none * * @return Worst possible result when matching p1 to p2. - * @note Exceptions: none - * @note History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ float CompareProtos(PROTO p1, PROTO p2) { FEATURE Feature; @@ -78,7 +75,7 @@ float CompareProtos(PROTO p1, PROTO p2) { Feature->Params[PicoFeatDir] = p1->Angle; /* convert angle to radians */ - Angle = p1->Angle * 2.0 * PI; + Angle = p1->Angle * 2.0 * M_PI; /* find distance from center of p1 to 1/2 picofeat from end */ Length = p1->Length / 2.0 - GetPicoFeatureLength () / 2.0; @@ -307,13 +304,11 @@ bool DummyFastMatch(FEATURE Feature, PROTO Proto) * Globals: none * * @return none (results are returned in BoundingBox) - * @note Exceptions: none - * @note History: Wed Nov 14 14:55:30 1990, DSJ, Created. */ void ComputePaddedBoundingBox (PROTO Proto, float TangentPad, float OrthogonalPad, FRECT *BoundingBox) { float Length = Proto->Length / 2.0 + TangentPad; - float Angle = Proto->Angle * 2.0 * PI; + float Angle = Proto->Angle * 2.0 * M_PI; float CosOfAngle = fabs(cos(Angle)); float SinOfAngle = fabs(sin(Angle)); diff --git a/src/wordrec/chop.cpp b/src/wordrec/chop.cpp index 5ff113eeb4..33faa3049b 100644 --- a/src/wordrec/chop.cpp +++ b/src/wordrec/chop.cpp @@ -1,5 +1,5 @@ /* -*-C-*- - ******************************************************************************** + ****************************************************************************** * * File: chop.cpp (Formerly chop.c) * Description: @@ -21,7 +21,7 @@ ** See the License for the specific language governing permissions and ** limitations under the License. * - *********************************************************************************/ + *****************************************************************************/ /*---------------------------------------------------------------------- I n c l u d e s @@ -102,7 +102,7 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) { if ((int) length == 0) return (0); angle = static_cast(floor(asin(CROSS (vector1, vector2) / - length) / PI * 180.0 + 0.5)); + length) / M_PI * 180.0 + 0.5)); /* Use dot product */ if (SCALAR (vector1, vector2) < 0)