admin管理员组文章数量:1123054
I'm implementing a Manhattan Voronoi diagram in Love2D, where regions are divided based on the Manhattan distance from a set of given sites. However, I'm encountering an issue when two or more sites are located on the same diagonal. In such cases, some grid cells are marked as 'tie' regions and displayed as black areas, which I want to avoid.
I understand that the problem occurs because the Manhattan distances to these sites are equal for certain points on the grid. Here's my current findClosestSite function:
function findClosestSite(x, y, sites)
local minDistance = math.huge
local closestSite = nil
local isTie = false
for _, site in ipairs(sites) do
local distance = math.abs(x - site[1]) + math.abs(y - site[2])
if distance < minDistance then
minDistance = distance
closestSite = site
isTie = false
elseif distance == minDistance then
isTie = true
end
end
return closestSite, isTie
end
In the case of a tie, I currently mark the cell as black. I'd like to resolve ties by prioritizing one of the sites.
How can I modify my function to handle ties in a robust way, or are there better approaches for resolving this issue in Manhattan Voronoi diagram?
本文标签: luaManhattan Voronoi Diagram Resolving Ties When Sites Are on the Same DiagonalStack Overflow
版权声明:本文标题:lua - Manhattan Voronoi Diagram: Resolving Ties When Sites Are on the Same Diagonal - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736543168a1944412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论