Open the context
Choose the project folder and name the files or behavior involved.
Fit an image into a pixel box using integer dimensions from 1 through 1000000. Test portrait, landscape and odd padding, rejecting a subpixel result and rounding the scaled size down before centering.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def fit_box(image_width, image_height, box_width, box_height):
values = (image_width,image_height,box_width,box_height)
if any(type(v) is not int or not 1 <= v <= 1000000 for v in values):
raise ValueError("dimensions 1 through 1000000")
if image_width*box_height > image_height*box_width:
width, height = box_width, image_height*box_width//image_width
else:
width, height = image_width*box_height//image_height, box_height
if not width or not height: raise ValueError("subpixel result")
return (box_width-width)//2, (box_height-height)//2, width, heightThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.