2011-07-03 15:08:34 +02:00
|
|
|
package net.osmand.router;
|
|
|
|
|
2012-06-20 20:14:36 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-06-14 20:52:03 +02:00
|
|
|
import net.osmand.binary.RouteDataObject;
|
2011-07-03 15:08:34 +02:00
|
|
|
import net.osmand.osm.LatLon;
|
2012-06-11 22:28:57 +02:00
|
|
|
import net.osmand.osm.MapUtils;
|
2011-07-03 15:08:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
public class RouteSegmentResult {
|
2012-06-20 20:14:36 +02:00
|
|
|
private final RouteDataObject object;
|
|
|
|
private final int startPointIndex;
|
|
|
|
private final int endPointIndex;
|
|
|
|
private final List<RouteSegmentResult>[] attachedRoutes;
|
2012-06-11 22:28:57 +02:00
|
|
|
private float segmentTime;
|
2012-06-17 23:48:36 +02:00
|
|
|
private float speed;
|
2012-06-19 19:13:34 +02:00
|
|
|
private float distance;
|
2012-06-20 20:14:36 +02:00
|
|
|
private String description = "";
|
2012-06-11 22:28:57 +02:00
|
|
|
|
2012-06-20 20:14:36 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-06-11 22:28:57 +02:00
|
|
|
public RouteSegmentResult(RouteDataObject object, int startPointIndex, int endPointIndex) {
|
|
|
|
this.object = object;
|
|
|
|
this.startPointIndex = startPointIndex;
|
|
|
|
this.endPointIndex = endPointIndex;
|
2012-06-20 20:14:36 +02:00
|
|
|
int capacity = Math.abs(endPointIndex - startPointIndex) + 1;
|
|
|
|
this.attachedRoutes = new List[capacity];
|
|
|
|
}
|
|
|
|
|
|
|
|
public void attachRoute(int roadIndex, RouteSegmentResult r){
|
|
|
|
int st = startPointIndex < endPointIndex ? startPointIndex : endPointIndex;
|
|
|
|
if(attachedRoutes[roadIndex - st] == null) {
|
|
|
|
attachedRoutes[roadIndex - st] = new ArrayList<RouteSegmentResult>();
|
|
|
|
}
|
|
|
|
attachedRoutes[roadIndex - st].add(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<RouteSegmentResult> getAttachedRoutes(int routeInd) {
|
|
|
|
int st = startPointIndex < endPointIndex ? startPointIndex : endPointIndex;
|
|
|
|
List<RouteSegmentResult> list = attachedRoutes[routeInd - st];
|
|
|
|
if(list == null) {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
return list;
|
2012-06-11 22:28:57 +02:00
|
|
|
}
|
|
|
|
|
2012-06-20 20:14:36 +02:00
|
|
|
|
2012-06-11 22:28:57 +02:00
|
|
|
public RouteDataObject getObject() {
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getSegmentTime() {
|
|
|
|
return segmentTime;
|
|
|
|
}
|
|
|
|
|
2012-06-19 19:13:34 +02:00
|
|
|
public float getBearingBegin() {
|
|
|
|
return (float) (object.directionRoute(startPointIndex, startPointIndex < endPointIndex) / Math.PI * 180);
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getBearingEnd() {
|
|
|
|
return (float) (MapUtils.alignAngleDifference(object.directionRoute(endPointIndex, startPointIndex > endPointIndex) - Math.PI) / Math.PI * 180);
|
|
|
|
}
|
|
|
|
|
2012-06-11 22:28:57 +02:00
|
|
|
public void setSegmentTime(float segmentTime) {
|
|
|
|
this.segmentTime = segmentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LatLon getStartPoint() {
|
|
|
|
return convertPoint(object, startPointIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getStartPointIndex() {
|
|
|
|
return startPointIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getEndPointIndex() {
|
|
|
|
return endPointIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LatLon getPoint(int i) {
|
|
|
|
return convertPoint(object, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public LatLon getEndPoint() {
|
|
|
|
return convertPoint(object, endPointIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
private LatLon convertPoint(RouteDataObject o, int ind){
|
|
|
|
return new LatLon(MapUtils.get31LatitudeY(o.getPoint31YTile(ind)), MapUtils.get31LongitudeX(o.getPoint31XTile(ind)));
|
|
|
|
}
|
2012-06-17 23:48:36 +02:00
|
|
|
|
|
|
|
public void setSegmentSpeed(float speed) {
|
|
|
|
this.speed = speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getSegmentSpeed() {
|
|
|
|
return speed;
|
|
|
|
}
|
|
|
|
|
2012-06-19 19:13:34 +02:00
|
|
|
public float getDistance() {
|
|
|
|
return distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDistance(float distance) {
|
|
|
|
this.distance = distance;
|
|
|
|
}
|
|
|
|
|
2012-06-20 20:14:36 +02:00
|
|
|
public String getDescription() {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDescription(String description) {
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
2012-06-17 23:48:36 +02:00
|
|
|
|
|
|
|
|
2011-07-03 15:08:34 +02:00
|
|
|
}
|