Skip to content

Commit

Permalink
Add logging to confirm generator is working.
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jul 23, 2021
1 parent a341cca commit 0efc6c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions scripts/segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
Expand Down
23 changes: 15 additions & 8 deletions scripts/utility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { log } from "./module.js";

/*
* Generator to iterate grid points under a line.
* This version handles lines in 3d.
Expand All @@ -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);
Expand All @@ -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);
}

/*
Expand Down

0 comments on commit 0efc6c9

Please sign in to comment.