Skip to content

Cell.bounding_box rounding #311

@nmz787-intel

Description

@nmz787-intel

It might be nice to allow an optional arg to Cell.bounding_box that would eliminate me needing to round to 1nm precision (just found an issue where some number had 11 zeroes and then a 1 after the two significant decimals (120.96 was coming as 120.96000000000001) with code like:

import gdstk

def bounding_box_with_rounding(polygon, rounding=None):
    original_bb = polygon.bounding_box()
    if rounding is not None:
        return tuple(tuple(round(coord, rounding) for coord in point) for point in original_bb)
    return original_bb

# Example usage
cell_boundary = gdstk.Polygon([(0.123456, 0.654321), (1.987654, 2.345678)])
cb_bb = bounding_box_with_rounding(cell_boundary, rounding=4)
print(cb_bb)  # Output: ((0.1235, 0.6543), (1.9877, 2.3457))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions