package de.daggit.domap.stitch

import groovy.util.logging.Log

import javax.imageio.ImageIO
import java.awt.image.BufferedImage

/**
 * Created by jbialek on 13.07.16.
 */
@Log
class Tile {
    String tmpDir
    int u
    int v

    double x1
    double y1
    double x2
    double y2

    File imgFile

    double getWidth() {
        return x2-x1
    }
    double getHeight() {
        return y2-y1
    }

    @Override
    String toString() {
        return [x1,y1,x2,y2].join(",")
    }

    void setImageFile(File file) {
        imgFile = file
    }
    BufferedImage getImage() {
        if (imgFile.exists()) {
            return ImageIO.read(imgFile)
        }
        return null
    }
    boolean isLastX() {
        BufferedImage img = image
        def a = img.raster.getPixel(image.width -1, 0, null as int[])
        return a[0] == 0
    }
    boolean isLastY() {
        def a = image.raster.getPixel(0, 0, null as int[])
        return a[0] == 0
    }

    def test() {
        def a = 9
        def x = a <= 9
        return 1 != 3
    }
}
