From f9fe2b43207c08df1d87156576641389aa73b3c8 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Sat, 17 Jul 2021 14:16:51 -0700 Subject: [PATCH 1/3] Try snapping to grid center If we are using grid spaces, then if the token moves diagonally in 2-D, the 3-D measure may be inconsistent. This appears to be because the projected hypotenuse endpoint is no longer centered in the grid, causing rounding to push the distance calculation off depending on cardinal direction of the move. --- scripts/segments.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/segments.js b/scripts/segments.js index 0b69e8a..a80bce2 100644 --- a/scripts/segments.js +++ b/scripts/segments.js @@ -164,13 +164,25 @@ export function elevationRulerDistanceFunction(wrapped, physical_path) { physical_path.destination = ProjectElevatedPoint(physical_path.origin, physical_path.destination); delete physical_path.origin.z; + delete physical_path.destination.z; + + // if we are using grid spaces, the destination needs to be re-centered to the grid. + // otherwise, when a token moves in 2-D diagonally, the 3-D measure will be inconsistent + // depending on cardinality of the move, as rounding will increase/decrease to the nearest gridspace + if(this.measure_distance_options?.gridSpaces) { + // canvas.grid.getCenter returns an array [x, y]; + const snapped = canvas.grid.getCenter(physical_path.destination) + log(`Snapping ${physical_path.destination.x}, ${physical_path.destination.y} to ${snapped[0]}, ${snapped[1]}`); + physical_path.destination = { x: snapped[0], y: snapped[1] }; + } + + log(`Projected physical_path from origin ${physical_path.origin.x}, ${physical_path.origin.y} to dest ${physical_path.destination.x}, ${physical_path.destination.y}`); return wrapped(physical_path); } - /* * @param {number} segmentDistance * @param {number} totalDistance From 51a37e7272acf8af0e9c7a670dd343cf0290f841 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Sat, 17 Jul 2021 14:20:19 -0700 Subject: [PATCH 2/3] Fix call to canvas.grid.getCenter --- scripts/segments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/segments.js b/scripts/segments.js index a80bce2..b904c1f 100644 --- a/scripts/segments.js +++ b/scripts/segments.js @@ -171,7 +171,7 @@ export function elevationRulerDistanceFunction(wrapped, physical_path) { // depending on cardinality of the move, as rounding will increase/decrease to the nearest gridspace if(this.measure_distance_options?.gridSpaces) { // canvas.grid.getCenter returns an array [x, y]; - const snapped = canvas.grid.getCenter(physical_path.destination) + const snapped = canvas.grid.getCenter(physical_path.destination.x, physical_path.destination.y); log(`Snapping ${physical_path.destination.x}, ${physical_path.destination.y} to ${snapped[0]}, ${snapped[1]}`); physical_path.destination = { x: snapped[0], y: snapped[1] }; } From e5857bcda95225b6542e38236f6b6a2763c64e01 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Sat, 17 Jul 2021 14:39:22 -0700 Subject: [PATCH 3/3] Update changelog. --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 448331d..330cefd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +# 0.2.3 +Fix #3. When a grid is present, snap the projected destination point to the center of the grid. This keeps the distances consistent for different cardinalities. Rounding still occurs with grid measurements such that adjacent squares may have the same measured 3-D distance despite appearing to be closer/further from the origin point. + ## 0.2.2 Update manifest for libruler dependency to point to correct JSON URL. Fixes #2.