Skip to content

Commit

Permalink
Merge branch 'release/0.2.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 17, 2021
2 parents 19b3325 + e5857bc commit 2e4e8a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
14 changes: 13 additions & 1 deletion scripts/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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] };
}


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
Expand Down

0 comments on commit 2e4e8a9

Please sign in to comment.