[geos-commits] [SCM] GEOS branch master updated. d23eb6ca3db2d5d2b4b3ab4515dc41a69a875e47

git at osgeo.org git at osgeo.org
Thu Apr 30 14:19:18 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  d23eb6ca3db2d5d2b4b3ab4515dc41a69a875e47 (commit)
      from  dc33ea4d5266da135e07204701efa39db37653fc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d23eb6ca3db2d5d2b4b3ab4515dc41a69a875e47
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Apr 30 14:18:43 2020 -0700

    Remove DoubleBits in favour of exp2 and frexp
    Closes #252, Closes #317

diff --git a/include/geos/index/quadtree/DoubleBits.h b/include/geos/index/quadtree/DoubleBits.h
deleted file mode 100644
index 9a00d90..0000000
--- a/include/geos/index/quadtree/DoubleBits.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2006 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- **********************************************************************
- *
- * Last port: index/quadtree/DoubleBits.java rev. 1.7 (JTS-1.16)
- *
- **********************************************************************/
-
-#ifndef GEOS_IDX_QUADTREE_DOUBLEBITS_H
-#define GEOS_IDX_QUADTREE_DOUBLEBITS_H
-
-#include <geos/export.h>
-#include <geos/constants.h> // for int64
-
-#include <string>
-
-namespace geos {
-namespace index { // geos::index
-namespace quadtree { // geos::index::quadtree
-
-
-/** \brief
- * DoubleBits manipulates Double numbers
- * by using bit manipulation and bit-field extraction.
- *
- * For some operations (such as determining the exponent)
- * this is more accurate than using mathematical operations
- * (which suffer from round-off error).
- *
- * The algorithms and constants in this class
- * apply only to IEEE-754 double-precision floating point format.
- *
- */
-class GEOS_DLL DoubleBits {
-
-public:
-
-    static const int EXPONENT_BIAS = 1023;
-
-    static double powerOf2(int exp);
-
-    static int exponent(double d);
-
-    static double truncateToPowerOfTwo(double d);
-
-    static std::string toBinaryString(double d);
-
-    static double maximumCommonMantissa(double d1, double d2);
-
-    DoubleBits(double nx);
-
-    double getDouble() const;
-
-    /// Determines the exponent for the number
-    int64 biasedExponent() const;
-
-    /// Determines the exponent for the number
-    int getExponent() const;
-
-    void zeroLowerBits(int nBits);
-
-    int getBit(int i) const;
-
-    /** \brief
-     * This computes the number of common most-significant bits in
-     * the mantissa.
-     *
-     * It does not count the hidden bit, which is always 1.
-     * It does not determine whether the numbers have the same exponent;
-     * if they do not, the value computed by this function is meaningless.
-     *
-     * @param db
-     *
-     * @return the number of common most-significant mantissa bits
-     */
-    int numCommonMantissaBits(const DoubleBits& db) const;
-
-    /// A representation of the Double bits formatted for easy readability
-    std::string toString() const;
-
-private:
-
-    double x;
-
-    int64 xBits;
-};
-
-} // namespace geos::index::quadtree
-} // namespace geos::index
-} // namespace geos
-
-#endif // GEOS_IDX_QUADTREE_DOUBLEBITS_H
diff --git a/include/geos/index/quadtree/Makefile.am b/include/geos/index/quadtree/Makefile.am
index d3f2571..04ace02 100644
--- a/include/geos/index/quadtree/Makefile.am
+++ b/include/geos/index/quadtree/Makefile.am
@@ -1,14 +1,13 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
-SUBDIRS = 
+SUBDIRS =
 
-EXTRA_DIST = 
+EXTRA_DIST =
 
 geosdir = $(includedir)/geos/index/quadtree
 
 geos_HEADERS = \
-    DoubleBits.h \
     IntervalSize.h \
     Key.h \
     NodeBase.h \
diff --git a/src/index/bintree/Key.cpp b/src/index/bintree/Key.cpp
index 2a35d0f..7bb24e4 100644
--- a/src/index/bintree/Key.cpp
+++ b/src/index/bintree/Key.cpp
@@ -15,7 +15,6 @@
 
 #include <geos/index/bintree/Key.h>
 #include <geos/index/bintree/Interval.h>
-#include <geos/index/quadtree/DoubleBits.h>
 
 #include <cmath>
 
