Notation used in Ruby API documentation

**Module**: db

**Description**: A polygon class

- Public constructors
- Public methods
- Public static methods and constants
- Deprecated methods (protected, public, static, non-static and constructors)
- Detailed description

A polygon consists of an outer hull and zero to many holes. Each contour consists of several points. The point list is normalized such that the leftmost, lowest point is the first one. The orientation is normalized such that the orientation of the hull contour is clockwise, while the orientation of the holes is counterclockwise.

It is in no way checked that the contours are not overlapping. This must be ensured by the user of the object when filling the contours.

A polygon can be asked for the number of holes using the holes method. each_point_hull delivers the points of the hull contour. each_point_hole delivers the points of a specific hole. each_edge delivers the edges (point-to-point connections) of both hull and holes. bbox delivers the bounding box, area the area and perimeter the perimeter of the polygon.

Here's an example of how to create a polygon:

hull = [ RBA::DPoint::new(0, 0), RBA::DPoint::new(6000, 0), RBA::DPoint::new(6000, 3000), RBA::DPoint::new(0, 3000) ] hole1 = [ RBA::DPoint::new(1000, 1000), RBA::DPoint::new(2000, 1000), RBA::DPoint::new(2000, 2000), RBA::DPoint::new(1000, 2000) ] hole2 = [ RBA::DPoint::new(3000, 1000), RBA::DPoint::new(4000, 1000), RBA::DPoint::new(4000, 2000), RBA::DPoint::new(3000, 2000) ] poly = RBA::DPolygon::new(hull) poly.insert_hole(hole1) poly.insert_hole(hole2) # ask the polygon for some properties poly.holes # -> 2 poly.area # -> 16000000.0 poly.perimeter # -> 26000.0 poly.bbox # -> (0,0;6000,3000)

The DPolygon class stores coordinates in floating-point format which gives a higher precision for some operations. A class that stores integer coordinates is Polygon.

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

new DPolygon ptr | new | (const Polygon polygon) | Creates a floating-point coordinate polygon from an integer coordinate polygon |

new DPolygon ptr | new | Creates an empty (invalid) polygon | |

new DPolygon ptr | new | (const DSimplePolygon sp) | Creates a polygon from a simple polygon |

new DPolygon ptr | new | (DPoint[] pts, bool raw = false) | Creates a polygon from a point array for the hull |

new DPolygon ptr | new | (const DBox box) | Creates a polygon from a box |

[const] | bool | != | (const DPolygon p) | Returns a value indicating whether the polygons are not equal |

[const] | DPolygon | * | (double f) | Scales the polygon by some factor |

[const] | bool | < | (const DPolygon p) | Returns a value indicating whether self is less than p |

[const] | bool | == | (const DPolygon p) | Returns a value indicating whether the polygons are equal |

[const] | DPolygon ptr | _const_cast | Returns a non-const reference to self. | |

void | _create | Ensures the C++ object is created | ||

void | _destroy | Explicitly 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 | _manage | Marks the object as managed by the script side. | ||

void | _unmanage | Marks the object as no longer owned by the script side. | ||

[const] | double | area | Gets the area of the polygon | |

[const] | double | area2 | Gets the double area of the polygon | |

void | assign | (const DPolygon other) | Assigns another object to self | |

void | assign_hole | (unsigned int n, DPoint[] p, bool raw = false) | Sets the points of the given hole of the polygon | |

void | assign_hole | (unsigned int n, const DBox b) | Sets the box as the given hole of the polygon | |

void | assign_hull | (DPoint[] p, bool raw = false) | Sets the points of the hull of polygon | |

[const] | DBox | bbox | Returns the bounding box of the polygon | |

[const] | DPolygon[] | break | (unsigned long max_vertex_count, double max_area_ratio) | Splits the polygon into parts with a maximum vertex count and area ratio |

void | compress | (bool remove_reflected) | Compresses the polygon. | |

