From dbb54da18a6643a3748191ffa6939f8dd510422d Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Wed, 16 Aug 2017 12:22:03 -0700 Subject: [PATCH] Update SymbolBucket unit test to work with viewport collision detection logic. --- test/unit/data/symbol_bucket.test.js | 56 ++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/test/unit/data/symbol_bucket.test.js b/test/unit/data/symbol_bucket.test.js index 87fcf8524c5..4a0328aeea0 100644 --- a/test/unit/data/symbol_bucket.test.js +++ b/test/unit/data/symbol_bucket.test.js @@ -12,6 +12,11 @@ const GlyphAtlas = require('../../../src/symbol/glyph_atlas'); const StyleLayer = require('../../../src/style/style_layer'); const util = require('../../../src/util/util'); const featureFilter = require('../../../src/style-spec/feature_filter'); +const PrepareSymbol = require('../../../src/symbol/prepare_symbol'); +const PlaceSymbol = require('../../../src/symbol/place_symbols'); +const Transform = require('../../../src/geo/transform'); + +const mat4 = require('@mapbox/gl-matrix').mat4; // Load a point feature from fixture tile. const vt = new VectorTile(new Protobuf(fs.readFileSync(path.join(__dirname, '/../../fixtures/mbsv5-6-18-23.vector.pbf')))); @@ -20,7 +25,21 @@ const glyphs = JSON.parse(fs.readFileSync(path.join(__dirname, '/../../fixtures/ /*eslint new-cap: 0*/ const collisionBoxArray = new CollisionBoxArray(); -const collision = new CollisionTile(0, 0, 1, 1, collisionBoxArray); +const transform = new Transform(); +transform.width = 100; +transform.height = 100; +transform.cameraToCenterDistance = 100; +const labelPlaneMatrix = mat4.identity(new Float64Array(16)); +// This is a bogus projection matrix: all it does is make tile coordinates +// project to somewhere within the viewport, assuming a tile extent of 8192. +mat4.scale(labelPlaneMatrix, labelPlaneMatrix, [1 / 8192, 1 / 8192, 1]); +const collision = new CollisionTile(transform); +collision.setMatrix(labelPlaneMatrix); +const showCollisionBoxes = false; +const zoom = 0; +const pixelRatio = 1; +const tileID = 0; + const atlas = new GlyphAtlas(); for (const id in glyphs) { glyphs[id].bitmap = true; @@ -51,39 +70,38 @@ test('SymbolBucket', (t) => { const options = {iconDependencies: {}, glyphDependencies: {}}; // add feature from bucket A - const a = collision.grid.keys.length; + const a = collision.grid.keysLength(); bucketA.populate([{feature}], options); - bucketA.prepare(stacks, {}); - bucketA.place(collision); + PrepareSymbol.prepare(bucketA, stacks, {}); + PlaceSymbol.place(bucketA, collision, showCollisionBoxes, zoom, pixelRatio, labelPlaneMatrix, tileID, collisionBoxArray); - const b = collision.grid.keys.length; + const b = collision.grid.keysLength(); t.notEqual(a, b, 'places feature'); // add same feature from bucket B - const a2 = collision.grid.keys.length; + const a2 = collision.grid.keysLength(); bucketB.populate([{feature}], options); - bucketB.prepare(stacks, {}); - bucketB.place(collision); - const b2 = collision.grid.keys.length; - t.equal(a2, b2, 'detects collision and does not place feature'); + PrepareSymbol.prepare(bucketB, stacks, {}); + PlaceSymbol.place(bucketB, collision, showCollisionBoxes, zoom, pixelRatio, labelPlaneMatrix, tileID, collisionBoxArray); + const b2 = collision.grid.keysLength(); + t.equal(b2, a2, 'detects collision and does not place feature'); t.end(); }); test('SymbolBucket integer overflow', (t) => { t.stub(util, 'warnOnce'); - t.stub(SymbolBucket, 'MAX_INSTANCES').value(5); + t.stub(SymbolBucket, 'MAX_GLYPHS').value(5); const bucket = bucketSetup(); const options = {iconDependencies: {}, glyphDependencies: {}}; bucket.populate([{feature}], options); - bucket.prepare(stacks, {}); - bucket.place(collision); + PrepareSymbol.prepare(bucket, stacks, {}); + PlaceSymbol.place(bucket, collision, showCollisionBoxes, zoom, pixelRatio, labelPlaneMatrix, tileID, collisionBoxArray); - t.ok(util.warnOnce.calledTwice); - t.ok(util.warnOnce.getCall(0).calledWithMatch(/Too many (symbols|glyphs) being rendered in a tile./)); - t.ok(util.warnOnce.getCall(1).calledWithMatch(/Too many (symbols|glyphs) being rendered in a tile./)); + t.ok(util.warnOnce.calledOnce); + t.ok(util.warnOnce.getCall(0).calledWithMatch(/Too many glyphs being rendered in a tile./)); t.end(); }); @@ -92,9 +110,9 @@ test('SymbolBucket redo placement', (t) => { const options = {iconDependencies: {}, glyphDependencies: {}}; bucket.populate([{feature}], options); - bucket.prepare(stacks, {}); - bucket.place(collision); - bucket.place(collision); + PrepareSymbol.prepare(bucket, stacks, {}); + PlaceSymbol.place(bucket, collision, showCollisionBoxes, zoom, pixelRatio, labelPlaneMatrix, tileID, collisionBoxArray); + PlaceSymbol.place(bucket, collision, showCollisionBoxes, zoom, pixelRatio, labelPlaneMatrix, tileID, collisionBoxArray); t.end(); });