Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode values larger than maxStorableValue as infinity #2990

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ public DecimalEncodedValueImpl(String name, int bits, double minStorableValue, d
public void setDecimal(boolean reverse, int edgeId, EdgeIntAccess edgeIntAccess, double value) {
if (!isInitialized())
throw new IllegalStateException("Call init before using EncodedValue " + getName());
if (useMaximumAsInfinity) {
if (Double.isInfinite(value)) {
super.setInt(reverse, edgeId, edgeIntAccess, maxStorableValue);
return;
} else if (value >= maxStorableValue * factor) { // equality is important as maxStorableValue is reserved for infinity
super.uncheckedSet(reverse, edgeId, edgeIntAccess, maxStorableValue - 1);
return;
}
if (useMaximumAsInfinity && value >= maxStorableValue * factor) {
// treat any value larger or equal to maxStorableValue as infinity
super.setInt(reverse, edgeId, edgeIntAccess, maxStorableValue);
return;
} else if (Double.isInfinite(value))
throw new IllegalArgumentException("Value cannot be infinite if useMaximumAsInfinity is false");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void testNextStorableValue_maxInfinity() {
EdgeIntAccess edgeIntAccess = new ArrayEdgeIntAccess(1);
int edgeId = 0;
enc.setDecimal(false, edgeId, edgeIntAccess, 45);
assertEquals(42, enc.getDecimal(false, edgeId, edgeIntAccess));
assertEquals(Double.POSITIVE_INFINITY, enc.getDecimal(false, edgeId, edgeIntAccess));

enc.setDecimal(false, edgeId, edgeIntAccess, Double.POSITIVE_INFINITY);
assertEquals(Double.POSITIVE_INFINITY, enc.getDecimal(false, edgeId, edgeIntAccess));
Expand Down Expand Up @@ -216,4 +216,4 @@ public void minStorableBug() {
enc.setDecimal(true, edgeId, edgeIntAccess, 1.6);
assertEquals(1.6, enc.getDecimal(true, edgeId, edgeIntAccess));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public void testSimpleTags() {
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(11.5, malEnc.getDecimal(false, edgeId, edgeIntAccess), .01);

// if value is beyond the maximum then do not use infinity instead fallback to more restrictive maximum
// if value is beyond the maximum then do use infinity
edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.setTag("maxaxleload", "80");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(63.0, malEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(Double.POSITIVE_INFINITY, malEnc.getNextStorableValue(80), .01);
assertEquals(Double.POSITIVE_INFINITY, malEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
}

@Test
Expand Down Expand Up @@ -65,4 +66,4 @@ public void testNoLimit() {
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(Double.POSITIVE_INFINITY, malEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public void testSimpleTags() {
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(5.0, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);

// if value is beyond the maximum then do not use infinity instead fallback to more restrictive maximum
// if value is beyond the maximum then do use infinity
edgeIntAccess = new ArrayEdgeIntAccess(1);
readerWay.setTag("maxweight", "50");
readerWay.setTag("maxweight", "120");
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(25.4, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
assertEquals(Double.POSITIVE_INFINITY, mwEnc.getNextStorableValue(120), .01);
assertEquals(Double.POSITIVE_INFINITY, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
}

@Test
Expand All @@ -62,4 +63,4 @@ public void testConditionalTags() {
parser.handleWayTags(edgeId, edgeIntAccess, readerWay, relFlags);
assertEquals(6, mwEnc.getDecimal(false, edgeId, edgeIntAccess), .01);
}
}
}