From 2d102c48108cd0c5b9c50b2757af5e50270889b3 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 16 Jul 2018 12:44:30 +0200 Subject: [PATCH] Compensate for bbox lack of accuracy --- lib/cartodb/models/aggregation/aggregation-query.js | 13 ++++++++----- test/acceptance/aggregation.js | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index e7eb2ecb..4f7060c5 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -274,20 +274,23 @@ const spatialFilter = ` // * This queries are used for rendering and the_geom is omitted in the results for better performance // * If the MVT extent or tile buffer was 0 or a multiple of the resolution we could use directly // the bbox for them, but in general we need to find the nearest cell limits inside the bbox. +// * bbox coordinates can have an error in the last digites; we apply a small correction before +// applying CEIL or FLOOR to compensate for this. const sqlParams = (ctx) => ` _cdb_res AS ( SELECT ${gridResolution(ctx)} AS res, - !bbox! AS bbox + !bbox! AS bbox, + (2*2.220446049250313e-16::double precision) AS eps ), _cdb_params AS ( SELECT res, bbox, - CEIL(ST_XMIN(bbox)/res)*res AS xmin, - FLOOR(ST_XMAX(bbox)/res)*res AS xmax, - CEIL(ST_YMIN(bbox)/res)*res AS ymin, - FLOOR(ST_YMAX(bbox)/res)*res AS ymax + CEIL((ST_XMIN(bbox) - eps*ABS(ST_XMIN(bbox)))/res)*res AS xmin, + FLOOR((ST_XMAX(bbox) + eps*ABS(ST_XMAX(bbox)))/res)*res AS xmax, + CEIL((ST_YMIN(bbox) - eps*ABS(ST_YMIN(bbox)))/res)*res AS ymin, + FLOOR((ST_YMAX(bbox) + eps*ABS(ST_YMAX(bbox)))/res)*res AS ymax FROM _cdb_res ) `; diff --git a/test/acceptance/aggregation.js b/test/acceptance/aggregation.js index 73a6ec11..8fd9029f 100644 --- a/test/acceptance/aggregation.js +++ b/test/acceptance/aggregation.js @@ -2455,7 +2455,7 @@ describe('aggregation', function () { }); }); - it.skip(`for ${placement} points aggregated into corner cluster`, function (done) { + it(`for ${placement} points aggregated into corner cluster`, function (done) { // this test will fail due to !bbox! lack of accuracy if strict cell filtering is in place this.mapConfig = { version: '1.6.0',