[const] | new DPolygon ptr | dup | Creates a copy of self | |

[const,iter] | DEdge | each_edge | Iterates over the edges that make up the polygon | |

[const,iter] | DEdge | each_edge | (unsigned int contour) | Iterates over the edges of one contour of the polygon |

[const,iter] | DPoint | each_point_hole | (unsigned int n) | Iterates over the points that make up the nth hole |

[const,iter] | DPoint | each_point_hull | Iterates over the points that make up the hull | |

[const] | variant[] | extract_rad | Extracts the corner radii from a rounded polygon | |

[const] | unsigned long | hash | Computes a hash value | |

[const] | unsigned int | holes | Returns the number of holes | |

void | hull= | (DPoint[] p) | Sets the points of the hull of polygon | |

void | insert_hole | (DPoint[] p, bool raw = false) | Inserts a hole with the given points | |

void | insert_hole | (const DBox b) | Inserts a hole from the given box | |

[const] | bool | inside? | (DPoint p) | Tests, if the given point is inside the polygon |

[const] | bool | is_box? | Returns true, if the polygon is a simple box. | |

[const] | bool | is_empty? | Returns a value indicating whether the polygon is empty | |

[const] | bool | is_halfmanhattan? | Returns a value indicating whether the polygon is half-manhattan | |

[const] | bool | is_rectilinear? | Returns a value indicating whether the polygon is rectilinear | |

DPolygon | move | (const DVector p) | Moves the polygon. | |

DPolygon | move | (double x, double y) | Moves the polygon. | |

[const] | DPolygon | moved | (const DVector p) | Returns the moved polygon (does not modify self) |

[const] | DPolygon | moved | (double x, double y) | Returns the moved polygon (does not modify self) |

[const] | unsigned long | num_points | Gets the total number of points (hull plus holes) | |

[const] | unsigned long | num_points_hole | (unsigned int n) | Gets the number of points of the given hole |

[const] | unsigned long | num_points_hull | Gets the number of points of the hull | |

[const] | double | perimeter | Gets the perimeter of the polygon | |

[const] | DPoint | point_hole | (unsigned int n, unsigned long p) | Gets a specific point of a hole |

[const] | DPoint | point_hull | (unsigned long p) | Gets a specific point of the hull |

[const] | DPolygon | round_corners | (double rinner, double router, unsigned int n) | Rounds the corners of the polygon |

void | size | (double dx, double dy, unsigned int mode) | Sizes the polygon (biasing) | |

void | size | (const Vector dv, unsigned int mode = 2) | Sizes the polygon (biasing) | |

void | size | (double d, unsigned int mode = 2) | Sizes the polygon (biasing) | |

[const] | DPolygon | sized | (double dx, double dy, unsigned int mode) | Sizes the polygon (biasing) without modifying self |

[const] | DPolygon | sized | (const Vector dv, unsigned int mode = 2) | Sizes the polygon (biasing) without modifying self |

[const] | DPolygon | sized | (double d, unsigned int mode = 2) | Sizes the polygon (biasing) without modifying self |

void | sort_holes | Brings the holes in a specific order | ||

[const] | DPolygon[] | split | Splits the polygon into two or more parts | |

[const] | Polygon | to_itype | (double dbu = 1) | Converts the polygon to an integer coordinate polygon |

[const] | string | to_s | Returns a string representing the polygon | |

[const] | bool | touches? | (const DBox box) | Returns true, if the polygon touches the given box. |

[const] | bool | touches? | (const DEdge edge) | Returns true, if the polygon touches the given edge. |

[const] | bool | touches? | (const DPolygon polygon) | Returns true, if the polygon touches the other polygon. |

[const] | bool | touches? | (const DSimplePolygon simple_polygon) | Returns true, if the polygon touches the other polygon. |

DPolygon ptr | transform | (const DCplxTrans t) | Transforms the polygon with a complex transformation (in-place) | |

