Commit 05ae13d4 authored by Mateusz Łoskot's avatar Mateusz Łoskot

Avoid use of internal geos/util/math.h

Copy java_math_round geos/util/math.cpp to xmltester.cpp.
Declared functions are internal to the library
and not included in GEOS shared library exports.

Fixes #831
parent c8053dd2
Pipeline #7847340 passed with stage
in 21 minutes and 49 seconds
/**********************************************************************
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
......@@ -39,7 +39,6 @@
#include <geos/operation/buffer/BufferOp.h>
#include <geos/util.h>
#include <geos/util/Interrupt.h>
#include <geos/util/math.h>
//#include <geos/geomgraph.h>
#include <geos/io/WKBReader.h>
#include <geos/io/WKBWriter.h>
......@@ -88,6 +87,34 @@ using std::runtime_error;
namespace {
// Asymmetric Rounding Algorithm - equivalent to Java Math.round()
// Copy from geos/util/math.cpp
double java_math_round(double val)
{
double n;
double f = std::fabs(std::modf(val, &n));
if (val >= 0)
{
if (f < 0.5) {
return std::floor(val);
} else if (f > 0.5) {
return std::ceil(val);
} else {
return (n + 1.0);
}
} else {
if (f < 0.5) {
return std::ceil(val);
} else if (f > 0.5) {
return std::floor(val);
} else {
return n;
}
}
} // java_math_round
// a utility function defining a very simple method to indent a line of text
const char * getIndent( unsigned int numIndents )
{
......@@ -335,7 +362,7 @@ XMLTester::printTest(bool success, const std::string& expected_result, const std
std::cout << " test" << testCount << ": "
<< opSignature;
std::cout << ": " << (success?"ok.":"failed.");
std::cout << " (" << std::setprecision(15) << geos::util::round(prof.getTot()/1000) << " ms)" << std::endl;
std::cout << " (" << std::setprecision(15) << java_math_round(prof.getTot()/1000) << " ms)" << std::endl;
std::cout << "\tDescription: " << curr_case_desc << std::endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment