Add a basic implementation of CheapRuler and use it across code.

This commit is contained in:
Phyks (Lucas Verney) 2018-11-20 23:27:55 +01:00
parent 997beb0e96
commit 665b7096e8
5 changed files with 59 additions and 37 deletions

View file

@ -2,6 +2,7 @@ package btools.router;
import btools.mapaccess.OsmNode;
import btools.mapaccess.OsmPos;
import btools.util.CheapRuler;
import java.io.DataInput;
import java.io.DataOutput;
@ -18,7 +19,7 @@ public class OsmPathElement implements OsmPos
private int ilat; // latitude
private int ilon; // longitude
private short selev; // longitude
public MessageData message = null; // description
public int cost;
@ -77,15 +78,7 @@ public class OsmPathElement implements OsmPos
public final int calcDistance( OsmPos p )
{
double l = (ilat-90000000) * 0.00000001234134;
double l2 = l*l;
double l4 = l2*l2;
double coslat = 1.- l2 + l4 / 6.;
double dlat = (ilat - p.getILat() )/1000000.;
double dlon = (ilon - p.getILon() )/1000000. * coslat;
double d = Math.sqrt( dlat*dlat + dlon*dlon ) * 110984.; // 6378000. / 57.3;
return (int)(d + 1.0 );
return (int)(CheapRuler.distance(ilon, ilat, p.getILon(), p.getILat()) + 1.0 );
}
public OsmPathElement origin;
@ -109,7 +102,7 @@ public class OsmPathElement implements OsmPos
pe.origin = origin;
return pe;
}
protected OsmPathElement()
{
}
@ -122,7 +115,7 @@ public class OsmPathElement implements OsmPos
{
return ilon + "_" + ilat;
}
public void writeToStream( DataOutput dos ) throws IOException
{
dos.writeInt( ilat );

View file

@ -307,6 +307,7 @@ public final class RoutingContext
public int calcDistance( int lon1, int lat1, int lon2, int lat2 )
{
// TODO[Phyks]
double l = (lat2 - 90000000) * 0.00000001234134;
double l2 = l*l;
double l4 = l2*l2;