Skip to content

refactor: enhance ComputerToolBase functionality and add coordinate s…#102

Closed
danyalxahid-askui wants to merge 2 commits intoCL-1377-chat-enable-agent-to-search-through-displayfrom
feat/cursor-position-support
Closed

refactor: enhance ComputerToolBase functionality and add coordinate s…#102
danyalxahid-askui wants to merge 2 commits intoCL-1377-chat-enable-agent-to-search-through-displayfrom
feat/cursor-position-support

Conversation

@danyalxahid-askui
Copy link
Contributor

…caling

  • Added _get_mouse_position_scaled method to ComputerToolBase for retrieving and scaling mouse position.
  • Updated action method to return scaled mouse position.
  • Introduced scale_coordinates_with_padding function in image_utils.py for scaling coordinates with padding.
  • Cleaned up import statements for better organization and readability.

…caling

- Added `_get_mouse_position_scaled` method to `ComputerToolBase` for retrieving and scaling mouse position.
- Updated `action` method to return scaled mouse position.
- Introduced `scale_coordinates_with_padding` function in `image_utils.py` for scaling coordinates with padding.
- Cleaned up import statements for better organization and readability.
- Modified the return type of the `action` method in `Computer20250124Tool` to include `Coordinate` in addition to `Image.Image | None`, enhancing its functionality to return more comprehensive results.
@adi-wan-askui adi-wan-askui self-requested a review July 25, 2025 08:34
Copy link
Contributor

@adi-wan-askui adi-wan-askui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work :)

Comment on lines +201 to +218
"""Convert coordinates from an original image to a scaled and padded image.

This function takes coordinates from the original image and calculates
their corresponding position in an image that has been scaled and
padded to fit within `max_width` and `max_height`.

Args:
x (float): The x-coordinate in the original image.
y (float): The y-coordinate in the original image.
original_width (int): The width of the original image.
original_height (int): The height of the original image.
max_width (int): The maximum width of the output scaled and padded image.
max_height (int): The maximum height of the output scaled and padded image.

Returns:
Tuple[float, float]: A tuple of (scaled_x, scaled_y) coordinates
in the padded image.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should adapt the docstring as it talks about an image where there is none 😆

Comment on lines +235 to +238
if scaled_x < 0 or scaled_y < 0 or scaled_x > max_width or scaled_y > max_height:
error_msg = "Coordinates are outside the padded image area"
raise ValueError(error_msg)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this even happen? Looks to me like this can be removed.

)


def scale_coordinates_with_padding(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse this inside the scale_image_with_padding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants