Home > Community > Forums > Custom IC SKILL > Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box

## Email

Recipients email * (separate multiple addresses with commas)

Message *

 Send yourself a copy

## Subscribe

Intro copy of the newsletter section here, some intro copy of the newsletter. Instruction of how to subscribe to this newsletter.

First Name *

Last Name *

Email *

Company / Institution *

 Send Yourself A Copy

# Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box

Last post Wed, Mar 4 2009 2:29 PM by JMCaJHU. 7 replies.
 Started by JMCaJHU 02 Mar 2009 03:29 PM. Topic has 7 replies and 5272 views
• #### Mon, Mar 2 2009 3:29 PM

• JMCaJHU
• Joined on Mon, Mar 2 2009
• Posts 13
• Points 275
Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 Hi, I'm new to Cadence and skill.  I've been studying sample code and ultimately need to make procedures that will create instances of different inv, different or gates and other logic gates in a row.  To do this, I plan to find the width of the gate, and stack them side by side.  Is there any code that will let me find a bounding box's x1 and x2?  I can then subtract to find its width and run a for loop that places an instance every n(x2-x1).  I realize there is already a similar question.  I tried that code but it didnt seem to work.JC
• Post Points: 35
• #### Tue, Mar 3 2009 6:56 AM

• dmay
• Joined on Thu, Jul 17 2008
• Allen, TX
• Posts 393
• Points 7,415
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 There are several ways to do this. The Skill shortcuts are easier to read and understand, but the pure cars and cdrs are more efficient. bBox = list(0:10 20:30);In Skill's purest and simplest formll = car(bBox)ur = cadr(bBox) ;same as car(cdr(bBox))x1 = car(ll)x2 = car(ur)y1 = cadr(ll)y2 = cadr(ur)println(list(x1 x2 y1 y2));In Skill's purest and shortest formx1 = caar(bBox) ;same as car(car(bBox))x2 = caadr(bBox) ;same as car(car(cdr(bBox)))y1 = cadar(bBox) ;same as car(cdr(car(bBox)))y2 = cadadr(bBox) ;same as car(cdr(car(cdr(bBox))))println(list(x1 x2 y1 y2));Using some of Skill's shortcutsx1 = leftEdge(bBox)x2 = rightEdge(bBox)y1 = bottomEdge(bBox)y2 = topEdge(bBox)println(list(x1 x2 y1 y2));Using some of Skill's shortcutsll = lowerLeft(bBox)ur = upperRight(bBox)x1 = xCoord(ll)x2 = xCoord(ur)y1 = yCoord(ll)y2 = yCoord(ur)println(list(x1 x2 y1 y2))Derek
• Post Points: 5
• #### Tue, Mar 3 2009 7:41 AM

• skillUser
• Joined on Fri, Sep 19 2008
• Austin, TX
• Posts 2,571
• Points 15,610
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 Hi JC,To add to what Derek has said, a neat way to get just the width of a bounding box, assuming that bBox contains the bounding box of hte object is: ` abs(apply('difference mapcar('car bBox)))` This obtains the car of each of the bBox elements, then it subtracts one from the other and then it takes the absolute value, to make the width a positive number. I hope that this helps! Lawrence.
• Post Points: 5
• #### Tue, Mar 3 2009 8:01 AM

• skillUser
• Joined on Fri, Sep 19 2008
• Austin, TX
• Posts 2,571
• Points 15,610
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 Oops, hit the "Post" button prematurely there.Anyway, to continue my thread, the above method may seem cumbersome for just getting the width, but it can be extended to other things. Let's say you wanted to find the left most point of all of the bounding boxes stored in bBoxes, you could iterate over them manually and store the smaller X value of either the lowerleft point or the previous left-most point each iteration, or you could do it in one statement: ``` apply('min mapcar('caar bBoxes)) ``` This iterates over each bBox in bBoxes and takes the caar (the car of the car) of each one to find the X ordinate of the lowerleft coordinate and then this list is passed to the min function which returns the lowest X value. Cool huh?Also, by the way, don't forget to use lowerLeft() and upperRight() for clarity in your code, but beware that these are simply aliases for the car and cadr functions respectively, they do not check to see if the input is a valid bounding box, they will just expect a list and operate on it, e.g. the following would not cause an error or warning: ` lowerLeft( list( 1 2 3 4 ) ) ` However, there is a handy function, isBBox() that can be used to validate that you have a correct bounding box.Happy coding!Lawrence.
• Post Points: 20
• #### Wed, Mar 4 2009 12:56 PM

• JMCaJHU
• Joined on Mon, Mar 2 2009
• Posts 13
• Points 275
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 Thanks for the multiple examples guys, it really helped understand lists.  I guess my biggest problem is selecting the bounding box and parsing it as a list.   I'm working on basic cells such as inv and or cells with only one bounding box.  I started playing around with dbComputeBBox but its still not working. The code is:db_inv_master=dbOpenCellViewByType("tsmcinv" "inv" "layout" "" "r") bBox=dbComputeBBox(db_inv_master) ll = lowerLeft(bBox) ur = upperRight(bBox) x1 = xCoord(ll) x2 = xCoord(ur) y1 = yCoord(ll) y2 = yCoord(ur) println(x1) This code resulted in an error of mismatched types, so i tried:bBox=list(list(dbComputeBBox(db_inv_master) ))but that just gives an output of t/nil when it should output the x1 coord
• Post Points: 35
• #### Wed, Mar 4 2009 1:17 PM

• dmay
• Joined on Thu, Jul 17 2008
• Allen, TX
• Posts 393
• Points 7,415
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 The dbComputeBBox routine returns a t or a nil and does not return a bBox. I'm not familiar with that routine and its purpose, but that is not what you want. The mismatched types is due to the fact that you are using commands for lists and your bBox is a boolean.Simply change the dbComputeBBox line in your code to be this:bBox = db_inv_master~>bBoxThe rest of the code should work fine. -Derek
• Post Points: 5
• #### Wed, Mar 4 2009 1:18 PM

• skillUser
• Joined on Fri, Sep 19 2008
• Austin, TX
• Posts 2,571
• Points 15,610
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 Hi JC,Oops - the dbComputeBBox() forces the bounding box to be recalculated but it does not return the bounding box of the cellview.  The bounding box of a database object can be found easily by querying the bBox attribute of it. Using your example: ` bBox = db_inv_master~>bBox` Then the code should work. As a suggestion I would recommend "defensive" programming, i.e. check what you are expecting and only continue if it is correct. Example of this: ```when( bBox = db_inv_master~>bBox ;; when this attribute is non-nil  ll = lowerLeft(bBox)  ... ); when ``` Or you could issue a warning, depending on what you want to do: ```bBox = db_inv_master~>bBox if(isBBox(bBox) then  ;; do the code else  warn("Did not obtain a valid bBox - %L" bBox) ); if ```Notice the use of the isBBox() function to validate the bounding box in the second example. Hopefully the examples above help you to get past this problem.Regards,Lawrence.
• Post Points: 20
• #### Wed, Mar 4 2009 2:29 PM

• JMCaJHU
• Joined on Mon, Mar 2 2009
• Posts 13
• Points 275
Re: Finding the lowerleft(x1,y1) and upperright(x2,y2) of a bounding box
 thanks so much for the help guys
• Post Points: 5
###### Sort Posts: Oldest to newest Newest to oldest
 Started by JMCaJHU at 02 Mar 2009 03:29 PM. Topic has 7 replies.