@wemap/routers 12.10.0 → 12.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -530,15 +530,13 @@ class StepsBuilder {
530
530
  const previousBearing = coordsBeforeStep.bearingTo(stepInfo.coords);
531
531
  const nextBearing = stepInfo.coords.bearingTo(coordsAfterStep);
532
532
  let distance = 0;
533
- const coordsToStopCalculation = stepId !== stepsInfo.length - 1 ? stepsInfo[stepId + 1].coords : pathCoords[pathCoords.length - 1];
533
+ const isLastStep = stepId === stepsInfo.length - 1;
534
+ const coordsToStopCalculation = isLastStep ? pathCoords[pathCoords.length - 1] : stepsInfo[stepId + 1].coords;
534
535
  let currentCoordsId = coordsId;
535
536
  while (!pathCoords[currentCoordsId].equals(coordsToStopCalculation)) {
536
537
  distance += pathCoords[currentCoordsId].distanceTo(pathCoords[currentCoordsId + 1]);
537
538
  currentCoordsId++;
538
539
  }
539
- if (currentCoordsId === pathCoords.length - 1) {
540
- distance += pathCoords[currentCoordsId].distanceTo(end);
541
- }
542
540
  return {
543
541
  coords: stepInfo.coords,
544
542
  name: stepInfo.name || null,
@@ -547,7 +545,7 @@ class StepsBuilder {
547
545
  nextBearing,
548
546
  angle: maths.diffAngle(previousBearing, nextBearing + Math.PI),
549
547
  firstStep: stepId === 0,
550
- lastStep: stepId === stepsInfo.length - 1,
548
+ lastStep: isLastStep,
551
549
  distance,
552
550
  // stepInfo.distance is overwritten
553
551
  duration: stepInfo.duration || getDurationFromLength(distance),
@@ -768,7 +766,7 @@ class Itinerary {
768
766
  }
769
767
  get distance() {
770
768
  if (this._distance === null) {
771
- this._distance = geo.Utils.calcDistance([this.origin, ...this.coords, this.destination]);
769
+ this._distance = geo.Utils.calcDistance(this.coords);
772
770
  }
773
771
  return this._distance;
774
772
  }
@@ -4844,9 +4842,7 @@ class ItineraryInfoManager {
4844
4842
  this._coordsPreviousStep = new Array(itinerary.coords.length);
4845
4843
  this._coordsDistanceTraveled = new Array(itinerary.coords.length);
4846
4844
  this._coordsLeg = new Array(itinerary.coords.length);
4847
- const originProjectionDistance = this._itinerary.origin.distanceTo(this._itinerary.coords[0]);
4848
- const destinationProjectionDistance = this._itinerary.destination.distanceTo(this._itinerary.coords[this._itinerary.coords.length - 1]);
4849
- this._itineraryDistanceWithoutProjections = itinerary.distance - originProjectionDistance - destinationProjectionDistance;
4845
+ this._itineraryDistanceWithoutProjections = itinerary.distance;
4850
4846
  let stepId = 0;
4851
4847
  let previousStep = null;
4852
4848
  let nextStep = this._steps[0];