Motive:
Im creating an android Application that does the following.
- Reads input points (of type Point - a custom class).
- Calculates the outermost points.
- Draws a polygon (needs input of type GeoPoint from osmdroid library) with those points as the vertices (a convex polygon).
Problem:
I made the algorithm to work. But there is a problem converting the datatypes.
The input is a Point array(Point is a custom class).
geoPoints = new Point[7];
geoPoints[0] = new Point(new GeoPoint(8.180992, 77.336551));
But the osmdroid function that draws the polygon needs List < GeoPoint > as input.
List<GeoPoint> gPoints;
polygon.setPoints(gPoints);
I managed to convert this on the Point() constructor like something below
public Point(GeoPoint geoPoint) {
this.x = geoPoint.getLatitude();
this.y = geoPoint.getLongitude();
}
But I have no idea how work out the return type.
SO, when I run the code. I get the following error.
error: incompatible types: inference variable T has incompatible bounds
equality constraints: GeoPoint
lower bounds: Point
where T is a type-variable:
T extends Object declared in method <T>asList(T...)
Calling Function:
private void callingFunction() {
geoPoints = new Point[7];
geoPoints[0] = new Point(new GeoPoint(8.180992, 77.336551));
geoPoints[1] = new Point(new GeoPoint(8.183966, 77.340353));
geoPoints[2] = new Point(new GeoPoint(8.179836, 77.336105));
geoPoints[3] = new Point(new GeoPoint(8.178744, 77.339179));
geoPoints[4] = new Point(new GeoPoint(8.182155, 77.341925));
geoPoints[5] = new Point(new GeoPoint(8.181655, 77.339318));
geoPoints[6] = new Point(new GeoPoint(8.182155, 77.341925));
polygon = new Polygon(); //see note below
polygon.setFillColor(Color.parseColor("#80FFE082"));
polygon.setStrokeColor(Color.parseColor("#FFD54F"));
polygon.setStrokeWidth(5f);
ConvexHull cx = new ConvexHull(geoPoints);
Point C1[]= cx.getConvexHull();
polygon.setPoints(Arrays.asList(C1));
map.getOverlayManager().add(polygon);
map.invalidate();
}
Note:
Using only List or only Array is not possible as
polygon.setPoints(geoPoints) //needs List<GeoPoint> in callingFunction
Arrays.sort(points); //requires array of Points in ConvexHull
Everything provided. How can I solve this problem? Any sorts of help will be really useful. And Thanks in advance.