-
Notifications
You must be signed in to change notification settings - Fork 54
refactor: enhance ComputerToolBase functionality and add coordinate s… #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
danyalxahid-askui
wants to merge
2
commits into
CL-1377-chat-enable-agent-to-search-through-display
from
feat/cursor-position-support
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,55 @@ def scale_image_with_padding( | |
| ) | ||
|
|
||
|
|
||
| def scale_coordinates_with_padding( | ||
| x: float, | ||
| y: float, | ||
| original_width: int, | ||
| original_height: int, | ||
| max_width: int, | ||
| max_height: int, | ||
| ) -> Tuple[float, float]: | ||
| """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. | ||
| """ | ||
|
Comment on lines
+201
to
+218
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should adapt the docstring as it talks about an |
||
| aspect_ratio = original_width / original_height | ||
| if (max_width / max_height) > aspect_ratio: | ||
| scale_factor = max_height / original_height | ||
| scaled_width = int(original_width * scale_factor) | ||
| scaled_height = max_height | ||
| else: | ||
| scale_factor = max_width / original_width | ||
| scaled_width = max_width | ||
| scaled_height = int(original_height * scale_factor) | ||
|
|
||
| pad_left = (max_width - scaled_width) // 2 | ||
| pad_top = (max_height - scaled_height) // 2 | ||
|
|
||
| scaled_x = x * scale_factor + pad_left | ||
| scaled_y = y * scale_factor + pad_top | ||
|
|
||
| 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) | ||
|
|
||
|
Comment on lines
+235
to
+238
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this even happen? Looks to me like this can be removed. |
||
| return scaled_x, scaled_y | ||
|
|
||
|
|
||
| def scale_coordinates_back( | ||
| x: float, | ||
| y: float, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?