From 1758e68485662540c8b9c88678900d9042dfb351 Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Thu, 26 Jan 2023 12:36:19 -0800 Subject: [PATCH 1/2] Fix wall elimination based on height of source Correct getting the source and type from config. Use Point3d to construct a 3d point for the origin. Fix how height is calculated for cycleToPolygon. In the updateWall, always update the cycle polygons to catch changes to height or restriction type. --- scripts/WallTracer.js | 24 ++++++++++++------------ scripts/clockwise_sweep.js | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/WallTracer.js b/scripts/WallTracer.js index 0e6ebdc3..52e0de00 100644 --- a/scripts/WallTracer.js +++ b/scripts/WallTracer.js @@ -562,8 +562,8 @@ export class WallTracer extends Graph { move: CONST.WALL_SENSE_TYPES.NORMAL }; const height = { - min: Number.NEGATIVE_INFINITY, - max: Number.POSITIVE_INFINITY + min: Number.POSITIVE_INFINITY, + max: Number.NEGATIVE_INFINITY }; let hasOneWay = false; @@ -583,9 +583,8 @@ export class WallTracer extends Graph { restrictionTypes.sound = Math.min(restrictionTypes.sound, doc.sound); restrictionTypes.move = Math.min(restrictionTypes.move, doc.move); - const minmax = Math.minMax(height.min, height.max, wall.topZ, wall.bottomZ); - height.min = minmax.min; - height.max = minmax.max; + height.min = Math.min(height.min, wall.bottomZ) + height.max = Math.max(height.max, wall.topZ) hasOneWay ||= doc.dir; @@ -629,7 +628,6 @@ export class WallTracer extends Graph { encompassingPolygons(origin, type) { origin.z ??= 0; - // Find those polygons that actually contain the origin. // Start by using the bounds, then test containment. const bounds = new PIXI.Rectangle(origin.x - 1, origin.y -1, 2, 2); @@ -807,14 +805,16 @@ Hooks.on("createWall", function(document, _options, _userId) { Hooks.on("updateWall", function(document, changes, _options, _userId) { log("updateWall"); - // Only update the edges if the coordinates have changed. - if ( !(Object.hasOwn(changes, "c") || Object.hasOwn(changes, "ds")) ) return; + // Only update the edges if the coordinates have changed or the door setting has changed. + if ( Object.hasOwn(changes, "c") || Object.hasOwn(changes, "ds") ) { + // Easiest approach is to trash the edges for the wall and re-create them. + SCENE_GRAPH.removeWall(document.id); - // Easiest approach is to trash the edges for the wall and re-create them. - SCENE_GRAPH.removeWall(document.id); + // Only add the wall back if it is not open + if ( !document.object.isOpen) SCENE_GRAPH.addWall(document.object); + } - // Only add the wall if it is not open - if ( !document.object.isOpen) SCENE_GRAPH.addWall(document.object); + // Update the polygons regardless, in case a wall limitation or wall height has changed. SCENE_GRAPH.updateCyclePolygons(); }); diff --git a/scripts/clockwise_sweep.js b/scripts/clockwise_sweep.js index 6222100a..acc756b3 100644 --- a/scripts/clockwise_sweep.js +++ b/scripts/clockwise_sweep.js @@ -317,7 +317,8 @@ function filterPotentialBlockingWalls(wallPoints, wallArr, sourceOrigin) { * @param {object} config */ export function initializeClockwiseSweepPolygon(wrapper, origin, config) { - const encompassingPolygon = SCENE_GRAPH.encompassingPolygon(origin, this.config.type); + const sourceOrigin = config.source ? Point3d.fromPointSource(config.source) : new Point3d(origin.x, origin.y, 0); + const encompassingPolygon = SCENE_GRAPH.encompassingPolygon(sourceOrigin, config.type); if ( encompassingPolygon ) { config.boundaryShapes ||= []; config.boundaryShapes.push(encompassingPolygon); From f45449a5cda9fe440628d544c78c096e236b648e Mon Sep 17 00:00:00 2001 From: Michael Enion Date: Thu, 26 Jan 2023 12:46:27 -0800 Subject: [PATCH 2/2] Update changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 4b45daa1..54e358a0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +## 0.3.5 +Fix for enhanced LOS when limited walls or walls with defined heights are present. + ## 0.3.4 Update to geometry lib v0.1.3.