Skip to content

Commit

Permalink
Rename geos::M_PI to less intrusive MATH_PI (that don't collide with …
Browse files Browse the repository at this point in the history
…standard <cmath> name
  • Loading branch information
Marian Krivos authored and dbaston committed Jan 14, 2020
1 parent a096c83 commit 089f877
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion doc/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ do_all()
geoms->push_back(create_rectangle(-5, -5, 10, 10)); // a square
geoms->push_back(create_rectangle(-5, -5, 10, 20)); // a rectangle
// The upper-right quarter of a vertical ellipse
geoms->push_back(create_arc(0, 0, 10, 20, 0, M_PI / 2));
geoms->push_back(create_arc(0, 0, 10, 20, 0, MATH_PI / 2));
geoms->push_back(create_sinestar(10, 10, 100, 5, 2).release()); // a sine star
#endif

Expand Down
5 changes: 1 addition & 4 deletions include/geos/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ typedef __int64 int64;
#include <cinttypes>


#ifdef M_PI
#undef M_PI
#endif
typedef int64_t int64;

namespace geos {

constexpr double M_PI = 3.14159265358979323846;
constexpr double MATH_PI = 3.14159265358979323846;



Expand Down
4 changes: 2 additions & 2 deletions src/geom/util/SineStarFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ SineStarFactory::createSineStar() const

// the angle for the current arm - in [0,2Pi]
// (each arm is a complete sine wave cycle)
double armAng = 2 * M_PI * armAngFrac;
double armAng = 2 * MATH_PI * armAngFrac;
// the current length of the arm
double armLenFrac = (cos(armAng) + 1.0) / 2.0;

// the current radius of the curve (core + arm)
double curveRadius = insideRadius + armMaxLen * armLenFrac;

// the current angle of the curve
double ang = i * (2 * M_PI / nPts);
double ang = i * (2 * MATH_PI / nPts);
double x = curveRadius * cos(ang) + centreX;
double y = curveRadius * sin(ang) + centreY;
pts[iPt++] = coord(x, y);
Expand Down
2 changes: 1 addition & 1 deletion src/operation/buffer/BufferParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ BufferParameters::setQuadrantSegments(int quadSegs)
double
BufferParameters::bufferDistanceError(int quadSegs)
{
double alpha = M_PI / 2.0 / quadSegs;
double alpha = MATH_PI / 2.0 / quadSegs;
return 1 - cos(alpha / 2.0);
}

Expand Down
8 changes: 4 additions & 4 deletions src/util/GeometricShapeFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ GeometricShapeFactory::createArc(double startAng, double angExtent)
env.reset();

double angSize = angExtent;
if(angSize <= 0.0 || angSize > 2 * M_PI) {
angSize = 2 * M_PI;
if(angSize <= 0.0 || angSize > 2 * MATH_PI) {
angSize = 2 * MATH_PI;
}
double angInc = angSize / (nPts - 1);

Expand Down Expand Up @@ -191,8 +191,8 @@ GeometricShapeFactory::createArcPolygon(double startAng, double angExtent)
env.reset();

double angSize = angExtent;
if(angSize <= 0.0 || angSize > 2 * M_PI) {
angSize = 2 * M_PI;
if(angSize <= 0.0 || angSize > 2 * MATH_PI) {
angSize = 2 * MATH_PI;
}
double angInc = angSize / (nPts - 1);

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/capi/GEOSDistanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ random_polygon(double x, double y, double r, size_t num_points)


for(size_t i = 0; i < num_points; i++) {
angle[i] = 2 * geos::M_PI * std::rand() / RAND_MAX;
angle[i] = 2 * geos::MATH_PI * std::rand() / RAND_MAX;
radius[i] = r * std::rand() / RAND_MAX;
}

Expand Down

0 comments on commit 089f877

Please sign in to comment.