From 1840f5b15218c7ffdf592f2020bd6731be199e12 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sun, 6 Nov 2016 10:33:51 +0100 Subject: [PATCH] Improve hint marker positioning A pixel up, down, left or right _is_ visible. Using `Math.round` goes to the most expected pixel. Previously, markers many times appeared to be slightly too close to the top of elements, rather than at the center. --- extension/lib/markable-elements.coffee | 8 ++++---- extension/lib/marker.coffee | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extension/lib/markable-elements.coffee b/extension/lib/markable-elements.coffee index 63adf68..b648136 100644 --- a/extension/lib/markable-elements.coffee +++ b/extension/lib/markable-elements.coffee @@ -177,14 +177,14 @@ getElementShape = (elementData, tryRight, rects = null) -> offset = null if rects.length == 1 lefts = boxQuads - .map(({bounds}) -> Math.floor(bounds.left)) - .filter((left) -> left >= Math.floor(nonCoveredPointRect.left)) + .map(({bounds}) -> Math.round(bounds.left)) + .filter((left) -> left >= Math.round(nonCoveredPointRect.left)) offset = if lefts.length == 0 then null else Math.min(lefts...) else {bounds: {left}} = boxQuads[Math.min(nonCoveredPointRect.index, boxQuads.length - 1)] offset = Math.max(nonCoveredPointRect.left, left) - result.textOffset = Math.floor(offset - nonCoveredPointRect.left) if offset? + result.textOffset = Math.round(offset - nonCoveredPointRect.left) if offset? return result @@ -209,7 +209,7 @@ getFirstNonCoveredPoint = (elementData, elementRect, tryRight) -> {left, top, bottom, height} = elementRect return tryPoint( elementData, elementRect, - left, +1, Math.floor(top + height / 2), 0, tryRight + left, +1, Math.round(top + height / 2), 0, tryRight ) # Tries a point `(x + dx, y + dy)`. Returns `(x, y)` (and the frame offset) if diff --git a/extension/lib/marker.coffee b/extension/lib/marker.coffee index 2f38246..afb8643 100644 --- a/extension/lib/marker.coffee +++ b/extension/lib/marker.coffee @@ -94,7 +94,7 @@ class Marker left -= Math.max(0, rect.width - elementWidth * @zoom) # Center the marker vertically on the non-covered point. - top -= Math.ceil(rect.height / 2) + top -= Math.round(rect.height / 2) # Make sure that the marker stays within the viewport. left = Math.min(left, @zoom * @viewport.right - rect.width) -- 2.39.3