KLayout 0.29.8 (2024-10-28 63dd591e5) [master]

API reference - Class Box

Notation used in Ruby API documentation

Module: db

Description: A box class with integer coordinates

This object represents a box (a rectangular shape).

The definition of the attributes is: p1 is the lower left point, p2 the upper right one. If a box is constructed from two points (or four coordinates), the coordinates are sorted accordingly.

A box can be empty. An empty box represents no area (not even a point). Empty boxes behave neutral with respect to most operations. Empty boxes return true on empty?.

A box can be a point or a single line. In this case, the area is zero but the box still can overlap other boxes for example and it is not empty.

See The Database API for more details about the database objects.

Public constructors

new Box ptrnew(const DBox dbox)Creates an integer coordinate box from a floating-point coordinate box
new Box ptrnewCreates an empty (invalid) box
new Box ptrnew(int w)Creates a square with the given dimensions centered around the origin
new Box ptrnew(int w,
int h)
Creates a rectangle with given width and height, centered around the origin
new Box ptrnew(int left,
int bottom,
int right,
int top)
Creates a box with four coordinates
new Box ptrnew(const Point lower_left,
const Point upper_right)
Creates a box from two points

Public methods

[const]bool!=(const Box box)Returns true if this box is not equal to the other box
[const]Box&(const Box box)Returns the intersection of this box with another box
[const]Box*(const Box box)Returns the convolution product from this box with another box
[const]Box*(double scale_factor)Returns the scaled box
[const]Box+(const Point point)Joins box with a point
[const]Box+(const Box box)Joins two boxes
[const]Box-(const Box box)Subtraction of boxes
[const]bool<(const Box box)Returns true if this box is 'less' than another box
[const]bool==(const Box box)Returns true if this box is equal to the other box
[const]Box ptr_const_castReturns a non-const reference to self.
void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
[const]doubleareaComputes the box area
voidassign(const Box other)Assigns another object to self
[const]BoxbboxReturns the bounding box
[const]intbottomGets the bottom coordinate of the box
voidbottom=(int c)Sets the bottom coordinate of the box
[const]PointcenterGets the center of the box
[const]boolcontains?(int x,
int y)
Returns true if the box contains the given point
[const]boolcontains?(const Point point)Returns true if the box contains the given point
[const]new Box ptrdupCreates a copy of self
[const]boolempty?Returns a value indicating whether the box is empty
Boxenlarge(int dx,
int dy)
Enlarges the box by a certain amount.
Boxenlarge(int d)Enlarges the box by a certain amount on all sides.
Boxenlarge(const Vector enlargement)Enlarges the box by a certain amount.
[const]Boxenlarged(int dx,
int dy)
Enlarges the box by a certain amount.
[const]Boxenlarged(int d)Enlarges the box by a certain amount on all sides.
[const]Boxenlarged(const Vector enlargement)Returns the enlarged box.
[const]unsigned longhashComputes a hash value
[const]unsigned intheightGets the height of the box
[const]boolinside?(const Box box)Tests if this box is inside the argument box
[const]boolis_point?Returns true, if the box is a single point
[const]intleftGets the left coordinate of the box
voidleft=(int c)Sets the left coordinate of the box
Boxmove(int dx,
int dy)
Moves the box by a certain distance
Boxmove(const Vector distance)Moves the box by a certain distance
[const]Boxmoved(int dx,
int dy)
Moves the box by a certain distance
[const]Boxmoved(const Vector distance)Returns the box moved by a certain distance
[const]booloverlaps?(const Box box)Tests if this box overlaps the argument box
[const]Pointp1Gets the lower left point of the box
voidp1=(const Point p)Sets the lower left point of the box
[const]Pointp2Gets the upper right point of the box
voidp2=(const Point p)Sets the upper right point of the box
[const]unsigned longperimeterReturns the perimeter of the box
[const]intrightGets the right coordinate of the box
voidright=(int c)Sets the right coordinate of the box
[const]DBoxto_dtype(double dbu = 1)Converts the box to a floating-point coordinate box
[const]stringto_s(double dbu = 0)Returns a string representing this box
[const]inttopGets the top coordinate of the box
voidtop=(int c)Sets the top coordinate of the box
[const]booltouches?(const Box box)Tests if this box touches the argument box
[const]Boxtransformed(const ICplxTrans t)Transforms the box with the given complex transformation
[const]Boxtransformed(const Trans t)Returns the box transformed with the given simple transformation
[const]DBoxtransformed(const CplxTrans t)Returns the box transformed with the given complex transformation
[const]unsigned intwidthGets the width of the box

Public static methods and constants

new Box ptrfrom_s(string s)Creates a box object from a string
BoxworldGets the 'world' box

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[static]new Box ptrfrom_dbox(const DBox dbox)Use of this method is deprecated. Use new instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead

