Math How many boxes can fit in area
lets say I have a viewport with a width of 1000px
And in the viewport I have 3 boxes placed horizontally along the viewport.
Each box is 500px. Now normally it would be viewport_width / box_width
which would yield 2
How ever, if you were to move the fir开发者_开发技巧st box slightly to the left, out of the viewport, the 3rd box would be slightly visible on the right hand side.
What equasion would i need to use to figure out the maximum number of boxes which can be visible in the defined viewport (assume all boxes are the same width)
Thanks
I'm pretty sure you already have it figured out. Since there can only ever be 1 partial box on either end, the maximum number of visible boxes should be (viewport_width / box_width) + 1
To take into account Will's (correct) caveat:
ceil((viewport_width/box_width) + 1))
Edit: convinced myself that ceil is in fact the correct choice
It's the same math, really. You seem to be thinking of fractional boxes as if being able to see 50% of box A, 100% of box B, and 50% of box C is more than two boxes, total, but it's not. The equation is unchanged.
精彩评论