use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GHRequestTest method testCorrectInit.
@Test
public void testCorrectInit() {
double lat0 = 51, lon0 = 1, lat1 = 52, lon1 = 2, lat2 = 53, lon2 = 3;
ArrayList<GHPoint> points = new ArrayList<GHPoint>(3);
points.add(new GHPoint(lat0, lon0));
points.add(new GHPoint(lat1, lon1));
points.add(new GHPoint(lat2, lon2));
List<Double> favoredHeadings = Arrays.asList(3.14, 4.15, Double.NaN);
List<Double> emptyHeadings = Arrays.asList(Double.NaN, Double.NaN, Double.NaN);
GHRequest instance;
instance = new GHRequest(points, favoredHeadings);
compareFavoredHeadings(instance, favoredHeadings);
assertEquals("Points not initialized correct", points, instance.getPoints());
instance = new GHRequest(points.get(0), points.get(1), favoredHeadings.get(0), favoredHeadings.get(1));
compareFavoredHeadings(instance, favoredHeadings.subList(0, 2));
assertEquals("Points not initialized correct", points.subList(0, 2), instance.getPoints());
instance = new GHRequest(lat0, lon0, lat1, lon1, favoredHeadings.get(0), favoredHeadings.get(1));
compareFavoredHeadings(instance, favoredHeadings.subList(0, 2));
assertEquals("Points not initialized correct", points.subList(0, 2), instance.getPoints());
instance = new GHRequest(3).addPoint(points.get(0), favoredHeadings.get(0)).addPoint(points.get(1), favoredHeadings.get(1)).addPoint(points.get(2), favoredHeadings.get(2));
compareFavoredHeadings(instance, favoredHeadings);
assertEquals("Points not initialized correct", points, instance.getPoints());
instance = new GHRequest().addPoint(points.get(0), favoredHeadings.get(0)).addPoint(points.get(1), favoredHeadings.get(1)).addPoint(points.get(2), favoredHeadings.get(2));
assertEquals("Points not initialized correct", points, instance.getPoints());
compareFavoredHeadings(instance, favoredHeadings);
// check init without favoredHeadings
instance = new GHRequest(points);
assertEquals("Points not initialized correct", points, instance.getPoints());
compareFavoredHeadings(instance, emptyHeadings);
instance = new GHRequest(points.get(0), points.get(1));
assertEquals("Points not initialized correct", points.subList(0, 2), instance.getPoints());
compareFavoredHeadings(instance, emptyHeadings.subList(0, 2));
instance = new GHRequest(lat0, lon0, lat1, lon1);
assertEquals("Points not initialized correct", points.subList(0, 2), instance.getPoints());
compareFavoredHeadings(instance, emptyHeadings.subList(0, 2));
instance = new GHRequest().addPoint(points.get(0)).addPoint(points.get(1)).addPoint(points.get(2));
assertEquals("Points not initialized correct", points, instance.getPoints());
compareFavoredHeadings(instance, emptyHeadings);
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class CompressedArrayTest method testCompress.
@Test
public void testCompress() throws Exception {
CompressedArray arr = new CompressedArray();
arr.write(10, 1);
arr.write(11, 2);
arr.write(12, 3);
arr.flush();
GHPoint coord = arr.get(0);
assertEquals(10, coord.lat, 1e-6);
assertEquals(1, coord.lon, 1e-6);
coord = arr.get(1);
assertEquals(11, coord.lat, 1e-6);
assertEquals(2, coord.lon, 1e-6);
coord = arr.get(2);
assertEquals(12, coord.lat, 1e-6);
assertEquals(3, coord.lon, 1e-6);
assertNull(arr.get(3));
// assertEquals(42, arr.calcMemInMB() * Helper.MB, 1e-3);
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class LinearKeyAlgoTest method testDecode.
@Test
public void testDecode() {
KeyAlgo algo = new LinearKeyAlgo(3, 4).setBounds(-1, 9, -2, 20);
GHPoint latLon = new GHPoint();
// decode that we get the center of the grid cell!
algo.decode(5, latLon);
assertEquals(9, latLon.lat, 1e-7);
assertEquals(2.75, latLon.lon, 1e-7);
algo.decode(2, latLon);
assertEquals(1.66666666, latLon.lat, 1e-7);
assertEquals(5.25, latLon.lon, 1e-7);
algo.decode(11, latLon);
assertEquals(16.3333333, latLon.lat, 1e-7);
assertEquals(7.75, latLon.lon, 1e-7);
algo.decode(10, latLon);
assertEquals(16.3333333, latLon.lat, 1e-7);
assertEquals(5.25, latLon.lon, 1e-7);
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class SpatialKeyAlgoTest method testOddBits.
@Test
public void testOddBits() {
GHPoint coord = new GHPoint();
SpatialKeyAlgo algo = new SpatialKeyAlgo(8);
long key = algo.encode(5, 30);
assertEquals("11000001", BitUtil.BIG.toLastBitString(key, 8));
algo.decode(key, coord);
assertEquals(5.63, coord.lat, 1e-2);
assertEquals(33.75, coord.lon, 1e-2);
algo = new SpatialKeyAlgo(7);
key = algo.encode(11.11, 40.66);
assertEquals("01100000", BitUtil.BIG.toLastBitString(key, 8));
assertEquals(5.63, coord.lat, 1e-2);
assertEquals(33.75, coord.lon, 1e-2);
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperServlet method getPoints.
protected List<GHPoint> getPoints(HttpServletRequest req, String key) {
String[] pointsAsStr = getParams(req, key);
final List<GHPoint> infoPoints = new ArrayList<GHPoint>(pointsAsStr.length);
for (String str : pointsAsStr) {
String[] fromStrs = str.split(",");
if (fromStrs.length == 2) {
GHPoint point = GHPoint.parse(str);
if (point != null)
infoPoints.add(point);
}
}
return infoPoints;
}
Aggregations