@@ -26,10 +25,9 @@ namespace bintree { // geos.index.bintree
 int
 Key::computeLevel(Interval* newInterval)
 {
-    using geos::index::quadtree::DoubleBits;
     double dx = newInterval->getWidth();
-    //int level = BinaryPower.exponent(dx) + 1;
-    int level = DoubleBits::exponent(dx) + 1;
+    int level;
+    frexp(dx, &level);
     return level;
 }
 
@@ -85,10 +83,7 @@ Key::computeKey(Interval* itemInterval)
 void
 Key::computeInterval(int p_level, Interval* itemInterval)
 {
-    using geos::index::quadtree::DoubleBits;
-
-    double size = DoubleBits::powerOf2(p_level);
-    //double size = pow2.power(p_level);
+    double size = exp2(p_level);
     pt = std::floor(itemInterval->getMin() / size) * size;
     interval->init(pt, pt + size);
 }
diff --git a/src/index/quadtree/DoubleBits.cpp b/src/index/quadtree/DoubleBits.cpp
deleted file mode 100644
index 336d411..0000000
--- a/src/index/quadtree/DoubleBits.cpp
+++ /dev/null
@@ -1,185 +0,0 @@
-/**********************************************************************
- *
- * GEOS - Geometry Engine Open Source
- * http://geos.osgeo.org
- *
- * Copyright (C) 2006 Refractions Research Inc.
- * Copyright (C) 2001-2002 Vivid Solutions Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU Lesser General Public Licence as published
- * by the Free Software Foundation.
- * See the COPYING file for more information.
- *
- **********************************************************************
- *
- * Last port: index/quadtree/DoubleBits.java rev. 1.7 (JTS-1.16)
- *
- **********************************************************************/
-
-#include <geos/index/quadtree/DoubleBits.h>
-#include <geos/util/IllegalArgumentException.h>
-
-#include <string>
-#include <cstring>
-#include <bitset>
-
-#if __STDC_IEC_559__
-#define ASSUME_IEEE_DOUBLE 1
-#else
-#define ASSUME_IEEE_DOUBLE 0
-#endif
-
-#if ! ASSUME_IEEE_DOUBLE
-#include <cmath>
-#endif
-
-namespace geos {
-namespace index { // geos.index
-namespace quadtree { // geos.index.quadtree
-
-using namespace std;
-
-double
-DoubleBits::powerOf2(int exp)
-{
-    if(exp > 1023 || exp < -1022) {
-        throw util::IllegalArgumentException("Exponent out of bounds");
-    }
-#if ASSUME_IEEE_DOUBLE
-    int64 expBias = exp + EXPONENT_BIAS;
-    int64 bits = expBias << 52;
-    double ret;
-    memcpy(&ret, &bits, sizeof(int64));
-    return ret;
-#else
-    return pow(2.0, exp);
-#endif
-}
-
-int
-DoubleBits::exponent(double d)
-{
-    DoubleBits db(d);
-    return db.getExponent();
-}
-
-double
-DoubleBits::truncateToPowerOfTwo(double d)
-{
-    DoubleBits db(d);
-    db.zeroLowerBits(52);
-    return db.getDouble();
-}
-
-string
-DoubleBits::toBinaryString(double d)
-{
-    DoubleBits db(d);
-    return db.toString();
-}
-
-double
-DoubleBits::maximumCommonMantissa(double d1, double d2)
-{
-    if(d1 == 0.0 || d2 == 0.0) {
-        return 0.0;
-    }
-    DoubleBits db1(d1);
-    DoubleBits db2(d2);
-    if(db1.getExponent() != db2.getExponent()) {
-        return 0.0;
-    }
-    int maxCommon = db1.numCommonMantissaBits(db2);
-    db1.zeroLowerBits(64 - (12 + maxCommon));
-    return db1.getDouble();
-}
-
-/*public*/
-DoubleBits::DoubleBits(double nx)
-{
-#if ASSUME_IEEE_DOUBLE
-    memcpy(&xBits, &nx, sizeof(double));
-#endif
-    x = nx;
-}
-
-/*public*/
-double
-DoubleBits::getDouble() const
-{
-    return x;
-}
-
-/*public*/
-int64
-DoubleBits::biasedExponent() const
-{
-    int64 signExp = xBits >> 52;
-    int64 exp = signExp & 0x07ff;
-    //cerr<<"xBits:"<<xBits<<" signExp:"<<signExp<<" exp:"<<exp<<endl;
-    return exp;
-}
-
-/*public*/
-int
-DoubleBits::getExponent() const
-{
-#if ASSUME_IEEE_DOUBLE
-    return static_cast<int>(biasedExponent() - EXPONENT_BIAS);
-#else
-    if(x <= 0) {
-        return 0;    // EDOM || ERANGE
-    }
-    return (int)((log(x) / log(2.0)) + (x < 1 ? -0.9 : 0.00000000001));
-#endif
-}
-
-/*public*/
-void
-DoubleBits::zeroLowerBits(int nBits)
-{
-    long invMask = (1L << nBits) - 1L;
-    long mask = ~invMask;
-    xBits &= mask;
-}
-
-/*public*/
-int
-DoubleBits::getBit(int i) const
-{
-    long mask = (1L << i);
-    return (xBits & mask) != 0 ? 1 : 0;
-}
-
-/*public*/
-int
-DoubleBits::numCommonMantissaBits(const DoubleBits& db) const
-{
-    for(int i = 0; i < 52; i++) {
-        if(getBit(i) != db.getBit(i)) {
-            return i;
-        }
-    }
-    return 52;
-}
-
-/*public*/
-string
-DoubleBits::toString() const
-{
-    int64 bit;
-    memcpy(&bit, &x, sizeof(x));
-    string bitStr = bitset<64>(bit).to_string();
-
-    string str = bitStr.substr(0, 1) + "  "
-        + bitStr.substr(1, 11) + "(" + std::to_string(getExponent()) + ") "
-        + bitStr.substr(12)
-        + " [ " + std::to_string(x) + " ]";
-
-    return str;
-}
-
-} // namespace geos.index.quadtree
-} // namespace geos.index
-} // namespace geos
diff --git a/src/index/quadtree/IntervalSize.cpp b/src/index/quadtree/IntervalSize.cpp
index 54d5e5c..68feb03 100644
--- a/src/index/quadtree/IntervalSize.cpp
+++ b/src/index/quadtree/IntervalSize.cpp
@@ -18,7 +18,6 @@
  **********************************************************************/
 
 #include <geos/index/quadtree/IntervalSize.h>
-#include <geos/index/quadtree/DoubleBits.h>
 
 #include <algorithm>
 #include <cmath>
@@ -40,7 +39,9 @@ IntervalSize::isZeroWidth(double mn, double mx)
 
     double maxAbs = max(fabs(mn), fabs(mx));
     double scaledInterval = width / maxAbs;
-    int level = DoubleBits::exponent(scaledInterval);
+    int level;
+    frexp(scaledInterval, &level);
+    level -= 1;
     return level <= MIN_BINARY_EXPONENT;
 }
 
