Skip to content

Commit

Permalink
fix searchbox calculation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ansis committed Jul 8, 2014
1 parent 2f179fb commit fccd8be
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions js/text/collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fccd8be

Please sign in to comment.