Detailed description

!=

Signature: [const] bool != (const Box box)

Description: Returns true if this box is not equal to the other box

Returns true, if this box and the given box are not equal

&

Signature: [const] Box & (const Box box)

Description: Returns the intersection of this box with another box

box:The box to take the intersection with
Returns:The intersection box

The intersection of two boxes is the largest box common to both boxes. The intersection may be empty if both boxes to not touch. If the boxes do not overlap but touch the result may be a single line or point with an area of zero. Overwrites this box with the result.

*

(1) Signature: [const] Box * (const Box box)

Description: Returns the convolution product from this box with another box

box:The box to convolve with this box.
Returns:The convolved box

The * operator convolves the firstbox with the one given as the second argument. The box resulting from "convolution" is the outer boundary of the union set formed by placing the second box at every point of the first. In other words, the returned box of (p1,p2)*(q1,q2) is (p1+q1,p2+q2).

Python specific notes:
This method also implements '__rmul__'.

(2) Signature: [const] Box * (double scale_factor)

Description: Returns the scaled box

scale_factor:The scaling factor
Returns:The scaled box

The * operator scales the box with the given factor and returns the result.

This method has been introduced in version 0.22.

Python specific notes:
This method also implements '__rmul__'.

+

(1) Signature: [const] Box + (const Point point)

Description: Joins box with a point

point:The point to join with this box.
Returns:The box joined with the point

The + operator joins a point with the box. The resulting box will enclose both the original box and the point.

(2) Signature: [const] Box + (const Box box)

Description: Joins two boxes

box:The box to join with this box.
Returns:The joined box

The + operator joins the first box with the one given as the second argument. Joining constructs a box that encloses both boxes given. Empty boxes are neutral: they do not change another box when joining. Overwrites this box with the result.

-

Signature: [const] Box - (const Box box)

Description: Subtraction of boxes

box:The box to subtract from this box.
Returns:The result box

The - operator subtracts the argument box from self. This will return the bounding box of the are covered by self, but not by argument box. Subtracting a box from itself will render an empty box. Subtracting another box from self will modify the first box only if the argument box covers one side entirely.

This feature has been introduced in version 0.29.

<

Signature: [const] bool < (const Box box)

Description: Returns true if this box is 'less' than another box

Returns true, if this box is 'less' with respect to first and second point (in this order)

==

Signature: [const] bool == (const Box box)

Description: Returns true if this box is equal to the other box

Returns true, if this box and the given box are equal

_const_cast

Signature: [const] Box ptr _const_cast

Description: Returns a non-const reference to self.

Basically, this method allows turning a const object reference to a non-const one. This method is provided as last resort to remove the constness from an object. Usually there is a good reason for a const object reference, so using this method may have undesired side effects.

This method has been introduced in version 0.29.6.

_create

Signature: void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

_destroy

Signature: void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

_destroyed?

