Skip to content

Commit

Permalink
Merge pull request #1727 from stweil/pi
Browse files Browse the repository at this point in the history
Replace macro PI by macro M_PI
  • Loading branch information
zdenop authored Jul 2, 2018
2 parents c323312 + f7b6189 commit a0291c7
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/api/baseapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(rot_theta + 0.5);
(*block_orientation)[i] = num_rotations;
Expand Down
4 changes: 2 additions & 2 deletions src/classify/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/classify/clusttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion src/classify/fpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/classify/intfeaturespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(y), static_cast<double>(x)) + PI;
angle *= kIntFeatureExtent / (2.0 * PI);
double angle = atan2(static_cast<double>(y), static_cast<double>(x)) + M_PI;
angle *= kIntFeatureExtent / (2.0 * M_PI);
feature.Theta = static_cast<uint8_t>(angle + 0.5);
index = Index(feature);
if (index < 0) {
Expand Down
7 changes: 3 additions & 4 deletions src/classify/intfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
** 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 "intfx.h"
#include "allheaders.h"
#include "ccutil.h"
#include "classify.h"
#include "const.h"
#include "helpers.h"
#include "intmatcher.h"
#include "linlsq.h"
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/classify/intproto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/classify/mfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/classify/protos.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -*-C-*-
********************************************************************************
******************************************************************************
*
* File: protos.cpp (Formerly protos.c)
* Description:
Expand All @@ -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
----------------------------------------------------------------------*/
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/classify/trainingsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(start_x + dx * i);
int y = static_cast<int>(start_y + dy * i);
Expand Down
2 changes: 0 additions & 2 deletions src/cutil/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/training/commontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 2 additions & 7 deletions src/training/mergenf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions src/wordrec/chop.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -*-C-*-
********************************************************************************
******************************************************************************
*
* File: chop.cpp (Formerly chop.c)
* Description:
Expand All @@ -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
Expand Down Expand Up @@ -102,7 +102,7 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) {
if ((int) length == 0)
return (0);
angle = static_cast<int>(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)
Expand Down

0 comments on commit a0291c7

Please sign in to comment.