Skip to content

Commit

Permalink
Merge branch 'feature/fix-diagonal-measure' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 17, 2021
2 parents 013569e + 51a37e7 commit 06b7389
Showing 1 changed file with 13 additions and 1 deletion.
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 06b7389

Please sign in to comment.