Page 1 of 1

Do we need so many variants of position and area?

Posted: Wed Oct 19, 2016 5:45 pm
by aubergine18

Code: Select all

-- position formats:

(x, y) -- methods only
{x, y}
{x=x, y=y}

-- area formats:

{{x,y}, {x,y}}
{{x=x, y=y}, {x=x, y=y}}
{left_top = {x,y}, right_bottom = {x,y}}
{left_top = {x=x, y=y}, right_bottom = {x=x, y=y}}
Would it be easier to make everything use a single format for position objects and a single format for table objects?

Code: Select all

local x, y, lt, rb = 1, 2, 1, 2

pos = {3,4}
area = {{5,6}, {7,8}}

pos[x] -- pos[1] = 3
aera[rb][y] -- area[2][2] = 8
This would make working with positions, and especially areas, much easier as there's only ever one format for the objects. It's also consistent with the way prototype collision_box, selection_box, window_box, etc., are defined.

The downside is that code becomes slightly less legible (example: `foo[x]` or `foo[1]` instead of `foo.x`), but it will remove loads of branching code, particularly in reuseable library functions (eg. Factorio StdLib) and remote interfaces. It will also simplify documentation - all areas and positions will be same format. Methods that currently take an (x,y) will change to only accept {x,y}, etc. That's going to break many mods, but it's trivial type of thing to fix.

Maybe something to consider for 0.15?

Related discussion on github: https://github.com/Afforess/Factorio-St ... -254750890