gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
34 stars 13 forks source link

add packing functions for Instances and KCells #431

Closed sebastian-goeldi closed 4 months ago

sebastian-goeldi commented 4 months ago
example.py ```python import kfactory as kf from kfactory.packing import pack_instances, pack_kcells @kf.cell def box(width: int, height: int) -> kf.KCell: c = kf.KCell() c.shapes(c.kcl.layer(1, 0)).insert(kf.kdb.Box(width, height)) return c c = kf.KCell("Box Packing") ig1 = pack_kcells( c, [box(w, h) for w, h in [(500, 500) for _ in range(15)] + [(15_000, 1000)]], max_width=16000, spacing=1000, ) small_boxes = [c << box(w, h) for w, h in ((500, 500) for _ in range(15))] bigbox = c << box(15_000, 1000) bigbox.transform(kf.kdb.Trans.R90) ig2 = pack_instances( c, small_boxes + [bigbox], max_width=16000, spacing=1000, ) ig2.movex(ig1.xmax + 5000 - ig2.xmin) c.show() ```

gives:

image

Also clean up some of the instance group code.

@joamatab @akshat-ja @gdspaul

sourcery-ai[bot] commented 4 months ago

🧙 Sourcery has finished reviewing your pull request!


Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.
akshat-ja commented 4 months ago

Let me test a bit more on my side @sebastian-goeldi then I'll green light.