Skip to content

Commit

Permalink
Merge branch 'release/0.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Nov 24, 2022
2 parents fea4136 + a519da2 commit 1f5e56f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.6.1
Fix ruler calculation so the combined elevation distance and 2d distance is shown. (Closes issue #11.)

# 0.6.0
Drag Ruler compatibility! Some under-the-hood changes extending Ray to a Ray3d class to make segment distance measurements easier to accomplish.

Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"manifestPlusVersion": "1.0.0",
"compatibility": {
"minimum": "10",
"verified": "10.288"
"verified": "10.290"
},
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/Ray3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function registerRayMethods() {
* @returns {number}
*/
function gameDistance(gridSpaces) {
return canvas.grid.measureDistances([this], { gridSpaces });
return canvas.grid.grid.measureDistances([{ ray: this }], { gridSpaces });
}

/**
Expand Down
18 changes: 15 additions & 3 deletions scripts/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export function _getMeasurementSegmentsDragRulerRuler(wrapped) {

function elevateSegments(ruler, segments) { // Add destination as the final waypoint
const waypoints = ruler.waypoints.concat([ruler.destination]);

const { distance, size } = canvas.dimensions;
const gridUnits = size / distance;

Expand Down Expand Up @@ -89,8 +88,21 @@ function elevationAtWaypoint(waypoint) {
* hypotenuse to do the measurement.
*/
export function measureDistancesGridLayer(wrapped, segments, options = {}) {
if ( segments[0] instanceof Ray ) return segments.map(s => s.gameDistance(options.gridSpaces));
return wrapped(segments, options);
if ( !segments.length || !(segments[0]?.ray instanceof Ray3d) ) return wrapped(segments, options);

// Avoid modifying the segment rays.
const ln = segments.length;
const origRays = Array(ln);
for ( let i = 0; i < ln; i += 1 ) {
const s = segments[i];
origRays[i] = s.ray;
s.ray = s.ray.projectOntoCanvas();
}

const out = wrapped(segments, options);

for ( let i = 0; i < ln; i += 1 ) segments[i].ray = origRays[i];
return out;
}

/**
Expand Down

0 comments on commit 1f5e56f

Please sign in to comment.