class Quad {
constructor(x, y, w, h) {
const [r, g, b, error] = colorFromHistogram(computeHistogram(x, y, w, h));
this.x = x, this.y = y, this.w = w, this.h = h;
this.color = `#${(0x1000000 + (r << 16) + (g << 8) + b).toString(16).substring(1)}`;
this.score = error * Math.pow(w * h, area_power);
}
split() {
const dx = this.w / 2, x1 = this.x, x2 = this.x + dx;
const dy = this.h / 2, y1 = this.y, y2 = this.y + dy;
return [
new Quad(x1, y1, dx, dy),
new Quad(x2, y1, dx, dy),
new Quad(x1, y2, dx, dy),
new Quad(x2, y2, dx, dy)
];
}
}