Skip to content
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

feat: added the geometric operations to BoundingBox #136

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

PeterStaar-IBM
Copy link
Contributor

No description provided.

Copy link

mergify bot commented Jan 28, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

Wonderful, this rule succeeded.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@PeterStaar-IBM PeterStaar-IBM changed the title added the geometric operations Added the geometric operations to BoundingBox Jan 28, 2025
Copy link
Contributor

@cau-git cau-git left a comment

Choose a reason for hiding this comment

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

I like that we get more functions but we should never add page_height as an argument, neither to existing nor to new methods. If the "other" bbox does not agree in coord_origin with the self bbox, it must raise an exception instead. It is user business to ensure this beforehand.

@dolfim-ibm
Copy link
Contributor

This is also a useful geometric operation to add: https://github.com/DS4SD/docling/blob/main/docling/models/base_model.py#L71

docling_core/types/doc/base.py Outdated Show resolved Hide resolved
docling_core/types/doc/base.py Outdated Show resolved Hide resolved
docling_core/types/doc/base.py Outdated Show resolved Hide resolved
docling_core/types/doc/base.py Outdated Show resolved Hide resolved
docling_core/types/doc/base.py Outdated Show resolved Hide resolved
docling_core/types/doc/base.py Outdated Show resolved Hide resolved
@dolfim-ibm
Copy link
Contributor

Just mentioning here one possibility that was discussed.

One wish is a simple way of dealing with rescaling from a given page size to a new one. In the current solution this can be done as a combination of .normalize(old_page_size).scale(new_page_size).

Would it worth leaving the scale() and normalize() untouched, and bring a new function

def resize_by_scale(self, x_scale: float, y_scale: float):
    return BoundingBox(
        l=self.l * x_scale,
        r=self.r * x_scale,
        t=self.t * y_scale,
        b=self.b * y_scale,
        coord_origin=self.coord_origin,
    )

def scale_to_size(self, orig_page_size: Size, new_page_size: Size):
    return self.resize_by_scale(x_scale=new_page_size.width/orig_page_size.width, y_scale=new_page_size.height/orig_page_size.height)

# same as before, but using the implementation above
def scale(self, scale: float):
    return self.resize_by_scale(scale, scale)

# same as before, but using the implementation above
def normalized(self, page_size: Size):
    return self.scale_to_size(orig_page_size=page_size, new_page_size=Size(1.0,1.0))

@PeterStaar-IBM
Copy link
Contributor Author

def resize_by_scale(self, x_scale: float, y_scale: float):
    return BoundingBox(
        l=self.l * x_scale,
        r=self.r * x_scale,
        t=self.t * y_scale,
        b=self.b * y_scale,
        coord_origin=self.coord_origin,
    )

def scale_to_size(self, orig_page_size: Size, new_page_size: Size):
    return self.resize_by_scale(x_scale=new_page_size.width/orig_page_size.width, y_scale=new_page_size.height/orig_page_size.height)

# same as before, but using the implementation above
def scale(self, scale: float):
    return self.resize_by_scale(scale, scale)

# same as before, but using the implementation above
def normalized(self, page_size: Size):
    return self.scale_to_size(orig_page_size=page_size, new_page_size=Size(1.0,1.0))

well, that was basically what was originally proposed, just different names. Anyhow, adapted this now ...

@dolfim-ibm
Copy link
Contributor

Tested within Docling here DS4SD/docling#830

@PeterStaar-IBM PeterStaar-IBM changed the title Added the geometric operations to BoundingBox feat: added the geometric operations to BoundingBox Jan 29, 2025
@PeterStaar-IBM PeterStaar-IBM merged commit f02bbae into main Jan 29, 2025
8 checks passed
@PeterStaar-IBM PeterStaar-IBM deleted the dev/add-geometric-operations-in-boundingbox branch January 29, 2025 10:11
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.

3 participants