DPolygon ptr | transform | (const DTrans t) | Transforms the polygon (in-place) | |

[const] | Polygon | transformed | (const VCplxTrans t) | Transforms the polygon with the given complex transformation |

[const] | DPolygon | transformed | (const DTrans t) | Transforms the polygon |

[const] | DPolygon | transformed | (const DCplxTrans t) | Transforms the polygon with a complex transformation |

new DPolygon ptr | ellipse | (const DBox box, int n) | Creates a simple polygon approximating an ellipse | |

new DPolygon ptr | from_s | (string s) | Creates a polygon from a string |

void | create | Use of this method is deprecated. Use _create instead | ||

void | destroy | Use of this method is deprecated. Use _destroy instead | ||

[const] | bool | destroyed? | Use of this method is deprecated. Use _destroyed? instead | |

[static] | new DPolygon ptr | from_ipoly | (const Polygon polygon) | Use of this method is deprecated. Use new instead |

[const] | bool | is_const_object? | Use of this method is deprecated. Use _is_const_object? instead | |

[const] | DPolygon | transformed_cplx | (const DCplxTrans t) | Use of this method is deprecated. Use transformed instead |

## != |
| ||||||||

## * |
Returns the scaled object. All coordinates are multiplied with the given factor and if necessary rounded.
| ||||||||

## < |
This operator is provided to establish some, not necessarily a certain sorting order | ||||||||

## == |
| ||||||||

## _const_cast |
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 |
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 |
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? |
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? |
This method returns true, if self is a const reference. In that case, only const methods may be called on self. | ||||||||

## _manage |
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 |
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 |
The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise.Orientation is ensured automatically in most cases. | ||||||||

## area2 |
This method is provided because the area for an integer-type polygon is a multiple of 1/2. Hence the double area can be expresses precisely as an integer for these types. This method has been introduced in version 0.26.1 | ||||||||

## assign |
| ||||||||

## assign_hole |
If the hole index is not valid, this method does nothing. This method was introduced in version 0.18. The 'raw' argument was added in version 0.24. | ||||||||

If the hole index is not valid, this method does nothing. This method was introduced in version 0.23. | |||||||||

## assign_hull |
If the 'raw' argument is set to true, the points are taken as they are. Specifically no removal of redundant points or joining of coincident edges will take place. In effect, polygons consisting of a single point or two points can be constructed as well as polygons with duplicate points. Note that such polygons may cause problems in some applications. Regardless of raw mode, the point list will be adjusted such that the first point is the lowest-leftmost one and the orientation is clockwise always. The 'assign_hull' variant is provided in analogy to 'assign_hole'. The 'raw' argument was added in version 0.24. | ||||||||

## bbox |
The bounding box is the box enclosing all points of the polygon. | ||||||||

## break |
The area ratio is the ratio between the bounding box area and the polygon area. Higher values mean more 'skinny' polygons. This method will split the input polygon into pieces having a maximum of 'max_vertex_count' vertices and an area ratio less than 'max_area_ratio'. 'max_vertex_count' can be zero. In this case the limit is ignored. Also 'max_area_ratio' can be zero, in which case it is ignored as well. The method of splitting is unspecified. The algorithm will apply 'split' recursively until the parts satisfy the limits. This method has been introduced in version 0.29.
| ||||||||

## compress |
This method removes redundant points from the polygon, such as points being on a line formed by two other points. If remove_reflected is true, points are also removed if the two adjacent edges form a spike. This method was introduced in version 0.18. | ||||||||

## create |
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 |
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? |
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 |
| ||||||||

## each_edge |
This iterator will deliver all edges, including those of the holes. Hole edges are oriented counterclockwise while hull edges are oriented clockwise. | ||||||||

This iterator will deliver all edges of the contour specified by the contour parameter. The hull has contour number 0, the first hole has contour 1 etc. Hole edges are oriented counterclockwise while hull edges are oriented clockwise. This method was introduced in version 0.24. | |||||||||

