Skip to content

Commit

Permalink
calculate street width in place
Browse files Browse the repository at this point in the history
  • Loading branch information
Algorush committed Feb 28, 2024
1 parent 4cfccb6 commit e560146
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 0 additions & 9 deletions src/tested/streetmix-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e560146

Please sign in to comment.