From 0efc6c9c18796fa6234d4c32590112ccf4f69f75 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Fri, 23 Jul 2021 14:03:31 -0700 Subject: [PATCH] Add logging to confirm generator is working. --- scripts/segments.js | 6 +++--- scripts/utility.js | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/segments.js b/scripts/segments.js index b02eccd..f7de545 100644 --- a/scripts/segments.js +++ b/scripts/segments.js @@ -148,7 +148,7 @@ export function elevationRulerConstructPhysicalPath(wrapped, ...args) { // --> this is done in AddProperties function log("Constructing the physical path."); const default_path = wrapped(...args); - log("Default path", default_path); + log("Default path: (${default_path.origin.x}, ${default_path.origin.y}), (${default_path.destination.x}, ${default_path.destination.y})", default_path); const starting_elevation = this.getFlag(MODULE_ID, "starting_elevation"); const ending_elevation = this.getFlag(MODULE_ID, "ending_elevation"); @@ -171,9 +171,9 @@ export function elevationRulerConstructPhysicalPath(wrapped, ...args) { const simple_path_distance = window.libRuler.RulerUtilities.calculateDistance(default_path.origin, default_path.destination); const ratio = simple_path_distance / ruler_distance; default_path.origin.z = starting_elevation_grid_units; - default_path.destination.z = starting_elevation_grid_units + elevation_delta * ratio; + default_path.destination.z = (starting_elevation_grid_units + elevation_delta) * ratio; - log("Default path", default_path); + log("Default path: (${default_path.origin.x}, ${default_path.origin.y}, ${default_path.origin.z}), (${default_path.destination.x}, ${default_path.destination.y}, ${default_path.destination.z})", default_path); return default_path; } diff --git a/scripts/utility.js b/scripts/utility.js index 54ed8e7..de374e3 100644 --- a/scripts/utility.js +++ b/scripts/utility.js @@ -1,3 +1,5 @@ +import { log } from "./module.js"; + /* * Generator to iterate grid points under a line. * This version handles lines in 3d. @@ -11,12 +13,17 @@ export function * iterateGridUnder3dLine(generator, origin, destination) { let prior_elevation = origin.z || 0; const end_elevation = destination.z || 0; const direction = prior_elevation <= end_elevation ? 1 : -1; - const elevation_increment = canvas.grid.grid.options.dimensions.distance; - + const elevation_increment = canvas.scene.data.gridDistance * canvas.scene.data.grid; + log(`elevation: ${prior_elevation}[prior], ${end_elevation}[end], ${direction}[direction], ${elevation_increment}[increment]`); + //log(generator); + let last_row, last_col; + for(const res of generator) { // step down in elevation if necessary - const {value, done} = res; - const [row, col] = value; + log(res); + //const {value, done} = res; + const [row, col] = res; + [last_row, last_col] = res; if(prior_elevation != end_elevation) { const remainder = Math.abs(prior_elevation - end_elevation); @@ -34,17 +41,17 @@ export function * iterateGridUnder3dLine(generator, origin, destination) { iteration += 1; const remainder = Math.abs(prior_elevation - end_elevation); const step_elevation = Math.min(remainder, elevation_increment); + log(`elevation: ${prior_elevation}[prior], ${end_elevation}[end], ${step_elevation}[step]`); prior_elevation += step_elevation * direction; - yield [row, col, elevation]; + yield [last_row, last_col, prior_elevation]; } } // needed for libWrapper export function iterateGridUnder3dLine_wrapper(wrapped, origin, destination) { - yield* base_gen = wrapped(origin, destination); - - return iterateGridUnder3dLine(base_gen, origin, destination); + log(`iterateGrid origin, destination`, origin, destination); + return iterateGridUnder3dLine(wrapped(origin, destination), origin, destination); } /*