[Misc]Tile length, its coordinates and center

Wrda

Spell Reviewer
Level 26
Why is this relevant?
One day I figured I needed a way to know the center of a tile, given an axis coordinate. Such thing isn't available to us directly so I did it myself. Also this is important for our common knowledge that sometimes we take for granted.

Assumptions
Our intuition would say that the length of a tile is exactly 128.00, and that given the tile of the center of the map, which is at 0, 0, would have the edges as 64.00, 64.00, -64.00, -64.00 (up, right, down, left edges respectively).
Upon having a loop to check each edge, this assumption was just wrong. Edges are 63.499, 63.499, -64.500, -64.500 (same order as above), length is 127.999 instead.

Researched method
I delved into a basic method to find out the edges of a tile by alternating between 2 different tile types, and with a loop, which increases an axis point (variable r in test map).

Figuring out the logic
My first attempt was pretty wack, quite inacurate, still useful in certain situations. The second is fully accurate, although it appears to be somewhat slower? Not very significative I hope.
JASS:
``````function GetTileCenter takes real x returns real
local real abs = RAbsBJ(x)
local real mod = ModuloReal(abs, 128.00)
local real multiples = R2I(abs/128)
if mod >= 63.500 and x > 0 then
return (128*(multiples + 1))*RSignBJ(x)
elseif mod >= 64.501 and x < 0 then
return (128*(multiples + 1))*RSignBJ(x)
elseif mod == 0 and multiples >= 1 then
return (128*(multiples))*RSignBJ(x)
endif
return (abs - mod)*RSignBJ(x)
endfunction``````
JASS:
``````function GetTileCenterEx takes real x returns real
local real result = RAbsBJ(x)
if x < 0 then
return (result - ModuloReal(result, 128.00))*-1
endif
return result - ModuloReal(result, 128.00)
endfunction``````
For lua:
Lua:
``````--INACCURATE
---@param x number
---@return number
function GetTileCenterEx(x)
local result = math.abs(x)
if x < 0 then
return (result - math.fmod(result, 128.00))*-1
end
return result - math.fmod(result, 128.00)
end

--FULLY ACCURATE
---@param x number
---@return number
function GetTileCenter(x)
local abs = math.abs(x)
local mod = math.fmod(abs, 128.00)
local multiples = math.floor(abs/128)
local sign = 1
if x < 0 then
sign = -1
end
if mod >= 63.500 and x > 0 then
return (128*(multiples + 1))*sign
elseif mod >= 64.501 and x < 0 then
return (128*(multiples + 1))*sign
elseif mod == 0 and multiples >= 1 then
return (128*(multiples))*sign
end
return (abs - mod)*sign
end``````

You can test it on the test map, just to see that I'm not going crazy..., yet.

Attachments

• Test tiles correctly.w3m
21.5 KB · Views: 21
Last edited:

IcemanBo

Level 38
^ function GetTileCenterCoordinate is supposed to do the same.
Yeh, you're right with length. Edge coordinate precisely is the minimum x/y of one tile, but actually wouldn't belong as maximum of prior tile.

Last edited:

Wrda

Spell Reviewer
Level 26
I had seen this snippet before, but didn't really paid full attention to it
It does work nicely, with a margin of error of 0.501 on max edge, and 0.5 on min edge. Not sure it if it is a big deal.
Anyway, I still think this should be useful for people to be aware how annoying blizzard can be about these details.

Chaosy

Tutorial Reviewer
Level 40
I am hesitant to approve this as it's not really a tutorial but rather a "useful tip"
Also either I am blind or the first function and the accurate function are identical.

Wrda

Spell Reviewer
Level 26
I am hesitant to approve this as it's not really a tutorial but rather a "useful tip"
Yes, definetely not a tutorial, but I didn't find any other appropriate place to post this useful tip or a slight knowledge about something.
Also either I am blind or the first function and the accurate function are identical.
They were, because I'm stupid fixed.

Replies
13
Views
2K
Replies
0
Views
710
Replies
8
Views
25K
Replies
6
Views
717
Replies
22
Views
2K