From e560146e37701d94bab08ad3b46b00c1047c70c7 Mon Sep 17 00:00:00 2001 From: Alexander Goryushkin Date: Wed, 28 Feb 2024 19:44:51 -0300 Subject: [PATCH] calculate street width in place --- src/aframe-streetmix-parsers.js | 3 ++- src/index.js | 3 ++- src/tested/streetmix-utils.js | 9 --------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/aframe-streetmix-parsers.js b/src/aframe-streetmix-parsers.js index 662fdfd0c..212414a59 100644 --- a/src/aframe-streetmix-parsers.js +++ b/src/aframe-streetmix-parsers.js @@ -695,7 +695,8 @@ function createBrtStationElement () { // offset to center the street around global x position of 0 function createCenteredStreetElement (segments) { const streetEl = document.createElement('a-entity'); - const streetWidth = streetmixUtils.calcStreetWidth(segments); + const streetWidth = segments.reduce( + (streetWidth, segmentData) => streetWidth + segmentData.width, 0); const offset = 0 - streetWidth / 2; streetEl.setAttribute('position', offset + ' 0 0'); return streetEl; diff --git a/src/index.js b/src/index.js index 5c92dae0f..e89b54ee6 100644 --- a/src/index.js +++ b/src/index.js @@ -53,7 +53,8 @@ AFRAME.registerComponent('street', { this.el.append(streetEl); if (data.left || data.right) { - const streetWidth = streetmixUtils.calcStreetWidth(streetmixSegments.streetmixSegmentsMetric, data.autoStriping); + const streetWidth = streetmixSegments.streetmixSegmentsMetric.reduce( + (streetWidth, segmentData) => streetWidth + segmentData.width, 0); const buildingsEl = streetmixParsers.processBuildings(data.left, data.right, streetWidth, data.showGround, data.length); this.el.append(buildingsEl); } diff --git a/src/tested/streetmix-utils.js b/src/tested/streetmix-utils.js index 47753186f..8884421b3 100644 --- a/src/tested/streetmix-utils.js +++ b/src/tested/streetmix-utils.js @@ -48,15 +48,6 @@ function streetmixAPIToUser (APIURL) { // eslint-disable-line no-unused-vars } module.exports.streetmixAPIToUser = streetmixAPIToUser; -function calcStreetWidth (segments) { // eslint-disable-line no-unused-vars - var cumulativeWidthInMeters = 0; - segments.forEach((currentSegment) => { - cumulativeWidthInMeters = cumulativeWidthInMeters + currentSegment.width; - }); - return cumulativeWidthInMeters; -} -module.exports.calcStreetWidth = calcStreetWidth; - // convert all feet values to meters for schemaVersion < 30 function convertStreetValues (streetData) { if (streetData.schemaVersion < 30) {