1. In this case, since W/H < Aw/Ah, we can either increase W or decrease H to increase the ratio, as is done in the two branches of the if statement. What's the rationale behind using the relation between W and H to decide whether to change W or H?
2. What's the logic behind the formula in DeltaX (and DeltaY respectively)? If we want W/H to reach Aw/Ah we could increase W by error/Ah, so it's not clear why we need the other terms (the proposed formula leads to an increase of error/Ah + 1 + 1/Ah).
It would be good to add a comment documenting how the proposed computations and decisions work.
122+ auto const error = new_size. height. as_int( )*(long) ar.width - new_size. width.as_ int()*( long)ar. height; height. as_int( ) > new_size. width.as_ int()) (error+ (ar.height- 1))/ar. height) ; (error+ (ar.width- 1))/ar. width);
123+
124+ if (error > 0)
125+ {
126+ if (new_size.
127+ {
128+ new_size.width = new_size.width + DeltaX(
129+ }
130+ else
131+ {
132+ new_size.height = new_size.height - DeltaY(
133+ }
134+ }
Some questions (Aw=aspect W, Ah=aspect H):
1. In this case, since W/H < Aw/Ah, we can either increase W or decrease H to increase the ratio, as is done in the two branches of the if statement. What's the rationale behind using the relation between W and H to decide whether to change W or H?
2. What's the logic behind the formula in DeltaX (and DeltaY respectively)? If we want W/H to reach Aw/Ah we could increase W by error/Ah, so it's not clear why we need the other terms (the proposed formula leads to an increase of error/Ah + 1 + 1/Ah).
It would be good to add a comment documenting how the proposed computations and decisions work.