From 45aebed4872e3b419b8153b0689323379944b808 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Thu, 10 Oct 2024 17:07:36 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix|MovePenalty|NA=20when=20?= =?UTF-8?q?measuring=20regions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Ruler.js | 4 +++- scripts/measurement/Grid.js | 11 +++++++---- scripts/segments.js | 3 ++- scripts/token_speed.js | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/Ruler.js b/scripts/Ruler.js index 3e441b5..3fbc401 100644 --- a/scripts/Ruler.js +++ b/scripts/Ruler.js @@ -505,7 +505,9 @@ function _getSegmentLabel(wrapped, segment) { const origTotalDistance = this.totalDistance; segment.distance = roundMultiple(segment.waypoint.cost); this.totalDistance = this.totalCost; - const origLabel = wrapped(segment); + + // Issue #214 and GURPS PR. + const origLabel = game.system.id === "gurps" ? wrapped(segment, this.totalDistance) : wrapped(segment); segment.distance = origSegmentDistance; this.totalDistance = origTotalDistance; diff --git a/scripts/measurement/Grid.js b/scripts/measurement/Grid.js index 25be037..072bab2 100644 --- a/scripts/measurement/Grid.js +++ b/scripts/measurement/Grid.js @@ -6,8 +6,8 @@ game /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */ "use strict"; -import { Point3d } from "../geometry/3d/Point3d.js"; import { Settings } from "../settings.js"; +import { log } from "../util.js"; /** * Modify Grid classes to measure in 3d. @@ -32,7 +32,7 @@ PATCHES_HexagonalGrid.BASIC = {}; */ function getDirectPathGridless(wrapped, waypoints) { const offsets2d = wrapped(waypoints); - if ( !(waypoints[0] instanceof Point3d) ) return offsets2d; + if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return offsets2d; // 1-to-1 relationship between the waypoints and the offsets2d for gridless. const GridCoordinates3d = CONFIG.GeometryLib.threeD.GridCoordinates3d; @@ -54,13 +54,16 @@ function getDirectPathGridless(wrapped, waypoints) { function getDirectPathGridded(wrapped, waypoints) { const { HexGridCoordinates3d, GridCoordinates3d } = CONFIG.GeometryLib.threeD; - if ( !(waypoints[0] instanceof Point3d) ) return wrapped(waypoints); + if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return wrapped(waypoints); let prevWaypoint = GridCoordinates3d.fromObject(waypoints[0]); const path3d = []; const path3dFn = canvas.grid.isHexagonal ? HexGridCoordinates3d._directPathHex : GridCoordinates3d._directPathSquare; + log(`getDirectPathGridded|${waypoints.length} waypoints`); for ( let i = 1, n = waypoints.length; i < n; i += 1 ) { const currWaypoint = GridCoordinates3d.fromObject(waypoints[i]); + log(`getDirectPathGridded|Path from ${prevWaypoint.x},${prevWaypoint.y},${prevWaypoint.z} to ${currWaypoint.x},${currWaypoint.y},${currWaypoint.z}`); const segments3d = path3dFn(prevWaypoint, currWaypoint); + log(`getDirectPathGridded|Adding ${segments3d.length} segments`, segments3d); path3d.push(...segments3d); prevWaypoint = currWaypoint; } @@ -77,7 +80,7 @@ function getDirectPathGridded(wrapped, waypoints) { * @param {GridMeasurePathResult} result The measurement result that the measurements need to be written to */ function _measurePath(wrapped, waypoints, { cost }, result) { - if ( !(waypoints[0] instanceof Point3d) ) return wrapped(waypoints, { cost }, result); + if ( !(waypoints[0] instanceof CONFIG.GeometryLib.threeD.Point3d) ) return wrapped(waypoints, { cost }, result); const GridCoordinates3d = CONFIG.GeometryLib.threeD.GridCoordinates3d; initializeResultObject(result); result.waypoints.forEach(waypoint => initializeResultObject(waypoint)); diff --git a/scripts/segments.js b/scripts/segments.js index 7a313de..f8d6d36 100644 --- a/scripts/segments.js +++ b/scripts/segments.js @@ -7,7 +7,6 @@ CONFIG import { MODULE_ID } from "./const.js"; import { Settings } from "./settings.js"; import { Ray3d } from "./geometry/3d/Ray3d.js"; -import { Point3d } from "./geometry/3d/Point3d.js"; import { log } from "./util.js"; import { Pathfinder, hasCollision } from "./pathfinding/pathfinding.js"; import { MovePenalty } from "./measurement/MovePenalty.js"; @@ -18,6 +17,7 @@ import { MovePenalty } from "./measurement/MovePenalty.js"; * @returns {PIXI.Point[]} */ export function calculatePathPointsForSegment(segment, token) { + const Point3d = CONFIG.GeometryLib.threeD.Point3d; const A = Point3d.fromObject(segment.ray.A); const B = Point3d.fromObject(segment.ray.B); @@ -79,6 +79,7 @@ export function constructPathfindingSegments(segments, segmentMap) { // Make sure to keep the label for the last segment piece only if ( !segmentMap.size ) return segments; const newSegments = []; + const Point3d = CONFIG.GeometryLib.threeD.Point3d; for ( const segment of segments ) { const key = `${segment.ray.A.key}|${segment.ray.B.key}`; const pathPoints = segmentMap.get(key); diff --git a/scripts/token_speed.js b/scripts/token_speed.js index e67d456..6cde43d 100644 --- a/scripts/token_speed.js +++ b/scripts/token_speed.js @@ -9,7 +9,6 @@ PIXI import { SPEED } from "./const.js"; import { Settings } from "./settings.js"; -import { Point3d } from "./geometry/3d/Point3d.js"; import { Ray3d } from "./geometry/3d/Ray3d.js"; import { gridShape } from "./util.js"; import { MovePenalty } from "./measurement/MovePenalty.js"; @@ -123,6 +122,7 @@ function locateSegmentBreakpoint(segment, splitMoveDistance, { mp, gridless, num if ( !segment.cost || splitMoveDistance > segment.cost ) return null; // Attempt to move the split distance and determine the split location. + const Point3d = CONFIG.GeometryLib.threeD.Point3d; const { A, B } = segment.ray; let breakpoint = targetSplitForSegment(splitMoveDistance, A, B, mp, numPrevDiagonal); if ( !gridless ) { @@ -156,7 +156,7 @@ function targetSplitForSegment(targetCost, a, b, mp, numPrevDiagonal = 0) { // Assume linear cost increment. // So divide move in half each time. if ( splitCost(a, b, mp, 0, numPrevDiagonal) > targetCost ) return a; - const totalDist = Point3d.distanceBetween(a, b); + const totalDist = CONFIG.GeometryLib.threeD.Point3d.distanceBetween(a, b); if ( splitCost(a, b, mp, totalDist, numPrevDiagonal) <= targetCost ) return b; // Now increment distance until we exceed the target cost. @@ -184,7 +184,7 @@ function targetSplitForSegment(targetCost, a, b, mp, numPrevDiagonal = 0) { * @param {number} [numPrevDiagonal=0] */ function splitCost(a, b, mp, stepDist = 1, numPrevDiagonal = 0) { - b = a.towardsPoint(b, stepDist, Point3d._tmp); + b = a.towardsPoint(b, stepDist, CONFIG.GeometryLib.threeD.Point3d._tmp); b.roundDecimals(); // Ensure b is on a pixel, so we don't inadvertently exceed the cost at a border. return mp.measureSegment(a, b, { numPrevDiagonal }).cost; } From 3ffbbfa56c9b33611dd5d3c5d95e4a4346927ce5 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Thu, 10 Oct 2024 17:14:56 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20docs|Changelog|Add=20n?= =?UTF-8?q?otes=20for=20v0.10.14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1e53540..1f22d70 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +# 0.10.14 +Fix for NaN in the move penalty calculation when moving over regions. + # 0.10.13 Use a cached map to track move penalties for different region combinations. Improves compatibility with DAE while not severely impacting performance. Addresses #209. Use a mixed wrap instead of override for `Ruler#_computeDistance`, which improves compatibility with some systems, like dnd4e. Closes #213.