すべての領域を優先順位を付けて保存し、ピクセルごとにコストを取得することで、これに取り組みます。
したがって、単一ピクセルのコストは次のようになります。
select c.*
from costs c
where PIXELX between c.x and c.x + c.deltax and PIXELY between c.y + c.deltay
order by priority desc
limit 1
これをピクセルの領域に拡張するには、領域を一連のピクセルに拡張します。numbers
これに役立つ表を用意することをお勧めします。
select x.num as x, y.num as y
from numbers x cross join
numbers y
where x.num between PIXELX and PIXELX and DELTAX and
y.num between PIXELY and PIXELY and DELTAY
次に、これらのアイデアを組み合わせて、特定のピクセルに対して考えられるすべてのコストを取得します。
select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
最後に、指定された優先度のコストを結合します。
select sum(c.cost)
from (select x.num as x, y.num as y, max(priority) as maxpriority
from numbers x cross join
numbers y join
costs c
on x.num between c.x and c.x + c.deltax and y.num between c.y + c.deltay
where x.value between PIXELX and PIXELX and DELTAX and
y.value between PIXELY and PIXELY and DELTAY
group by x.num, y.num
) xyp join
costs c
on xyp.x between c.x and c.x + c.deltax and xyp.y between c.y + c.deltay and
xyp.maxpriority = c.priority