com.github.davidmoten.grumpy.wms.reduction.RectangleUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grumpy-ogc Show documentation
Show all versions of grumpy-ogc Show documentation
OGC tools including WMS server
package com.github.davidmoten.grumpy.wms.reduction;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
public class RectangleUtil {
public static List corners(Rectangle region) {
List list = new ArrayList();
list.add(new Point(region.x, region.y));
list.add(new Point(region.x, region.y + region.height));
list.add(new Point(region.x + region.width, region.y));
list.add(new Point(region.x + region.width, region.y + region.height));
return list;
}
public static List splitHorizontally(Rectangle region) {
List list = new ArrayList();
int halfWidth = region.width / 2;
list.add(new Rectangle(region.x, region.y, halfWidth, region.height));
list.add(new Rectangle(region.x + halfWidth, region.y, region.width - halfWidth,
region.height));
return list;
}
public static List splitVertically(Rectangle region) {
List list = new ArrayList();
int halfHeight = region.height / 2;
list.add(new Rectangle(region.x, region.y, region.width, halfHeight));
list.add(new Rectangle(region.x, region.y + halfHeight, region.width, region.height
- halfHeight));
return list;
}
public static List quarter(Rectangle region) {
List list = new ArrayList();
for (Rectangle r : splitHorizontally(region))
list.addAll(splitVertically(r));
return list;
}
}