## each_point_hole |
The hole number must be less than the number of holes (see holes) | ||||||||

## each_point_hull |
| ||||||||

## ellipse |
This method has been introduced in version 0.23. | ||||||||

## extract_rad |
Attempts to extract the radii of rounded corner polygon. This is essentially the inverse of the round_corners method. If this method succeeds, if will return an array of four elements: - The polygon with the rounded corners replaced by edgy ones
- The radius of the inner corners
- The radius of the outer corners
- The number of points per full circle
This method is based on some assumptions and may fail. In this case, an empty array is returned. If successful, the following code will more or less render the original polygon and parameters p = ... # some polygon p.round_corners(ri, ro, n) (p2, ri2, ro2, n2) = p.extract_rad # -> p2 == p, ro2 == ro, ri2 == ri, n2 == n (within some limits) This method was introduced in version 0.25. | ||||||||

## from_ipoly |
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_ipolygon'.
| ||||||||

## from_s |
Creates the object from a string representation (as returned by to_s) This method has been added in version 0.23. | ||||||||

## hash |
Returns a hash value for the given polygon. This method enables polygons as hash keys. This method has been introduced in version 0.25.
| ||||||||

## holes |
| ||||||||

## hull= |
The 'assign_hull' variant is provided in analogy to 'assign_hole'.
| ||||||||

## insert_hole |
The 'raw' argument was added in version 0.24. | ||||||||

This method was introduced in version 0.23. | |||||||||

## inside? |
If the given point is inside or on the edge of the polygon, true is returned. This tests works well only if the polygon is not self-overlapping and oriented clockwise. | ||||||||

## is_box? |
A polygon is a box if it is identical to its bounding box. This method was introduced in version 0.23. | ||||||||

## is_const_object? |
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_empty? |
| ||||||||

## is_halfmanhattan? |
Half-manhattan polygons have edges which are multiples of 45 degree. These polygons can be clipped at a rectangle without potential grid snapping. This predicate was introduced in version 0.27. | ||||||||

## is_rectilinear? |
| ||||||||

## move |
Moves the polygon by the given offset and returns the moved polygon. The polygon is overwritten. This method has been introduced in version 0.23. | ||||||||

Moves the polygon by the given offset and returns the moved polygon. The polygon is overwritten. | |||||||||

## moved |
Moves the polygon by the given offset and returns the moved polygon. The polygon is not modified. This method has been introduced in version 0.23. | ||||||||

Moves the polygon by the given offset and returns the moved polygon. The polygon is not modified. This method has been introduced in version 0.23. | |||||||||

## new |
This constructor has been introduced in version 0.25 and replaces the previous static method 'from_ipolygon'.
| ||||||||

| |||||||||

This method was introduced in version 0.22.
| |||||||||

The 'raw' argument was added in version 0.24.
| |||||||||

| |||||||||

## num_points |
This method was introduced in version 0.18. | ||||||||

## num_points_hole |
The argument gives the index of the hole of which the number of points are requested. The index must be less than the number of holes (see holes). | ||||||||

## num_points_hull |
| ||||||||

## perimeter |
The perimeter is sum of the lengths of all edges making up the polygon. This method has been introduce in version 0.23. | ||||||||

## point_hole |
If the index of the point or of the hole is not valid, a default value is returned. This method was introduced in version 0.18. | ||||||||

## point_hull |
If the index of the point is not a valid index, a default value is returned. This method was introduced in version 0.18. | ||||||||

## round_corners |
Replaces the corners of the polygon with circle segments. This method was introduced in version 0.20 for integer coordinates and in 0.25 for all coordinate types. | ||||||||

