[Liblas-commits] hg-main-tree: fix off-by-one

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Mar 24 15:12:28 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/fdb971f09db1
changeset: 432:fdb971f09db1
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Thu Mar 24 12:12:21 2011 -0700
description:
fix off-by-one

diffstat:

 src/drivers/faux/Reader.cpp  |   7 +++--
 test/unit/FauxReaderTest.cpp |  53 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 53 insertions(+), 7 deletions(-)

diffs (88 lines):

diff -r acddf79a6421 -r fdb971f09db1 src/drivers/faux/Reader.cpp
--- a/src/drivers/faux/Reader.cpp	Thu Mar 24 11:19:10 2011 -0700
+++ b/src/drivers/faux/Reader.cpp	Thu Mar 24 12:12:21 2011 -0700
@@ -143,9 +143,10 @@
     const double minZ = dims[2].getMinimum();
     const double maxZ = dims[2].getMaximum();
     
-    const double delX = (maxX - minX) / header.getNumPoints();
-    const double delY = (maxY - minY) / header.getNumPoints();
-    const double delZ = (maxZ - minZ) / header.getNumPoints();
+    const double numDeltas = (double)header.getNumPoints() - 1.0;
+    const double delX = (maxX - minX) / numDeltas;
+    const double delY = (maxY - minY) / numDeltas;
+    const double delZ = (maxZ - minZ) / numDeltas;
 
     const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
     const int offsetX = schema.getDimensionIndex(Dimension::Field_X);
diff -r acddf79a6421 -r fdb971f09db1 test/unit/FauxReaderTest.cpp
--- a/test/unit/FauxReaderTest.cpp	Thu Mar 24 11:19:10 2011 -0700
+++ b/test/unit/FauxReaderTest.cpp	Thu Mar 24 12:12:21 2011 -0700
@@ -221,8 +221,53 @@
     return;
 }
 
+BOOST_AUTO_TEST_CASE(test_ramp_mode_1)
+{
+    Bounds<double> bounds(0,0,0,4,4,4);
+    libpc::drivers::faux::Reader reader(bounds, 2, libpc::drivers::faux::Reader::Ramp);
 
-BOOST_AUTO_TEST_CASE(test_ramp_mode)
+    const Schema& schema = reader.getHeader().getSchema();
+    SchemaLayout layout(schema);
+
+    PointBuffer data(layout, 2);
+
+    SequentialIterator* iter = reader.createSequentialIterator();
+    boost::uint32_t numRead = iter->read(data);
+
+    BOOST_CHECK(numRead == 2);
+
+    const int offsetX = schema.getDimensionIndex(Dimension::Field_X);
+    const int offsetY = schema.getDimensionIndex(Dimension::Field_Y);
+    const int offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
+    const int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
+
+    const double x0 = data.getField<double>(0, offsetX);
+    const double y0 = data.getField<double>(0, offsetY);
+    const double z0 = data.getField<double>(0, offsetZ);
+    const boost::uint64_t t0 = data.getField<boost::uint64_t>(0, offsetT);
+
+    const double x1 = data.getField<double>(1, offsetX);
+    const double y1 = data.getField<double>(1, offsetY);
+    const double z1 = data.getField<double>(1, offsetZ);
+    const boost::uint64_t t1 = data.getField<boost::uint64_t>(1, offsetT);
+
+    BOOST_CHECK(Utils::compare_approx<double>(x0, 0, 0.000001));
+    BOOST_CHECK(Utils::compare_approx<double>(y0, 0, 0.000001));
+    BOOST_CHECK(Utils::compare_approx<double>(z0, 0, 0.000001));
+    BOOST_CHECK(t0 == 0);
+
+    BOOST_CHECK(Utils::compare_approx<double>(x1, 4, 0.000001));
+    BOOST_CHECK(Utils::compare_approx<double>(y1, 4, 0.000001));
+    BOOST_CHECK(Utils::compare_approx<double>(z1, 4, 0.000001));
+    BOOST_CHECK(t1 == 1);
+
+    delete iter;
+
+    return;
+}
+
+
+BOOST_AUTO_TEST_CASE(test_ramp_mode_2)
 {
     Bounds<double> bounds(1.0, 2.0, 3.0, 101.0, 152.0, 203.0);
     libpc::drivers::faux::Reader reader(bounds, 750, libpc::drivers::faux::Reader::Ramp);
@@ -242,9 +287,9 @@
     int offsetZ = schema.getDimensionIndex(Dimension::Field_Z);
     int offsetT = schema.getDimensionIndex(Dimension::Field_Time);
 
-    double delX = (101.0 - 1.0) / 750.0;
-    double delY = (152.0 - 2.0) / 750.0;
-    double delZ = (203.0 - 3.0) / 750.0;
+    double delX = (101.0 - 1.0) / (750.0 - 1.0);
+    double delY = (152.0 - 2.0) / (750.0 - 1.0);
+    double delZ = (203.0 - 3.0) / (750.0 - 1.0);
 
     for (boost::uint32_t i=0; i<numRead; i++)
     {


More information about the Liblas-commits mailing list