All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.davidmoten.grumpy.wms.reduction.RectangleUtil Maven / Gradle / Ivy

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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy