Workspace/Coding labs
Loading progress

Map a screenshot target

Intermediate50 min

Implement map_point(point, image_size, region). The image has width and height; region is logical origin x, origin y, width, height. Map the image point with independent x and y scale plus origin translation. Require finite numeric values and strictly positive dimensions; require half-open image bounds. Return a float-compatible coordinate pair. Origins may be negative. Raise ValueError for invalid inputs. No pointer movement occurs.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Input(600,100), image=(800,400), region=(100,50,400,200)

Output(400.0,100.0)

Normalize, scale, then add the crop origin.
EXAMPLE 2

Input(0,0), image=(10,10), region=(-20,5,100,100)

Output(-20.0,5.0)

The logical origin can be negative.
solution.pyPython 3.12