diff --git a/src/index/quadtree/Key.cpp b/src/index/quadtree/Key.cpp
index 25c830a..f3ee2f8 100644
--- a/src/index/quadtree/Key.cpp
+++ b/src/index/quadtree/Key.cpp
@@ -19,7 +19,6 @@
  **********************************************************************/
 
 #include <geos/index/quadtree/Key.h>
-#include <geos/index/quadtree/DoubleBits.h>
 #include <geos/geom/Envelope.h>
 #include <geos/geom/Coordinate.h>
 
@@ -46,7 +45,8 @@ Key::computeQuadLevel(const Envelope& env)
     double dx = env.getWidth();
     double dy = env.getHeight();
     double dMax = dx > dy ? dx : dy;
-    int level = DoubleBits::exponent(dMax) + 1;
+    int level;
+    frexp(dMax, &level);
 #if GEOS_DEBUG
     std::cerr << "Maxdelta:" << dMax << " exponent:" << (level - 1) << std::endl;
 #endif
@@ -113,8 +113,7 @@ Key::computeKey(const Envelope& itemEnv)
 void
 Key::computeKey(int p_level, const Envelope& itemEnv)
 {
-    double quadSize = DoubleBits::powerOf2(p_level);
-    //double quadSize=pow2.power(level);
+    double quadSize = exp2(p_level);
     pt.x = std::floor(itemEnv.getMinX() / quadSize) * quadSize;
     pt.y = std::floor(itemEnv.getMinY() / quadSize) * quadSize;
     env.init(pt.x, pt.x + quadSize, pt.y, pt.y + quadSize);
diff --git a/src/index/quadtree/Makefile.am b/src/index/quadtree/Makefile.am
index cc77945..98d5123 100644
--- a/src/index/quadtree/Makefile.am
+++ b/src/index/quadtree/Makefile.am
@@ -1,15 +1,14 @@
 #
-# This file is part of project GEOS (http://trac.osgeo.org/geos/) 
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
 #
 noinst_LTLIBRARIES = libindexquadtree.la
 
-AM_CPPFLAGS = -I$(top_srcdir)/include 
+AM_CPPFLAGS = -I$(top_srcdir)/include
 
 libindexquadtree_la_SOURCES = \
-    DoubleBits.cpp \
     IntervalSize.cpp \
     Quadtree.cpp \
     Key.cpp \
     Node.cpp \
     NodeBase.cpp \
-    Root.cpp 
+    Root.cpp
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index cef4374..50b2af7 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -145,7 +145,6 @@ geos_unit_SOURCES = \
 	geom/prep/PreparedGeometry/touchesTest.cpp \
 	geom/TriangleTest.cpp \
 	geom/util/GeometryExtracterTest.cpp \
-	index/quadtree/DoubleBitsTest.cpp \
 	index/strtree/SIRtreeTest.cpp \
 	io/ByteOrderValuesTest.cpp \
 	io/WKBReaderTest.cpp \
diff --git a/tests/unit/index/quadtree/DoubleBitsTest.cpp b/tests/unit/index/quadtree/DoubleBitsTest.cpp
deleted file mode 100644
index f33a128..0000000
--- a/tests/unit/index/quadtree/DoubleBitsTest.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Test Suite for geos::index::quadtree::DoubleBits class.
-
-#include <tut/tut.hpp>
-// geos
-#include <geos/index/quadtree/DoubleBits.h>
-
-using namespace geos::index::quadtree;
-
-namespace tut {
-// dummy data, not used
-struct test_doublebits_data {};
-
-typedef test_group<test_doublebits_data> group;
-typedef group::object object;
-
-group test_doublebits_group("geos::index::quadtree::DoubleBits");
-
-//
-// Test Cases
-//
-
-// 1 - Test exponent()
-template<>
-template<>
-void object::test<1>
-()
-{
-    ensure_equals(DoubleBits::exponent(-1), 0);
-    ensure_equals(DoubleBits::exponent(8.0), 3);
-    ensure_equals(DoubleBits::exponent(128.0), 7);
-}
-
-// 2 - Test toString()
-template<>
-template<>
-void object::test<2>
-()
-{
-    ensure_equals(DoubleBits(-1).toString(),
-        "1  01111111111(0) 0000000000000000000000000000000000000000000000000000 [ -1.000000 ]");
-    ensure_equals(DoubleBits(8.0).toString(),
-        "0  10000000010(3) 0000000000000000000000000000000000000000000000000000 [ 8.000000 ]");
-    ensure_equals(DoubleBits(128.0).toString(),
-        "0  10000000110(7) 0000000000000000000000000000000000000000000000000000 [ 128.000000 ]");
-}
-
-} // namespace tut
-

-----------------------------------------------------------------------

Summary of changes:
 include/geos/index/quadtree/DoubleBits.h     | 102 ---------------
 include/geos/index/quadtree/Makefile.am      |   7 +-
 src/index/bintree/Key.cpp                    |  11 +-
 src/index/quadtree/DoubleBits.cpp            | 185 ---------------------------
 src/index/quadtree/IntervalSize.cpp          |   5 +-
 src/index/quadtree/Key.cpp                   |   7 +-
 src/index/quadtree/Makefile.am               |   7 +-
 tests/unit/Makefile.am                       |   1 -
 tests/unit/index/quadtree/DoubleBitsTest.cpp |  49 -------
 9 files changed, 15 insertions(+), 359 deletions(-)
 delete mode 100644 include/geos/index/quadtree/DoubleBits.h
 delete mode 100644 src/index/quadtree/DoubleBits.cpp
 delete mode 100644 tests/unit/index/quadtree/DoubleBitsTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list