Signature: [const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

_is_const_object?

Signature: [const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

_manage

Signature: void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

_unmanage

Signature: void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

area

Signature: [const] double area

Description: Computes the box area

Returns the box area or 0 if the box is empty

assign

Signature: void assign (const Box other)

Description: Assigns another object to self

bbox

Signature: [const] Box bbox

Description: Returns the bounding box

This method is provided for consistency of the shape API is returns the box itself.

This method has been introduced in version 0.27.

bottom

Signature: [const] int bottom

Description: Gets the bottom coordinate of the box

Python specific notes:
The object exposes a readable attribute 'bottom'. This is the getter.

bottom=

Signature: void bottom= (int c)

Description: Sets the bottom coordinate of the box

Python specific notes:
The object exposes a writable attribute 'bottom'. This is the setter.

center

Signature: [const] Point center

Description: Gets the center of the box

contains?

(1) Signature: [const] bool contains? (int x, int y)

Description: Returns true if the box contains the given point

Returns:true if the point is inside the box.

Tests whether a point (x, y) is inside the box. It also returns true if the point is exactly on the box contour.

(2) Signature: [const] bool contains? (const Point point)

Description: Returns true if the box contains the given point

p:The point to test against.
Returns:true if the point is inside the box.

Tests whether a point is inside the box. It also returns true if the point is exactly on the box contour.

create

Signature: void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

destroy

Signature: void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

destroyed?

Signature: [const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

dup

Signature: [const] new Box ptr dup

Description: Creates a copy of self

Python specific notes:
This method also implements '__copy__' and '__deepcopy__'.

empty?

Signature: [const] bool empty?

Description: Returns a value indicating whether the box is empty

An empty box may be created with the default constructor for example. Such a box is neutral when combining it with other boxes and renders empty boxes if used in box intersections and false in geometrical relationship tests.

enlarge

(1) Signature: Box enlarge (int dx, int dy)

Description: Enlarges the box by a certain amount.

Returns:A reference to this box.

This is a convenience method which takes two values instead of a Vector object. This method has been introduced in version 0.23.

(2) Signature: Box enlarge (int d)

Description: Enlarges the box by a certain amount on all sides.

Returns:A reference to this box.

This is a convenience method which takes one values instead of two values. It will apply the given enlargement in both directions. This method has been introduced in version 0.28.

(3) Signature: Box enlarge (const Vector enlargement)

Description: Enlarges the box by a certain amount.

enlargement:The grow or shrink amount in x and y direction
Returns:A reference to this box.

Enlarges the box by x and y value specified in the vector passed. Positive values with grow the box, negative ones will shrink the box. The result may be an empty box if the box disappears. The amount specifies the grow or shrink per edge. The width and height will change by twice the amount. Does not check for coordinate overflows.

enlarged

(1) Signature: [const] Box enlarged (int dx, int dy)

Description: Enlarges the box by a certain amount.

Returns:The enlarged box.

This is a convenience method which takes two values instead of a Vector object. This method has been introduced in version 0.23.

(2) Signature: [const] Box enlarged (int d)

Description: Enlarges the box by a certain amount on all sides.

Returns:The enlarged box.

This is a convenience method which takes one values instead of two values. It will apply the given enlargement in both directions. This method has been introduced in version 0.28.

(3) Signature: [const] Box enlarged (const Vector enlargement)

Description: Returns the enlarged box.

enlargement:The grow or shrink amount in x and y direction
Returns:The enlarged box.

Enlarges the box by x and y value specified in the vector passed. Positive values with grow the box, negative ones will shrink the box. The result may be an empty box if the box disappears. The amount specifies the grow or shrink per edge. The width and height will change by twice the amount. Does not modify this box. Does not check for coordinate overflows.

from_dbox

Signature: [static] new Box ptr from_dbox (const DBox dbox)

Description: Creates an integer coordinate box from a floating-point coordinate box

Use of this method is deprecated. Use new instead

This constructor has been introduced in version 0.25 and replaces the previous static method 'from_dbox'.

Python specific notes:
This method is the default initializer of the object.

from_s

Signature: [static] new Box ptr from_s (string s)

Description: Creates a box object from a string

Creates the object from a string representation (as returned by to_s)

This method has been added in version 0.23.

hash

Signature: [const] unsigned long hash

Description: Computes a hash value

Returns a hash value for the given box. This method enables boxes as hash keys.

This method has been introduced in version 0.25.

Python specific notes:
This method is also available as 'hash(object)'.

height

Signature: [const] unsigned int height

Description: Gets the height of the box

inside?

Signature: [const] bool inside? (const Box box)

Description: Tests if this box is inside the argument box

Returns true, if this box is inside the given box, i.e. the box intersection renders this box

is_const_object?

Signature: [const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

is_point?

Signature: [const] bool is_point?

Description: Returns true, if the box is a single point

left

Signature: [const] int left

Description: Gets the left coordinate of the box

Python specific notes:
The object exposes a readable attribute 'left'. This is the getter.

left=

Signature: void left= (int c)

Description: Sets the left coordinate of the box

Python specific notes:
The object exposes a writable attribute 'left'. This is the setter.

move

(1) Signature: Box move (int dx, int dy)

Description: Moves the box by a certain distance

Returns:A reference to this box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

(2) Signature: Box move (const Vector distance)

Description: Moves the box by a certain distance

distance:The offset to move the box.
Returns:A reference to this box.

Moves the box by a given offset and returns the moved box. Does not check for coordinate overflows.

moved

(1) Signature: [const] Box moved (int dx, int dy)

Description: Moves the box by a certain distance

Returns:The moved box.

This is a convenience method which takes two values instead of a Point object. This method has been introduced in version 0.23.

(2) Signature: [const] Box moved (const Vector distance)

Description: Returns the box moved by a certain distance

distance:The offset to move the box.
Returns:The moved box.

Moves the box by a given offset and returns the moved box. Does not modify this box. Does not check for coordinate overflows.

new

(1) Signature: [static] new Box ptr new (const DBox dbox)

Description: Creates an integer coordinate box from a floating-point coordinate box

This constructor has been introduced in version 0.25 and replaces the previous static method 'from_dbox'.

Python specific notes:
This method is the default initializer of the object.

(2) Signature: [static] new Box ptr new

Description: Creates an empty (invalid) box

Empty boxes don't modify a box when joined with it. The intersection between an empty and any other box is also an empty box. The width, height, p1 and p2 attributes of an empty box are undefined. Use empty? to get a value indicating whether the box is empty.

Python specific notes:
This method is the default initializer of the object.

(3) Signature: [static] new Box ptr new (int w)

Description: Creates a square with the given dimensions centered around the origin

Note that for integer-unit boxes, the dimension has to be an even number to avoid rounding.

This convenience constructor has been introduced in version 0.28.

Python specific notes:
This method is the default initializer of the object.

(4) Signature: [static] new Box ptr new (int w, int h)

Description: Creates a rectangle with given width and height, centered around the origin

Note that for integer-unit boxes, the dimensions have to be an even number to avoid rounding.

This convenience constructor has been introduced in version 0.28.

Python specific notes:
This method is the default initializer of the object.

(5) Signature: [static] new Box ptr new (int left, int bottom, int right, int top)

Description: Creates a box with four coordinates

Four coordinates are given to create a new box. If the coordinates are not provided in the correct order (i.e. right < left), these are swapped.

Python specific notes:
This method is the default initializer of the object.

(6) Signature: [static] new Box ptr new (const Point lower_left, const Point upper_right)

Description: Creates a box from two points

Two points are given to create a new box. If the coordinates are not provided in the correct order (i.e. right < left), these are swapped.

Python specific notes:
This method is the default initializer of the object.

overlaps?

Signature: [const] bool overlaps? (const Box box)

Description: Tests if this box overlaps the argument box

Returns true, if the intersection box of this box with the argument box exists and has a non-vanishing area

p1

Signature: [const] Point p1

Description: Gets the lower left point of the box

Python specific notes:
The object exposes a readable attribute 'p1'. This is the getter.

p1=

Signature: void p1= (const Point p)

Description: Sets the lower left point of the box

Python specific notes:
The object exposes a writable attribute 'p1'. This is the setter.

p2

Signature: [const] Point p2

Description: Gets the upper right point of the box

Python specific notes:
The object exposes a readable attribute 'p2'. This is the getter.

p2=

Signature: void p2= (const Point p)

Description: Sets the upper right point of the box

Python specific notes:
The object exposes a writable attribute 'p2'. This is the setter.

perimeter

Signature: [const] unsigned long perimeter

Description: Returns the perimeter of the box

This method is equivalent to 2*(width+height). For empty boxes, this method returns 0.

This method has been introduced in version 0.23.

right

Signature: [const] int right

Description: Gets the right coordinate of the box

Python specific notes:
The object exposes a readable attribute 'right'. This is the getter.

right=

Signature: void right= (int c)

Description: Sets the right coordinate of the box

Python specific notes:
The object exposes a writable attribute 'right'. This is the setter.

to_dtype

Signature: [const] DBox to_dtype (double dbu = 1)

Description: Converts the box to a floating-point coordinate box

The database unit can be specified to translate the integer-coordinate box into a floating-point coordinate box in micron units. The database unit is basically a scaling factor.

This method has been introduced in version 0.25.

to_s

Signature: [const] string to_s (double dbu = 0)

Description: Returns a string representing this box

This string can be turned into a box again by using from_s . If a DBU is given, the output units will be micrometers.

The DBU argument has been added in version 0.27.6.

Python specific notes:
This method is also available as 'str(object)'.

top

Signature: [const] int top

Description: Gets the top coordinate of the box

Python specific notes:
The object exposes a readable attribute 'top'. This is the getter.

top=

Signature: void top= (int c)

Description: Sets the top coordinate of the box

Python specific notes:
The object exposes a writable attribute 'top'. This is the setter.

touches?

Signature: [const] bool touches? (const Box box)

Description: Tests if this box touches the argument box

Two boxes touch if they overlap or their boundaries share at least one common point. Touching is equivalent to a non-empty intersection ('!(b1 & b2).empty?').

transformed

(1) Signature: [const] Box transformed (const ICplxTrans t)

Description: Transforms the box with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed box (in this case an integer coordinate box)

This method has been introduced in version 0.18.

(2) Signature: [const] Box transformed (const Trans t)

Description: Returns the box transformed with the given simple transformation

t:The transformation to apply
Returns:The transformed box

(3) Signature: [const] DBox transformed (const CplxTrans t)

Description: Returns the box transformed with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed box (a DBox now)

width

Signature: [const] unsigned int width

Description: Gets the width of the box

world

Signature: [static] Box world

Description: Gets the 'world' box

The world box is the biggest box that can be represented. So it is basically 'all'. The world box behaves neutral on intersections for example. In other operations such as displacement or transformations, the world box may render unexpected results because of coordinate overflow.

The world box can be used

  • for comparison ('==', '!=', '<')
  • in union and intersection ('+' and '&')
  • in relations (contains?, overlaps?, touches?)
  • as 'all' argument in region queries

This method has been introduced in version 0.28.