Distributing integers using weights? How to calculate?

前端 未结 4 398
鱼传尺愫
鱼传尺愫 2020-12-10 09:03

I need to distribute a value based on some weights. For example, if my weights are 1 and 2, then I would expect the column weighted as 2 to have twice the value as the colum

4条回答
  •  情深已故
    2020-12-10 09:50

    You have to distribute the rounding errors somehow:

    Actual:
    | |   |     |
    
    Pixel grid:
    |   |   |   |
    

    The simplest would be to round each true value to the nearest pixel, for both the start and end position. So, when you round up block A 0.5 to 1, you also change the start position of the block B from 0.5 to 1. This decreases the size of B by 0.5 (in essence, "stealing" the size from it). Of course, this leads you to having B steal size from C, ultimately resulting in having:

    |   |   |   |
    

    but how else did you expect to divide 3 into 3 integral parts?

提交回复
热议问题