Listing 3. The getZoomedInCoords() subroutine
sub getZoomedInCoords {
# The Cartesian vector ($x, $y) corresponds to a point in the
# *overview* map
#
my ( $x, $y ) = @_;
# Scale and translate the input Cartesian vector to the Cartesian
# vector corresponding to the top-left and bottom-right corners of
# the frame in the *detailed* map
#
$x = ( $x * RATIO_X ) - HALF_WIDTH;
$y = ( $y * RATIO_Y ) - HALF_HEIGHT;
# Make sure that the point coordinates are inside the image
# boundaries
#
if ( $x < 0 ) {
$x = 0;
}
elsif ( $x > ( ZOOM_IN_WIDTH - CROP_WIDTH ) ) {
$x = ZOOM_IN_WIDTH - CROP_WIDTH;
}
if ( $y < 0 ) {
$y = 0;
}
elsif ( $y > ( ZOOM_IN_HEIGHT - CROP_HEIGHT ) ) {
$y = ZOOM_IN_HEIGHT - CROP_HEIGHT;
}
# Return the top-left and bottom-right coordinates of the bounding box
#
return ( $x, $y, $x+CROP_WIDTH, $y+CROP_HEIGHT );
}