chellymehdi / vopenlayers

Automatically exported from code.google.com/p/vopenlayers
0 stars 0 forks source link

constructor Bounds(Point[]) does not work as one would expect #123

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Let's assume v defines a polygon. v is an instance of Area class.
2. create bounding box of v as follows: 
Bounds bb = new Bounds(v.getPoints());

What is the expected output? 
bb is the bounding box polygon v lies in.

What do you see instead?
max/min latitudes of bb are 90/-90 correspondingly.

What version of the product are you using? 
1.3.0

On what operating system?
Windows 7 Enterprise SP 1

Solution:

Bounds bb = getBounds(new Bounds(), v.getPoints());

    private Bounds getBounds(Bounds bounds, Point[] points) {
        if (points == null || points.length == 0){
            return bounds;
        }

        double maxLat = points[0].getLat();
        double minLat = points[0].getLat();

        double maxLon = points[0].getLon();
        double minLon = points[0].getLon();

        for (Point point : points) {
            minLat = Math.min(minLat, point.getLat());
            minLon = Math.min(minLon, point.getLon());
            maxLat = Math.max(maxLat, point.getLat());
            maxLon = Math.max(maxLon, point.getLon());
        }

        bounds.setMaxLat(maxLat);
        bounds.setMaxLon(maxLon);
        bounds.setMinLat(minLat);
        bounds.setMinLon(minLon);

        return bounds;
    }

Original issue reported on code.google.com by womba...@gmail.com on 2 Apr 2013 at 9:41

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r222.

Original comment by ma...@vaadin.com on 16 Apr 2013 at 2:21