Problems were partially caused by the limits of floating point accuracy.
This commit is contained in:
parent
f94ebf5296
commit
8d16c047cc
@ -185,17 +185,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint);
|
// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint);
|
||||||
// INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord));
|
// INFO("length of old edge: " << ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord));
|
||||||
// INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint));
|
// INFO("Length of new edge: " << ApproximateDistance(smallestEdge.startCoord, newEndpoint));
|
||||||
// assert(!resultNode.isBidirected() || (resultNode.weight1 == resultNode.weight2));
|
// assert(!resultNode.isBidirected() || (resultNode.weight1 == resultNode.weight2));
|
||||||
// if(resultNode.weight1 != resultNode.weight2) {
|
// if(resultNode.weight1 != resultNode.weight2) {
|
||||||
// INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2);
|
// INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2);
|
||||||
// INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected() ? "yes" : "no"));
|
// INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected() ? "yes" : "no"));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) );
|
double ratio = std::min(1., ApproximateDistance(smallestEdge.startCoord, newEndpoint)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord));
|
||||||
assert(ratio >= 0 && ratio <=1);
|
|
||||||
|
|
||||||
|
// INFO("startCoord: " << smallestEdge.startCoord << "; targetCoord: " << smallestEdge.targetCoord << ", newEndpoint: " << newEndpoint);
|
||||||
|
// INFO("Length of vector: " << ApproximateDistance(smallestEdge.startCoord, newEndpoint)/ApproximateDistance(smallestEdge.startCoord, smallestEdge.targetCoord));
|
||||||
//Hack to fix rounding errors and wandering via nodes.
|
//Hack to fix rounding errors and wandering via nodes.
|
||||||
if(std::abs(location.lon - resultNode.location.lon) == 1)
|
if(std::abs(location.lon - resultNode.location.lon) == 1)
|
||||||
resultNode.location.lon = location.lon;
|
resultNode.location.lon = location.lon;
|
||||||
@ -207,8 +208,8 @@ public:
|
|||||||
resultNode.weight2 -= resultNode.weight1;
|
resultNode.weight2 -= resultNode.weight1;
|
||||||
}
|
}
|
||||||
resultNode.ratio = ratio;
|
resultNode.ratio = ratio;
|
||||||
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2);
|
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2 << ", ratio: " << ratio);
|
||||||
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--")
|
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--");
|
||||||
return foundNode;
|
return foundNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,12 +279,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double LengthOfVector(const _Coordinate & c1, const _Coordinate & c2) {
|
|
||||||
double length1 = std::sqrt(c1.lat/100000.*c1.lat/100000. + c1.lon/100000.*c1.lon/100000.);
|
|
||||||
double length2 = std::sqrt(c2.lat/100000.*c2.lat/100000. + c2.lon/100000.*c2.lon/100000.);
|
|
||||||
return std::fabs(length1-length2);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool DoubleEpsilonCompare(const double d1, const double d2) {
|
inline bool DoubleEpsilonCompare(const double d1, const double d2) {
|
||||||
return (std::fabs(d1 - d2) < 0.0001);
|
return (std::fabs(d1 - d2) < 0.0001);
|
||||||
}
|
}
|
||||||
|
@ -354,6 +354,7 @@ public:
|
|||||||
// for(unsigned i = 0; i < packedPath.size(); ++i)
|
// for(unsigned i = 0; i < packedPath.size(); ++i)
|
||||||
// std::cout << packedPath[i] << " ";
|
// std::cout << packedPath[i] << " ";
|
||||||
// std::cout << std::endl;
|
// std::cout << std::endl;
|
||||||
|
|
||||||
_UnpackPath(packedPath, path);
|
_UnpackPath(packedPath, path);
|
||||||
return _upperbound;
|
return _upperbound;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,7 @@ void DescriptionFactory::Run(const unsigned zoomLevel, const unsigned duration)
|
|||||||
|
|
||||||
//Post-processing to remove empty or nearly empty path segments
|
//Post-processing to remove empty or nearly empty path segments
|
||||||
if(0. == startPhantom.ratio || 0 == pathDescription[0].length) {
|
if(0. == startPhantom.ratio || 0 == pathDescription[0].length) {
|
||||||
|
if(pathDescription.size() > 2)
|
||||||
pathDescription.erase(pathDescription.begin());
|
pathDescription.erase(pathDescription.begin());
|
||||||
pathDescription[0].turnInstruction = TurnInstructions.HeadOn;
|
pathDescription[0].turnInstruction = TurnInstructions.HeadOn;
|
||||||
pathDescription[0].necessary = true;
|
pathDescription[0].necessary = true;
|
||||||
@ -106,6 +107,7 @@ void DescriptionFactory::Run(const unsigned zoomLevel, const unsigned duration)
|
|||||||
pathDescription[0].duration *= startPhantom.ratio;
|
pathDescription[0].duration *= startPhantom.ratio;
|
||||||
}
|
}
|
||||||
if(1. == targetPhantom.ratio || 0 == pathDescription.back().length) {
|
if(1. == targetPhantom.ratio || 0 == pathDescription.back().length) {
|
||||||
|
if(pathDescription.size() > 2)
|
||||||
pathDescription.pop_back();
|
pathDescription.pop_back();
|
||||||
pathDescription.back().necessary = true;
|
pathDescription.back().necessary = true;
|
||||||
pathDescription.back().turnInstruction = TurnInstructions.NoTurn;
|
pathDescription.back().turnInstruction = TurnInstructions.NoTurn;
|
||||||
|
Loading…
Reference in New Issue
Block a user