+ private static Pair<Pair<Double,Double>,Pair<Double,Double>> getBounds(List<Pair<Double,Double>> aList) {
+ Pair<Double,Double> first = aList.get(0);
+ double minx= first.getFirst();
+ double maxx = minx;
+ double miny = first.getSecond();
+ double maxy = miny;
+
+ for (int i = 0; i < aList.size(); i++) {
+ Pair<Double,Double> value = aList.get(i);
+ minx = Math.min(minx, value.getFirst());
+ maxx = Math.max(maxx, value.getFirst());
+ miny = Math.min(miny, value.getSecond());
+ maxy = Math.max(maxy, value.getSecond());
+ }
+ if ( maxx == minx ) {
+ maxx += 1.0; // to avoid problems.
+ }
+ if ( maxy == miny ) {
+ maxy += 1.0; // to avoid problems.
+ }
+ final double paddingFactor = 0.3; // allow some space around min and max
+ return new Pair<Pair<Double,Double>,Pair<Double,Double>>(
+ new Pair<Double,Double>( minx - paddingFactor*(maxx-minx),
+ maxx + paddingFactor*(maxx-minx)),
+ new Pair<Double,Double>( miny - paddingFactor*(maxy-miny),
+ maxy + paddingFactor*(maxy-miny))
+ );
+ }