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

result of get_bounding_box() for a polygon is wrong #231

Closed
tinaa160 opened this issue May 30, 2023 · 2 comments
Closed

result of get_bounding_box() for a polygon is wrong #231

tinaa160 opened this issue May 30, 2023 · 2 comments

Comments

@tinaa160
Copy link

tinaa160 commented May 30, 2023

Hi,

I would like to obtain the bounding box of a polygon(108:250) in a cell.
polygon(108:250) is a rectangle polygon.

Here's how I did:

all_pol = top_cell.get_polygons(by_spec = True)
target_layer = all_pol[108, 250]
print(target_layer)
tmp_target_layer = gdspy.Polygon(target_layer)
out = tmp_target_layer.get_bounding_box()
print(out)

output of "print(target_layer)"
[[15, 15],
[15, 45],
[45, 45],
[45, 15]
]

output of "print(out)"
[[15, 15],
[15, 45]
]

It seems output of "print(out)" should be
[[15, 15],
[45, 45]
]

Do I misunderstand the usage of the function?

Thanks a lot,

@heitzmann
Copy link
Owner

Your polygon creation is wrong. If you print target_layer you'll see that the output is not what you're showing. It should be like this:

In [1]: import gdspy

In [2]: top_cell = gdspy.Cell("CELL").add(gdspy.Rectangle((15, 15), (45, 45), layer=108, datatype=250))

In [3]: all_pol = top_cell.get_polygons(by_spec=True)

In [4]: target_layer = all_pol[108, 250]

In [5]: print(target_layer)
[array([[15, 15],
       [15, 45],
       [45, 45],
       [45, 15]])]

You see: all_pol is a dictionary of lists of polygon vertices, so, if you want to create a new polygon, you have to select one of the list items:

In [6]: tmp_target_layer = gdspy.Polygon(target_layer[0])

In [7]: out = tmp_target_layer.get_bounding_box()

In [8]: print(out)
[[15 15]
 [45 45]]

@tinaa160
Copy link
Author

tinaa160 commented Jun 1, 2023

Hi heitzmann,
Yes your are correct!
It works after I use the function correctly.
Thanks a lot

@tinaa160 tinaa160 closed this as completed Jun 1, 2023
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

No branches or pull requests

2 participants