Add "DIVIDE" command and new "maxslope" and "maxslopecost" parameters (#642)
* Added 'DIV' expression for profiles * Added 'uphillmaxbuffercost' and 'downhillmaxbuffercost' parameter. This makes it possible to penalize very steep path sections * Added 'div by zero' check in BExpression.java DIV command * Simplify maxbuffercostdiv logic * Added documentation about new features * Fix typo * Rename new DIV command * Redesign the new commands - Allow to set both the maxslope and the maxslopecost in the way context separately for uphill and downhill - New names for the new commands that better reflect what they actually do * Adapt the profile developers guide to the latest changes * Improve wording --------- Co-authored-by: quaelnix <122357328+quaelnix@users.noreply.github.com>
This commit is contained in:
parent
d2e183c625
commit
2f1422352e
4 changed files with 84 additions and 19 deletions
|
|
@ -9,14 +9,15 @@ final class BExpression {
|
|||
|
||||
private static final int ADD_EXP = 20;
|
||||
private static final int MULTIPLY_EXP = 21;
|
||||
private static final int MAX_EXP = 22;
|
||||
private static final int EQUAL_EXP = 23;
|
||||
private static final int GREATER_EXP = 24;
|
||||
private static final int MIN_EXP = 25;
|
||||
private static final int DIVIDE_EXP = 22;
|
||||
private static final int MAX_EXP = 23;
|
||||
private static final int EQUAL_EXP = 24;
|
||||
private static final int GREATER_EXP = 25;
|
||||
private static final int MIN_EXP = 26;
|
||||
|
||||
private static final int SUB_EXP = 26;
|
||||
private static final int LESSER_EXP = 27;
|
||||
private static final int XOR_EXP = 28;
|
||||
private static final int SUB_EXP = 27;
|
||||
private static final int LESSER_EXP = 28;
|
||||
private static final int XOR_EXP = 29;
|
||||
|
||||
private static final int SWITCH_EXP = 30;
|
||||
private static final int ASSIGN_EXP = 31;
|
||||
|
|
@ -144,6 +145,8 @@ final class BExpression {
|
|||
exp.typ = AND_EXP;
|
||||
} else if ("multiply".equals(operator)) {
|
||||
exp.typ = MULTIPLY_EXP;
|
||||
} else if ("divide".equals(operator)) {
|
||||
exp.typ = DIVIDE_EXP;
|
||||
} else if ("add".equals(operator)) {
|
||||
exp.typ = ADD_EXP;
|
||||
} else if ("max".equals(operator)) {
|
||||
|
|
@ -277,6 +280,8 @@ final class BExpression {
|
|||
return op1.evaluate(ctx) - op2.evaluate(ctx);
|
||||
case MULTIPLY_EXP:
|
||||
return op1.evaluate(ctx) * op2.evaluate(ctx);
|
||||
case DIVIDE_EXP:
|
||||
return divide(op1.evaluate(ctx), op2.evaluate(ctx));
|
||||
case MAX_EXP:
|
||||
return max(op1.evaluate(ctx), op2.evaluate(ctx));
|
||||
case MIN_EXP:
|
||||
|
|
@ -360,6 +365,11 @@ final class BExpression {
|
|||
return v1 < v2 ? v1 : v2;
|
||||
}
|
||||
|
||||
private float divide(float v1, float v2) {
|
||||
if (v2 == 0f) throw new IllegalArgumentException("div by zero");
|
||||
return v1 / v2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (typ == NUMBER_EXP) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public final class BExpressionContextWay extends BExpressionContext implements T
|
|||
private boolean decodeForbidden = true;
|
||||
|
||||
private static String[] buildInVariables =
|
||||
{"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed", "uphillcost", "downhillcost", "uphillcutoff", "downhillcutoff"};
|
||||
{"costfactor", "turncost", "uphillcostfactor", "downhillcostfactor", "initialcost", "nodeaccessgranted", "initialclassifier", "trafficsourcedensity", "istrafficbackbone", "priorityclassifier", "classifiermask", "maxspeed", "uphillcost", "downhillcost", "uphillcutoff", "downhillcutoff", "uphillmaxslope", "downhillmaxslope", "uphillmaxslopecost", "downhillmaxslopecost"};
|
||||
|
||||
protected String[] getBuildInVariableNames() {
|
||||
return buildInVariables;
|
||||
|
|
@ -82,6 +82,22 @@ public final class BExpressionContextWay extends BExpressionContext implements T
|
|||
return getBuildInVariable(15);
|
||||
}
|
||||
|
||||
public float getUphillmaxslope() {
|
||||
return getBuildInVariable(16);
|
||||
}
|
||||
|
||||
public float getDownhillmaxslope() {
|
||||
return getBuildInVariable(17);
|
||||
}
|
||||
|
||||
public float getUphillmaxslopecost() {
|
||||
return getBuildInVariable(18);
|
||||
}
|
||||
|
||||
public float getDownhillmaxslopecost() {
|
||||
return getBuildInVariable(19);
|
||||
}
|
||||
|
||||
public BExpressionContextWay(BExpressionMetaData meta) {
|
||||
super("way", meta);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue