1

I am a little familar with MySQL but thinking about implementing this feature makes my brain hurt. I need a system where you can set the "cost" of an area say between the coordinates X=20 Y=20 WIDTH=20 HEIGHT=20 at cost of 15 per pixel, now if you place another area within this area, say at X=25, Y=25, WIDTH=10, HEIGHT=10 at cost of 5 per pixel the previous area is broken down into 4 parts and the middle is wiped in favor of this area.

I would also like to be able to calculate the "cost" of an area between certain pixels. Hope I've explained that in a manner most of you will understand. I have no idea where to start.

4

2 回答 2

2

我会通过优先存储所有区域然后逐个像素地获取成本来解决这个问题。

因此,单个像素的成本为:

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
于 2013-04-15T21:00:46.530 回答
-1

考虑实现这个功能让我的大脑受伤

对,我的也是!嗯……这听起来确实很熟悉——因为它以前在百万美元主页上做过

也许您可以改为使用或调整预制解决方案,例如Gpix或谷歌“像素广告脚本”。

于 2013-04-16T13:52:46.230 回答