## size |
Shifts the contour outwards (dx,dy>0) or inwards (dx,dy<0). dx is the sizing in x-direction and dy is the sizing in y-direction. The sign of dx and dy should be identical. The sizing operation create invalid (self-overlapping, reverse oriented) contours. The mode defines at which bending angle cutoff occurs (0:>0, 1:>45, 2:>90, 3:>135, 4:>approx. 168, other:>approx. 179) In order to obtain a proper polygon in the general case, the sized polygon must be merged in 'greater than zero' wrap count mode. This is necessary since in the general case, sizing can be complicated operation which lets a single polygon fall apart into disjoint pieces for example. This can be achieved using the EdgeProcessor class for example: poly = ... # a RBA::Polygon poly.size(-50, 2) ep = RBA::EdgeProcessor::new # result is an array of RBA::Polygon objects result = ep.simple_merge_p2p([ poly ], false, false, 1) | ||||||||

This method is equivalent to size(dv.x, dv.y, mode) See size for a detailed description. This version has been introduced in version 0.28. | |||||||||

Shifts the contour outwards (d>0) or inwards (d<0). This method is equivalent to size(d, d, mode) See size for a detailed description. This method has been introduced in version 0.23. | |||||||||

## sized |
This method applies sizing to the polygon but does not modify self. Instead a sized copy is returned. See size for a description of the operation. This method has been introduced in version 0.23. | ||||||||

This method is equivalent to sized(dv.x, dv.y, mode) See size and sized for a detailed description. This version has been introduced in version 0.28. | |||||||||

Shifts the contour outwards (d>0) or inwards (d<0). This method is equivalent to sized(d, d, mode) | |||||||||

## sort_holes |
This function is normalize the hole order so the comparison of two polygons does not depend on the order the holes were inserted. Polygons generated by KLayout's alorithms have their holes sorted. This method has been introduced in version 0.28.8. | ||||||||

## split |
This method will break the polygon into parts. The exact breaking algorithm is unspecified, the result are smaller polygons of roughly equal number of points and 'less concave' nature. Usually the returned polygon set consists of two polygons, but there can be more. The merged region of the resulting polygons equals the original polygon with the exception of small snapping effects at new vertexes. The intended use for this method is a iteratively split polygons until the satisfy some maximum number of points limit. This method has been introduced in version 0.25.3. | ||||||||

## to_itype |
The database unit can be specified to translate the floating-point coordinate polygon in micron units to an integer-coordinate polygon in database units. The polygons coordinates will be divided by the database unit. This method has been introduced in version 0.25. | ||||||||

## to_s |
| ||||||||

## touches? |
The box and the polygon touch if they overlap or their contours share at least one point. This method was introduced in version 0.25.1. | ||||||||

The edge and the polygon touch if they overlap or the edge shares at least one point with the polygon's contour. This method was introduced in version 0.25.1. | |||||||||

The polygons touch if they overlap or their contours share at least one point. This method was introduced in version 0.25.1. | |||||||||

The polygons touch if they overlap or their contours share at least one point. This method was introduced in version 0.25.1. | |||||||||

## transform |
Transforms the polygon with the given complex transformation. Modifies self and returns self. An out-of-place version which does not modify self is transformed. This method has been introduced in version 0.24. | ||||||||

Transforms the polygon with the given transformation. Modifies self and returns self. An out-of-place version which does not modify self is transformed. This method has been introduced in version 0.24. | |||||||||

## transformed |
This method has been introduced in version 0.25. | ||||||||

Transforms the polygon with the given transformation. Does not modify the polygon but returns the transformed polygon. | |||||||||

Transforms the polygon with the given complex transformation. Does not modify the polygon but returns the transformed polygon. With version 0.25, the original 'transformed_cplx' method is deprecated and 'transformed' takes both simple and complex transformations. | |||||||||

## transformed_cplx |
Use of this method is deprecated. Use transformed instead Transforms the polygon with the given complex transformation. Does not modify the polygon but returns the transformed polygon. With version 0.25, the original 'transformed_cplx' method is deprecated and 'transformed' takes both simple and complex transformations. |