Page 1 of 1
Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Mon Jul 29, 2019 3:13 am
by AngledLuffa
I assume that if I'm given a Position chunk_position, I can convert that to a bounding box by doing x * 32, y * 32, x * 32 + 31, y * 32 + 31. However, it seems kind of hacky to hardcode those numbers, even if the size of a chunk is not likely to ever change.
Ultimately, what I want is a way to get the BoundingBox for on_chunk_charted
https://lua-api.factorio.com/latest/eve ... nk_charted
It's a little unfortunate that on_chunk_charted and on_chunk_generated have different attributes. Is it possible to unify that somehow? Preferably by having the bounding box in both, or at perhaps by adding the bounding box to on_chunk_charted without removing any of its existing attributes.
Re: Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Fri Aug 02, 2019 3:45 am
by kingarthur
seems to be the current way to handle it. for that last part it would need to be a modding interface request and unless there is some particular reason for it the devs should add it.
i would suggest going to
viewforum.php?f=28 and clearly explain exactly what your requesting they add and why. at that point they should take a look at it soonish compared to here where its buried under a sort of question even though its more a feature request
Re: Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Fri Aug 02, 2019 1:33 pm
by eradicator
Code: Select all
for chunk in surface.get_chunks() do
local area = {
left_top = {x = chunk.x*32 , y = chunk.y*32 },
right_bottom = {x = chunk.x*32+32, y = chunk.y*32+32}
}
--dostuff
end
The chunk iterator has the same "problem". Funny enough there's already an
interface request to include the area there too.
Btw, why are you using +31? When i tested with rendering.draw_rectangle the above code seemed to perfectly match the tile grid.
Re: Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Sun Aug 04, 2019 6:02 pm
by AngledLuffa
eradicator wrote: Fri Aug 02, 2019 1:33 pm
Btw, why are you using +31? When i tested with rendering.draw_rectangle the above code seemed to perfectly match the tile grid.
Wasn't sure if it would use < or <= at the end of the range. 32 makes more sense now that you mention it. Thanks!
Re: Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Mon Aug 26, 2019 3:13 pm
by Bilka
AngledLuffa wrote: Mon Jul 29, 2019 3:13 am
Ultimately, what I want is a way to get the BoundingBox for on_chunk_charted
I have added the area to the event for the next version.
Re: Canonical way to convert ChunkPosition -> BoundingBox?
Posted: Mon Aug 26, 2019 4:27 pm
by AngledLuffa
Thank you, that's perfect!