Pass estimated cost factor to kinematic calc

(only to use different formula > 4.9)
This commit is contained in:
Norbert Renner 2022-04-26 12:41:41 +02:00
parent 6a19b53dc0
commit 7f481b8db3
2 changed files with 13 additions and 7 deletions

View file

@ -489,8 +489,9 @@ BR.Routing = L.Routing.extend({
return btools.util.CheapRuler.calcDistance(ilon1, ilat1, ilon2, ilat2); return btools.util.CheapRuler.calcDistance(ilon1, ilat1, ilon2, ilat2);
}, },
_computeKinematic: function (distance, deltaHeight) { _computeKinematic: function (distance, deltaHeight, costFactor) {
const rc = new BR.RoutingContext(this.profile); const rc = new BR.RoutingContext(this.profile);
rc.expctxWay = new BR.BExpressionContextWay(undefined, costFactor);
const stdPath = new BR.StdPath(); const stdPath = new BR.StdPath();
stdPath.computeKinematic(rc, distance, deltaHeight, true); stdPath.computeKinematic(rc, distance, deltaHeight, true);
@ -498,7 +499,7 @@ BR.Routing = L.Routing.extend({
}, },
_getCostFactor: function (line) { _getCostFactor: function (line) {
let costFactor = null; let costFactor;
if (line) { if (line) {
const props = line.feature.properties; const props = line.feature.properties;
const length = props['track-length']; const length = props['track-length'];
@ -530,7 +531,7 @@ BR.Routing = L.Routing.extend({
if (beforeCostFactor != null && afterCostFactor != null) { if (beforeCostFactor != null && afterCostFactor != null) {
costFactor = Math.max(beforeCostFactor, afterCostFactor); costFactor = Math.max(beforeCostFactor, afterCostFactor);
} else { } else {
costFactor = beforeCostFactor ?? afterCostFactor ?? 0; costFactor = beforeCostFactor ?? afterCostFactor;
} }
for (const beeline of serialBeelines) { for (const beeline of serialBeelines) {
@ -538,7 +539,7 @@ BR.Routing = L.Routing.extend({
const distance = props['track-length']; const distance = props['track-length'];
const deltaHeight = (serialDelta * distance) / serialDistance; const deltaHeight = (serialDelta * distance) / serialDistance;
const stdPath = this._computeKinematic(distance, deltaHeight); const stdPath = this._computeKinematic(distance, deltaHeight, costFactor);
props['total-energy'] = stdPath.getTotalEnergy(); props['total-energy'] = stdPath.getTotalEnergy();
props['total-time'] = stdPath.getTotalTime(); props['total-time'] = stdPath.getTotalTime();
@ -551,7 +552,7 @@ BR.Routing = L.Routing.extend({
props['plain-ascend'] = Math.trunc(deltaHeight + 0.5); props['plain-ascend'] = Math.trunc(deltaHeight + 0.5);
// do not set interpolated alt value, to explicitly show missing data, e.g. in height graph // do not set interpolated alt value, to explicitly show missing data, e.g. in height graph
props['cost'] = Math.round(distance * costFactor); props['cost'] = Math.round(distance * (costFactor ?? 0));
} }
}, },

View file

@ -2,11 +2,15 @@
// Calculates time and energy stats // Calculates time and energy stats
class BExpressionContextWay { class BExpressionContextWay {
constructor(maxspeed = 45.0, costfactor = 1.0) {
this.maxspeed = maxspeed;
this.costfactor = costfactor;
}
getMaxspeed() { getMaxspeed() {
return 45.0; return this.maxspeed;
} }
getCostfactor() { getCostfactor() {
return 1.0; return this.costfactor;
} }
} }
@ -156,4 +160,5 @@
BR.StdPath = StdPath; BR.StdPath = StdPath;
BR.RoutingContext = RoutingContext; BR.RoutingContext = RoutingContext;
BR.BExpressionContextWay = BExpressionContextWay;
})(); })();