package org.kne.codec.kif;

import java.util.ArrayList;
import java.util.List;

/**
 * 分块坐标信息（仅包含位置和尺寸，不包含实际像素数据）
 */
public class BlockCoord {
    private final int posX;
    private final int posY;
    private final int width;
    private final int height;
    
    public BlockCoord(int posX, int posY, int width, int height) {
        this.posX = posX;
        this.posY = posY;
        this.width = width;
        this.height = height;
    }
    
    public int getPosX() { return posX; }
    public int getPosY() { return posY; }
    public int getWidth() { return width; }
    public int getHeight() { return height; }
    
    @Override
    public String toString() {
        return String.format("BlockCoord(%d,%d,%dx%d)", posX, posY, width, height);
    }
    
	// ==================== 分块坐标计算 ====================

	public static List<BlockCoord> calculateBlockCoords(int width, int height, int blockWidth, int blockHeight) {
		int blocksX = (width + blockWidth - 1) / blockWidth;
		int blocksY = (height + blockHeight - 1) / blockHeight;
		List<BlockCoord> coords = new ArrayList<>(blocksX * blocksY);

		for (int by = 0; by < blocksY; by++) {
			for (int bx = 0; bx < blocksX; bx++) {
				int posX = bx * blockWidth;
				int posY = by * blockHeight;
				int bw = Math.min(blockWidth, width - posX);
				int bh = Math.min(blockHeight, height - posY);
				coords.add(new BlockCoord(posX, posY, bw, bh));
			}
		}
		return coords;
	}
}