Fix a small bug in lat computation in CheapRulerSingleton and update

according to latest master branch.
This commit is contained in:
Phyks (Lucas Verney) 2018-12-11 09:04:13 +01:00
parent 2591f22348
commit 1a2a1164f9
4 changed files with 8 additions and 9 deletions

View file

@ -28,9 +28,8 @@ public class OsmNodeNamed extends OsmNode
public double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength) { public double distanceWithinRadius(int lon1, int lat1, int lon2, int lat2, double totalSegmentLength) {
double[] lonlat2m = CheapRulerSingleton.getLonLatToMeterScales( (lat1 + lat2) >> 1 ); double[] lonlat2m = CheapRulerSingleton.getLonLatToMeterScales( (lat1 + lat2) >> 1 );
double realRadius = radius * 110984.; boolean isFirstPointWithinCircle = CheapRulerSingleton.distance(lon1, lat1, ilon, ilat) < radius;
boolean isFirstPointWithinCircle = CheapRulerSingleton.distance(lon1, lat1, ilon, ilat) < realRadius; boolean isLastPointWithinCircle = CheapRulerSingleton.distance(lon2, lat2, ilon, ilat) < radius;
boolean isLastPointWithinCircle = CheapRulerSingleton.distance(lon2, lat2, ilon, ilat) < realRadius;
// First point is within the circle // First point is within the circle
if (isFirstPointWithinCircle) { if (isFirstPointWithinCircle) {
// Last point is within the circle // Last point is within the circle
@ -62,7 +61,7 @@ public class OsmNodeNamed extends OsmNode
double initialToCenter = CheapRulerSingleton.distance(ilon, ilat, lon1, lat1); double initialToCenter = CheapRulerSingleton.distance(ilon, ilat, lon1, lat1);
// Half length of the segment within the circle // Half length of the segment within the circle
double halfDistanceWithin = Math.sqrt( double halfDistanceWithin = Math.sqrt(
realRadius*realRadius - ( radius*radius - (
initialToCenter*initialToCenter - initialToCenter*initialToCenter -
initialToProject*initialToProject initialToProject*initialToProject
) )

View file

@ -426,7 +426,7 @@ public final class RoutingContext
double dd = Math.sqrt( (dx10*dx10 + dy10*dy10)*(dx21*dx21 + dy21*dy21) ); double dd = Math.sqrt( (dx10*dx10 + dy10*dy10)*(dx21*dx21 + dy21*dy21) );
if ( dd == 0. ) { cosangle = 1.; return 0.; } if ( dd == 0. ) { cosangle = 1.; return 0.; }
double sinp = (dy10*dy21 - dx10*dx21)/dd; double sinp = (dx10*dy21 - dy10*dx21)/dd;
double cosp = (dy10*dy21 + dx10*dx21)/dd; double cosp = (dy10*dy21 + dx10*dx21)/dd;
cosangle = cosp; cosangle = cosp;

View file

@ -29,7 +29,7 @@ public class OsmNodeNamedTest {
node.ilon = toOsmLon(2.334243); node.ilon = toOsmLon(2.334243);
node.ilat = toOsmLat(48.824017); node.ilat = toOsmLat(48.824017);
// Radius // Radius
node.radius = 30 / 110984.; node.radius = 30;
// Check distance within radius is correctly computed if the segment passes through the center // Check distance within radius is correctly computed if the segment passes through the center
lon1 = toOsmLon(2.332559); lon1 = toOsmLon(2.332559);
@ -39,9 +39,9 @@ public class OsmNodeNamedTest {
double totalSegmentLength = CheapRulerSingleton.distance(lon1, lat1, lon2, lat2); double totalSegmentLength = CheapRulerSingleton.distance(lon1, lat1, lon2, lat2);
assertEquals( assertEquals(
"Works for segment aligned with the nogo center", "Works for segment aligned with the nogo center",
2 * node.radius * 110984., 2 * node.radius,
node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength), node.distanceWithinRadius(lon1, lat1, lon2, lat2, totalSegmentLength),
0.01 * (2 * node.radius * 110984.) 0.01 * (2 * node.radius)
); );
// Check distance within radius is correctly computed for a given circle // Check distance within radius is correctly computed for a given circle

View file

@ -33,7 +33,7 @@ public final class CheapRulerSingleton {
} }
private static double[] calcKxKyFromILat(int ilat) { private static double[] calcKxKyFromILat(int ilat) {
double lat = DEG_TO_RAD*ilat*ILATLNG_TO_LATLNG - 90; double lat = DEG_TO_RAD*(ilat*ILATLNG_TO_LATLNG - 90);
double cos = Math.cos(lat); double cos = Math.cos(lat);
double cos2 = 2 * cos * cos - 1; double cos2 = 2 * cos * cos - 1;
double cos3 = 2 * cos * cos2 - cos; double cos3 = 2 * cos * cos2 - cos;