From fccd8be27cbac8664059df0e466f3d849038943d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 8 Jul 2014 14:46:02 -0700 Subject: [PATCH] fix searchbox calculation If the anchor is within the glyph's box the previous approach worked fine, but if the anchor is outside, then the searchbox was too small. --- js/text/collision.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/text/collision.js b/js/text/collision.js index 9b4f52e7426..37e284726e6 100644 --- a/js/text/collision.js +++ b/js/text/collision.js @@ -68,10 +68,10 @@ Collision.prototype.getPlacementScale = function(glyphs, minPlacementScale) { // Compute the scaled bounding box of the unrotated glyph var searchBox = [ - anchor.x + bbox.x1 / minScale, - anchor.y + bbox.y1 / minScale, - anchor.x + bbox.x2 / minScale, - anchor.y + bbox.y2 / minScale]; + anchor.x + Math.min(bbox.x1 / minScale, bbox.x1 / maxScale), + anchor.y + Math.min(bbox.y1 / minScale, bbox.y1 / maxScale), + anchor.x + Math.max(bbox.x2 / minScale, bbox.x2 / maxScale), + anchor.y + Math.max(bbox.y2 / minScale, bbox.y2 / maxScale)]; var blocking = this.hTree.search(searchBox).concat(this.cTree.search(searchBox)); @@ -196,12 +196,12 @@ Collision.prototype.insert = function(glyphs, anchor, placementScale, placementR var minScale = Math.max(placementScale, glyph.minScale); + var maxScale = glyph.maxScale || Infinity; var bounds = [ - anchor.x + bbox.x1 / minScale, - anchor.y + bbox.y1 / minScale, - anchor.x + bbox.x2 / minScale, - anchor.y + bbox.y2 / minScale - ]; + anchor.x + Math.min(bbox.x1 / minScale, bbox.x1 / maxScale), + anchor.y + Math.min(bbox.y1 / minScale, bbox.y1 / maxScale), + anchor.x + Math.max(bbox.x2 / minScale, bbox.x2 / maxScale), + anchor.y + Math.max(bbox.y2 / minScale, bbox.y2 / maxScale)]; bounds.anchor = anchor; bounds.box = glyph.box;