gdsfactory / kfactory

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

size_info #225

Closed joamatab closed 7 months ago

joamatab commented 8 months ago

in gdsfactory we had the concept of size info for Cells and Instances

how about adding it to kfactory?

class SizeInfo:
    def __init__(self, bbox: ndarray) -> None:
        """Initialize this object."""
        self.west = bbox[0, 0]
        self.east = bbox[1, 0]
        self.south = bbox[0, 1]
        self.north = bbox[1, 1]

        self.width = self.east - self.west
        self.height = self.north - self.south

        xc = 0.5 * (self.east + self.west)
        yc = 0.5 * (self.north + self.south)

        self.sw = np.array([self.west, self.south])
        self.se = np.array([self.east, self.south])
        self.nw = np.array([self.west, self.north])
        self.ne = np.array([self.east, self.north])

        self.cw = np.array([self.west, yc])
        self.ce = np.array([self.east, yc])
        self.nc = np.array([xc, self.north])
        self.sc = np.array([xc, self.south])
        self.cc = self.center = np.array([xc, yc])

    def get_rect(
        self, padding=0, padding_w=None, padding_e=None, padding_n=None, padding_s=None
    ) -> tuple[Coordinate, Coordinate, Coordinate, Coordinate]:
        w, e, s, n = self.west, self.east, self.south, self.north

        padding_n = padding if padding_n is None else padding_n
        padding_e = padding if padding_e is None else padding_e
        padding_w = padding if padding_w is None else padding_w
        padding_s = padding if padding_s is None else padding_s

        w = w - padding_w
        e = e + padding_e
        s = s - padding_s
        n = n + padding_n

        return ((w, s), (e, s), (e, n), (w, n))

    @property
    def rect(self) -> tuple[Coordinate, Coordinate]:
        return self.get_rect()

    def __str__(self) -> str:
        """Return a string representation of the object."""
        return f"w: {self.west}\ne: {self.east}\ns: {self.south}\nn: {self.north}\n"
sebastian-goeldi commented 8 months ago

I am not sure I understand what you want from this? The bounding box? c.bbox(layer_index) or c.bbox() or in um c.dbbox() and c.dbbox(layer_index)

joamatab commented 8 months ago

yes, it's similar to bbox but more convenient, as it allows you to easily get

sebastian-goeldi commented 8 months ago

I mean a lot of it is there:

box.left, box.right, box.bottom, box.top, box.p1, box.p2, box.center(), box.height(), box.width()

sebastian-goeldi commented 8 months ago

best thing: this does not only apply to cells and instances but all geometrical objects. all of them have a .bbox()

sebastian-goeldi commented 7 months ago

@joamatab do you still think we need this?

joamatab commented 7 months ago

We can close it