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

clean_value_json should handle Polygons #889

Closed
tvt173 opened this issue Nov 17, 2022 · 3 comments
Closed

clean_value_json should handle Polygons #889

tvt173 opened this issue Nov 17, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@tvt173
Copy link
Collaborator

tvt173 commented Nov 17, 2022

Sometimes it is desirable to pass a Polygon, list of Polygon, or list of numpy arrays representing polygons as an argument, but it currently breaks clean_value_json. Would be great if that worked.

@tvt173 tvt173 added the enhancement New feature or request label Nov 17, 2022
@joamatab
Copy link
Contributor

Hi Troy, can you add an example for the code to reproduce?

@tvt173
Copy link
Collaborator Author

tvt173 commented Nov 18, 2022

hi @joamatab , please see the script below

import gdsfactory as gf


@gf.cell
def wrap_polygon(polygon) -> gf.Component:
    c = gf.Component()
    # c.add_polygon(polygon, layer="WG")
    return c

@gf.cell
def wrap_polygons(polygons) -> gf.Component:
    c = gf.Component()
    # c.add_polygon(polygons, layer="WG")
    return c

if __name__ == '__main__':
    import gdstk

    # Try individually toggling on/off the commented lines below to see failing/passing cases

    # c = wrap_polygon(gdstk.rectangle((0,0), (1,1)))  # FAILS

    s = gf.components.straight()
    # c = wrap_polygons(s.get_polygons(as_array=False))  # FAILS
    # c = wrap_polygons(s.get_polygons(by_spec=False, as_array=True))  # WORKS
    c = wrap_polygons(s.get_polygons(by_spec=True, as_array=True))  # WORKS

    s = gf.components.ring_double_heater()
    # c = wrap_polygons(s.get_polygons(by_spec=False, as_array=True))  # FAILS
    # c = wrap_polygons(s.get_polygons(by_spec=(1, 0), as_array=True))  # FAILS
    # c = wrap_polygons(s.get_polygons(by_spec=True, as_array=True))  # FAILS

    c.show()

@joamatab
Copy link
Contributor

Thank you Troy, just released 6.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants