Help needed to calculate distance of equal pixel distribution

13 Views Asked by At

I came across a layout with a mathematical problem. I have made all my shapes to have 3 pixel gap between them, the problem I'm facing is:

1)3 Green squares are 17x17px,but I'm left with 1px gap. (Where Red arrow is pointing).

2)Teal colour boxes 30x30px and do have 3 pixels gap, but obviously they're too big. So they go beyond the boundaries of the Orange square. Need to fit them within the Orange square with 3 pixel gap.

I cant figure out how to correct this problem. What do I need to calculate first so all the shapes can have 3px distance between them.

Thank you.

enter image description here