SegmentedArea.java

package ac.essex.ooechs.imaging.commons; 
 
public class SegmentedArea { 
    int left, top, width, height; 
 
    int colour = Colours.UNKNOWN_COLOUR; 
 
    public SegmentedArea(int left, int top, int width, int height) { 
        this.left = left; 
        this.top = top; 
        this.width = width; 
        this.height = height; 
    } 
 
    public int size() { 
        return width * height; 
    } 
 
    public boolean nearEdge(int imageWidth, int imageHeight) { 
 
        int pLeft = (int) ((((double) left) / imageWidth) * 100); 
        int pTop = (int) ((((double) top) / imageHeight) * 100); 
        int pRight = (int) ((((double) (left + width)) / imageWidth) * 100); 
        int pBottom = (int) ((((double)(top + height)) / imageHeight) * 100); 
 
        // 10% 
        double threshold = 15; 
 
        if (pLeft < threshold) return true; 
        if (pTop < threshold) return true; 
        if (pBottom > (100 - threshold)) return true; 
        if (pRight > (100 - threshold)) return true; 
 
        return false; 
    } 
 
    public int getColour() { 
        return colour; 
    } 
 
    public void setColour(int colour) { 
        this.colour = colour; 
    } 
 
    public String toString() { 
        return "Left: " + left + ", Top: " + top + ", Width: " + width + ", Height: " + height + ", Colour: " + Colours.colourToString(colour); 
    } 
 
 
 
 
}