From 93b6438cea61dc4849c9157923954f91c8f2f54d Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Tue, 21 Jun 2016 16:50:06 +0200 Subject: [PATCH] Fix fromTop and fromLeft calculation --- src/extractor/raster_source.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/extractor/raster_source.cpp b/src/extractor/raster_source.cpp index 66a50792d..33b765253 100644 --- a/src/extractor/raster_source.cpp +++ b/src/extractor/raster_source.cpp @@ -54,7 +54,9 @@ RasterDatum RasterSource::GetRasterInterpolate(const int lon, const int lat) con } const auto xthP = (lon - xmin) / xstep; - const auto ythP = (ymax - lat) / ystep; + const auto ythP = + (ymax - lat) / + ystep; // the raster texture uses a different coordinate system with y pointing downwards const std::size_t top = static_cast(fmax(floor(ythP), 0)); const std::size_t bottom = static_cast(fmin(ceil(ythP), height - 1)); @@ -62,8 +64,8 @@ RasterDatum RasterSource::GetRasterInterpolate(const int lon, const int lat) con const std::size_t right = static_cast(fmin(ceil(xthP), width - 1)); // Calculate distances from corners for bilinear interpolation - const float fromLeft = (lon - left * xstep + xmin) / xstep; - const float fromTop = (ymax - top * ystep - lat) / ystep; + const float fromLeft = xthP - left; // this is the fraction part of xthP + const float fromTop = ythP - top; // this is the fraction part of ythP const float fromRight = 1 - fromLeft; const float fromBottom = 1 - fromTop;