use of net.osmand.data.QuadPoint in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method projectDistance.
protected double projectDistance(List<RouteSegmentResult> res, int k, int px, int py) {
RouteSegmentResult sr = res.get(k);
RouteDataObject r = sr.getObject();
QuadPoint pp = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(sr.getStartPointIndex()), r.getPoint31YTile(sr.getStartPointIndex()), r.getPoint31XTile(sr.getEndPointIndex()), r.getPoint31YTile(sr.getEndPointIndex()));
double currentsDist = squareDist((int) pp.x, (int) pp.y, px, py);
return currentsDist;
}
use of net.osmand.data.QuadPoint in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method updateResult.
private void updateResult(RouteSegmentResult routeSegmentResult, LatLon point, boolean st) {
int px = MapUtils.get31TileNumberX(point.getLongitude());
int py = MapUtils.get31TileNumberY(point.getLatitude());
int pind = st ? routeSegmentResult.getStartPointIndex() : routeSegmentResult.getEndPointIndex();
RouteDataObject r = routeSegmentResult.getObject();
QuadPoint before = null;
QuadPoint after = null;
if (pind > 0) {
before = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind - 1), r.getPoint31YTile(pind - 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
}
if (pind < r.getPointsLength() - 1) {
after = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(pind + 1), r.getPoint31YTile(pind + 1), r.getPoint31XTile(pind), r.getPoint31YTile(pind));
}
int insert = 0;
double dd = MapUtils.getDistance(point, MapUtils.get31LatitudeY(r.getPoint31YTile(pind)), MapUtils.get31LongitudeX(r.getPoint31XTile(pind)));
double ddBefore = Double.POSITIVE_INFINITY;
double ddAfter = Double.POSITIVE_INFINITY;
QuadPoint i = null;
if (before != null) {
ddBefore = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) before.y), MapUtils.get31LongitudeX((int) before.x));
if (ddBefore < dd) {
insert = -1;
i = before;
}
}
if (after != null) {
ddAfter = MapUtils.getDistance(point, MapUtils.get31LatitudeY((int) after.y), MapUtils.get31LongitudeX((int) after.x));
if (ddAfter < dd && ddAfter < ddBefore) {
insert = 1;
i = after;
}
}
if (insert != 0) {
if (st && routeSegmentResult.getStartPointIndex() < routeSegmentResult.getEndPointIndex()) {
routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
}
if (!st && routeSegmentResult.getStartPointIndex() > routeSegmentResult.getEndPointIndex()) {
routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
}
if (insert > 0) {
r.insert(pind + 1, (int) i.x, (int) i.y);
if (st) {
routeSegmentResult.setStartPointIndex(routeSegmentResult.getStartPointIndex() + 1);
}
if (!st) {
routeSegmentResult.setEndPointIndex(routeSegmentResult.getEndPointIndex() + 1);
}
} else {
r.insert(pind, (int) i.x, (int) i.y);
}
}
}
use of net.osmand.data.QuadPoint in project Osmand by osmandapp.
the class RoutePlannerFrontEnd method findRouteSegment.
public RouteSegmentPoint findRouteSegment(double lat, double lon, RoutingContext ctx, List<RouteSegmentPoint> list) throws IOException {
int px = MapUtils.get31TileNumberX(lon);
int py = MapUtils.get31TileNumberY(lat);
ArrayList<RouteDataObject> dataObjects = new ArrayList<RouteDataObject>();
ctx.loadTileData(px, py, 17, dataObjects);
if (dataObjects.isEmpty()) {
ctx.loadTileData(px, py, 15, dataObjects);
}
if (list == null) {
list = new ArrayList<BinaryRoutePlanner.RouteSegmentPoint>();
}
for (RouteDataObject r : dataObjects) {
if (r.getPointsLength() > 1) {
RouteSegmentPoint road = null;
for (int j = 1; j < r.getPointsLength(); j++) {
QuadPoint pr = MapUtils.getProjectionPoint31(px, py, r.getPoint31XTile(j - 1), r.getPoint31YTile(j - 1), r.getPoint31XTile(j), r.getPoint31YTile(j));
double currentsDistSquare = squareDist((int) pr.x, (int) pr.y, px, py);
if (road == null || currentsDistSquare < road.distSquare) {
RouteDataObject ro = new RouteDataObject(r);
road = new RouteSegmentPoint(ro, j, currentsDistSquare);
road.preciseX = (int) pr.x;
road.preciseY = (int) pr.y;
}
}
if (road != null) {
list.add(road);
}
}
}
Collections.sort(list, new Comparator<RouteSegmentPoint>() {
@Override
public int compare(RouteSegmentPoint o1, RouteSegmentPoint o2) {
return Double.compare(o1.distSquare, o2.distSquare);
}
});
if (list.size() > 0) {
RouteSegmentPoint ps = list.get(0);
ps.others = list;
return ps;
}
return null;
}
use of net.osmand.data.QuadPoint in project Osmand by osmandapp.
the class MapUtils method getProjectionPoint31.
public static QuadPoint getProjectionPoint31(int px, int py, int st31x, int st31y, int end31x, int end31y) {
double projection = calculateProjection31TileMetric(st31x, st31y, end31x, end31y, px, py);
double mDist = measuredDist31(end31x, end31y, st31x, st31y);
int pry = end31y;
int prx = end31x;
if (projection < 0) {
prx = st31x;
pry = st31y;
} else if (projection >= mDist * mDist) {
prx = end31x;
pry = end31y;
} else {
prx = (int) (st31x + (end31x - st31x) * (projection / (mDist * mDist)));
pry = (int) (st31y + (end31y - st31y) * (projection / (mDist * mDist)));
}
return new QuadPoint(prx, pry);
}
use of net.osmand.data.QuadPoint in project Osmand by osmandapp.
the class MapContextMenuFragment method getAdjustedMarkerLocation.
private LatLon getAdjustedMarkerLocation(int y, LatLon reqMarkerLocation, boolean center, int zoom) {
double markerLat = reqMarkerLocation.getLatitude();
double markerLon = reqMarkerLocation.getLongitude();
RotatedTileBox box = getBox();
// box.setCenterLocation(0.5f, map.getMapPosition() == OsmandSettings.BOTTOM_CONSTANT ? 0.15f : 0.5f);
box.setZoom(zoom);
int markerMapCenterX = (int) box.getPixXFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
int markerMapCenterY = (int) box.getPixYFromLatLon(mapCenter.getLatitude(), mapCenter.getLongitude());
float cpyOrig = box.getCenterPixelPoint().y;
box.setCenterLocation(0.5f, 0.5f);
int markerX = (int) box.getPixXFromLatLon(markerLat, markerLon);
int markerY = (int) box.getPixYFromLatLon(markerLat, markerLon);
QuadPoint cp = box.getCenterPixelPoint();
float cpx = cp.x;
float cpy = cp.y;
float cpyDelta = menu.isLandscapeLayout() ? 0 : cpyOrig - cpy;
markerY += cpyDelta;
y += cpyDelta;
float origMarkerY = this.origMarkerY + cpyDelta;
LatLon latlon;
if (center) {
latlon = reqMarkerLocation;
} else {
latlon = box.getLatLonFromPixel(markerMapCenterX, markerMapCenterY);
}
if (menu.isLandscapeLayout()) {
int x = menu.getLandscapeWidthPx();
if (markerX - markerPaddingXPx < x || markerX > origMarkerX) {
int dx = (x + markerPaddingXPx) - markerX;
int dy = 0;
if (center) {
dy = (int) cpy - markerY;
} else {
cpy = cpyOrig;
}
if (dx >= 0 || center) {
latlon = box.getLatLonFromPixel(cpx - dx, cpy - dy);
}
}
} else {
if (markerY + markerPaddingPx > y || markerY < origMarkerY) {
int dx = 0;
int dy = markerY - (y - markerPaddingPx);
if (markerY - dy <= origMarkerY) {
if (center) {
dx = markerX - (int) cpx;
}
latlon = box.getLatLonFromPixel(cpx + dx, cpy + dy);
}
}
}
return latlon;
}
Aggregations