API reference - Class Polygon

Notation used in Ruby API documentation

Module: db

Description: A polygon class

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::Point::new(0, 0),       RBA::Point::new(6000, 0), 
          RBA::Point::new(6000, 3000), RBA::Point::new(0, 3000) ]
hole1 = [ RBA::Point::new(1000, 1000), RBA::Point::new(2000, 1000), 
          RBA::Point::new(2000, 2000), RBA::Point::new(1000, 2000) ]
hole2 = [ RBA::Point::new(3000, 1000), RBA::Point::new(4000, 1000), 
          RBA::Point::new(4000, 2000), RBA::Point::new(3000, 2000) ]
poly = RBA::Polygon::new(hull)
poly.insert_hole(hole1)
poly.insert_hole(hole2)

# ask the polygon for some properties
poly.holes      # -> 2
poly.area       # -> 16000000
poly.perimeter  # -> 26000
poly.bbox       # -> (0,0;6000,3000)

The Polygon class stores coordinates in integer format. A class that stores floating-point coordinates is DPolygon.

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

Public constructors

new Polygon ptrnew(const DPolygon dpolygon)Creates an integer coordinate polygon from a floating-point coordinate polygon
new Polygon ptrnewCreates an empty (invalid) polygon
new Polygon ptrnew(const SimplePolygon sp)Creates a polygon from a simple polygon
new Polygon ptrnew(Point[] pts,
bool raw = false)
Creates a polygon from a point array for the hull
new Polygon ptrnew(const Box box)Creates a polygon from a box

Public methods

[const]bool!=(const Polygon p)Returns a value indicating whether the polygons are not equal
[const]Polygon*(double f)Scales the polygon by some factor
[const]bool<(const Polygon p)Returns a value indicating whether self is less than p
[const]bool==(const Polygon p)Returns a value indicating whether the polygons are equal
[const]Polygon 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]longareaGets the area of the polygon
[const]longarea2Gets the double area of the polygon
voidassign(const Polygon other)Assigns another object to self
voidassign_hole(unsigned int n,
Point[] p,
bool raw = false)
Sets the points of the given hole of the polygon
voidassign_hole(unsigned int n,
const Box b)
Sets the box as the given hole of the polygon
voidassign_hull(Point[] p,
bool raw = false)
Sets the points of the hull of polygon
[const]BoxbboxReturns the bounding box of the polygon
[const]Polygon[]break(unsigned long max_vertex_count,
double max_area_ratio)
Splits the polygon into parts with a maximum vertex count and area ratio
voidcompress(bool remove_reflected)Compresses the polygon.
[const]SimplePolygon[]decompose_convex(int preferred_orientation = PO_any)Decomposes the polygon into convex pieces
[const]SimplePolygon[]decompose_trapezoids(int mode = TD_simple)Decomposes the polygon into trapezoids
[const]new Polygon ptrdupCreates a copy of self
[const,iter]Edgeeach_edgeIterates over the edges that make up the polygon
[const,iter]Edgeeach_edge(unsigned int contour)Iterates over the edges of one contour of the polygon
[const,iter]Pointeach_point_hole(unsigned int n)Iterates over the points that make up the nth hole
[const,iter]Pointeach_point_hullIterates over the points that make up the hull
[const]variant[]extract_radExtracts the corner radii from a rounded polygon
[const]unsigned longhashComputes a hash value
[const]unsigned intholesReturns the number of holes
voidhull=(Point[] p)Sets the points of the hull of polygon
voidinsert_hole(Point[] p,
bool raw = false)
Inserts a hole with the given points
voidinsert_hole(const Box b)Inserts a hole from the given box
[const]boolinside?(Point p)Tests, if the given point is inside the polygon
[const]boolis_box?Returns true, if the polygon is a simple box.
[const]boolis_convex?Returns a value indicating whether the polygon is convex
[const]boolis_empty?Returns a value indicating whether the polygon is empty
[const]boolis_halfmanhattan?Returns a value indicating whether the polygon is half-manhattan
[const]boolis_rectilinear?Returns a value indicating whether the polygon is rectilinear
[const]Polygonminkowski_sum(const Edge e,
bool resolve_holes)
Computes the Minkowski sum of the polygon and an edge
[const]Polygonminkowski_sum(const Polygon b,
bool resolve_holes)
Computes the Minkowski sum of the polygon and a polygon
[const]Polygonminkowski_sum(const Box b,
bool resolve_holes)
Computes the Minkowski sum of the polygon and a box
[const]Polygonminkowski_sum(Point[] b,
bool resolve_holes)
Computes the Minkowski sum of the polygon and a contour of points (a trace)
Polygonmove(const Vector p)Moves the polygon.
Polygonmove(int x,
int y)
Moves the polygon.
[const]Polygonmoved(const Vector p)Returns the moved polygon (does not modify self)
[const]Polygonmoved(int x,
int y)
Returns the moved polygon (does not modify self)
[const]unsigned longnum_pointsGets the total number of points (hull plus holes)
[const]unsigned longnum_points_hole(unsigned int n)Gets the number of points of the given hole
[const]unsigned longnum_points_hullGets the number of points of the hull
[const]unsigned longperimeterGets the perimeter of the polygon
[const]Pointpoint_hole(unsigned int n,
unsigned long p)
Gets a specific point of a hole
[const]Pointpoint_hull(unsigned long p)Gets a specific point of the hull
voidresolve_holesResolve holes by inserting cut lines and joining the holes with the hull
[const]Polygonresolved_holesReturns a polygon without holes
[const]Polygonround_corners(double rinner,
double router,
unsigned int n)
Rounds the corners of the polygon
voidsize(int dx,
int dy,
unsigned int mode)
Sizes the polygon (biasing)
voidsize(const Vector dv,
unsigned int mode = 2)
Sizes the polygon (biasing)
voidsize(int d,
unsigned int mode = 2)
Sizes the polygon (biasing)
[const]Polygonsized(int dx,
int dy,
unsigned int mode)
Sizes the polygon (biasing) without modifying self
[const]Polygonsized(const Vector dv,
unsigned int mode = 2)
Sizes the polygon (biasing) without modifying self
[const]Polygonsized(int d,
unsigned int mode = 2)
Sizes the polygon (biasing) without modifying self
[const]Polygonsmooth(int d,
bool keep_hv = false)
Smooths a polygon
voidsort_holesBrings the holes in a specific order
[const]Polygon[]splitSplits the polygon into two or more parts
[const]DPolygonto_dtype(double dbu = 1)Converts the polygon to a floating-point coordinate polygon
[const]stringto_sReturns a string representing the polygon
[const]SimplePolygonto_simple_polygonConverts a polygon to a simple polygon
[const]booltouches?(const Box box)Returns true, if the polygon touches the given box.
[const]booltouches?(const Edge edge)Returns true, if the polygon touches the given edge.
[const]booltouches?(const Polygon polygon)Returns true, if the polygon touches the other polygon.
[const]booltouches?(const SimplePolygon simple_polygon)Returns true, if the polygon touches the other polygon.
Polygon ptrtransform(const ICplxTrans t)Transforms the polygon with a complex transformation (in-place)
Polygon ptrtransform(const Trans t)Transforms the polygon (in-place)
[const]Polygontransformed(const Trans t)Transforms the polygon
[const]DPolygontransformed(const CplxTrans t)Transforms the polygon with a complex transformation

Public static methods and constants

[static,const]intPO_anyA value for the preferred orientation parameter of decompose_convex
[static,const]intPO_horizontalA value for the preferred orientation parameter of decompose_convex
[static,const]intPO_htrapezoidsA value for the preferred orientation parameter of decompose_convex
[static,const]intPO_verticalA value for the preferred orientation parameter of decompose_convex
[static,const]intPO_vtrapezoidsA value for the preferred orientation parameter of decompose_convex
[static,const]intTD_htrapezoidsA value for the mode parameter of decompose_trapezoids
[static,const]intTD_simpleA value for the mode parameter of decompose_trapezoids
[static,const]intTD_vtrapezoidsA value for the mode parameter of decompose_trapezoids
new Polygon ptrellipse(const Box box,
int n)
Creates a simple polygon approximating an ellipse
new Polygon ptrfrom_s(string s)Creates a polygon from a string

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 Polygon ptrfrom_dpoly(const DPolygon dpolygon)Use of this method is deprecated. Use new instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead
[const]Polygonminkowsky_sum(const Edge e,
bool resolve_holes)
Use of this method is deprecated. Use minkowski_sum instead
[const]Polygonminkowsky_sum(const Polygon b,
bool resolve_holes)
Use of this method is deprecated. Use minkowski_sum instead
[const]Polygonminkowsky_sum(const Box b,
bool resolve_holes)
Use of this method is deprecated. Use minkowski_sum instead
[const]Polygonminkowsky_sum(Point[] b,
bool resolve_holes)
Use of this method is deprecated. Use minkowski_sum instead
[const]Polygontransformed(const ICplxTrans t)Use of this method is deprecated
[const]DPolygontransformed_cplx(const CplxTrans t)Use of this method is deprecated. Use transformed instead

Detailed description

!=

Signature: [const] bool != (const Polygon p)

Description: Returns a value indicating whether the polygons are not equal

p:The object to compare against

*

Signature: [const] Polygon * (double f)

Description: Scales the polygon by some factor

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

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

<

Signature: [const] bool < (const Polygon p)

Description: Returns a value indicating whether self is less than p

p:The object to compare against

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

==

Signature: [const] bool == (const Polygon p)

Description: Returns a value indicating whether the polygons are equal

p:The object to compare against

PO_any

Signature: [static,const] int PO_any

Description: A value for the preferred orientation parameter of decompose_convex

This value indicates that there is not cut preference This constant has been introduced in version 0.25.

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

PO_horizontal

Signature: [static,const] int PO_horizontal

Description: A value for the preferred orientation parameter of decompose_convex

This value indicates that there only horizontal cuts are allowed This constant has been introduced in version 0.25.

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

PO_htrapezoids

Signature: [static,const] int PO_htrapezoids

Description: A value for the preferred orientation parameter of decompose_convex

This value indicates that cuts shall favor decomposition into horizontal trapezoids This constant has been introduced in version 0.25.

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

PO_vertical

Signature: [static,const] int PO_vertical

Description: A value for the preferred orientation parameter of decompose_convex

This value indicates that there only vertical cuts are allowed This constant has been introduced in version 0.25.

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

PO_vtrapezoids

Signature: [static,const] int PO_vtrapezoids

Description: A value for the preferred orientation parameter of decompose_convex

This value indicates that cuts shall favor decomposition into vertical trapezoids This constant has been introduced in version 0.25.

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

TD_htrapezoids

Signature: [static,const] int TD_htrapezoids

Description: A value for the mode parameter of decompose_trapezoids

This value indicates simple decomposition mode. This mode produces horizontal trapezoids and tries to minimize the number of trapezoids. This constant has been introduced in version 0.25.

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

TD_simple

Signature: [static,const] int TD_simple

Description: A value for the mode parameter of decompose_trapezoids

This value indicates simple decomposition mode. This mode is fast but does not make any attempts to produce less trapezoids. This constant has been introduced in version 0.25.

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

TD_vtrapezoids

Signature: [static,const] int TD_vtrapezoids

Description: A value for the mode parameter of decompose_trapezoids

This value indicates simple decomposition mode. This mode produces vertical trapezoids and tries to minimize the number of trapezoids.

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

_const_cast

Signature: [const] Polygon 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] long area

Description: Gets the area of the polygon

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

Signature: [const] long area2

Description: Gets the double area of the polygon

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

Signature: void assign (const Polygon other)

Description: Assigns another object to self

assign_hole

(1) Signature: void assign_hole (unsigned int n, Point[] p, bool raw = false)

Description: Sets the points of the given hole of the polygon

n:The index of the hole to which the points should be assigned
p:An array of points to assign to the polygon's hole
raw:If true, the points won't be compressed (see assign_hull)

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.

(2) Signature: void assign_hole (unsigned int n, const Box b)

Description: Sets the box as the given hole of the polygon

n:The index of the hole to which the points should be assigned
b:The box to assign to the polygon's hole

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

assign_hull

Signature: void assign_hull (Point[] p, bool raw = false)

Description: Sets the points of the hull of polygon

p:An array of points to assign to the polygon's hull
raw:If true, the points won't be compressed

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

Signature: [const] Box bbox

Description: Returns the bounding box of the polygon

The bounding box is the box enclosing all points of the polygon.

break

Signature: [const] Polygon[] break (unsigned long max_vertex_count, double max_area_ratio)

Description: Splits the polygon into parts with a maximum vertex count and area ratio

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.

Python specific notes:
This attribute is available as 'break_' in Python.

compress

Signature: void compress (bool remove_reflected)

Description: Compresses the polygon.

remove_reflected:See description of the functionality.

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

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.

decompose_convex

Signature: [const] SimplePolygon[] decompose_convex (int preferred_orientation = PO_any)

Description: Decomposes the polygon into convex pieces

preferred_orientation:One of the PO_... constants

This method returns a decomposition of the polygon that contains convex pieces only. If the polygon was convex already, the list returned has a single element which is the original polygon.

This method was introduced in version 0.25.

decompose_trapezoids

Signature: [const] SimplePolygon[] decompose_trapezoids (int mode = TD_simple)

Description: Decomposes the polygon into trapezoids

mode:One of the TD_... constants

This method returns a decomposition of the polygon into trapezoid pieces. It supports different modes for various applications. See the TD_... constants for details.

This method was introduced in version 0.25.

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 Polygon ptr dup

Description: Creates a copy of self

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

each_edge

(1) Signature: [const,iter] Edge each_edge

Description: Iterates over the edges that make up the polygon

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

(2) Signature: [const,iter] Edge each_edge (unsigned int contour)

Description: Iterates over the edges of one contour of the polygon

contour:The contour number (0 for hull, 1 for first hole ...)

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

Signature: [const,iter] Point each_point_hole (unsigned int n)

Description: Iterates over the points that make up the nth hole

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

each_point_hull

Signature: [const,iter] Point each_point_hull

Description: Iterates over the points that make up the hull

ellipse

Signature: [static] new Polygon ptr ellipse (const Box box, int n)

Description: Creates a simple polygon approximating an ellipse

box:The bounding box of the ellipse
n:The number of points that will be used to approximate the ellipse

This method has been introduced in version 0.23.

extract_rad

Signature: [const] variant[] extract_rad

Description: Extracts the corner radii from a rounded polygon

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_dpoly

Signature: [static] new Polygon ptr from_dpoly (const DPolygon dpolygon)

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

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_dpolygon'.

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

from_s

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

Description: Creates a polygon 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 polygon. This method enables polygons as hash keys.

This method has been introduced in version 0.25.

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

holes

Signature: [const] unsigned int holes

Description: Returns the number of holes

hull=

Signature: void hull= (Point[] p)

Description: Sets the points of the hull of polygon

p:An array of points to assign to the polygon's hull

The 'assign_hull' variant is provided in analogy to 'assign_hole'.

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

insert_hole

(1) Signature: void insert_hole (Point[] p, bool raw = false)

Description: Inserts a hole with the given points

p:An array of points to insert as a new hole
raw:If true, the points won't be compressed (see assign_hull)

The 'raw' argument was added in version 0.24.

(2) Signature: void insert_hole (const Box b)

Description: Inserts a hole from the given box

b:The box to insert as a new hole

This method was introduced in version 0.23.

inside?

Signature: [const] bool inside? (Point p)

Description: Tests, if the given point is inside the polygon

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?

Signature: [const] bool is_box?

Description: Returns true, if the polygon is a simple box.

Returns:True if the polygon is a 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?

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_convex?

Signature: [const] bool is_convex?

Description: Returns a value indicating whether the polygon is convex

This method will return true, if the polygon is convex.

This method was introduced in version 0.25.

is_empty?

Signature: [const] bool is_empty?

Description: Returns a value indicating whether the polygon is empty

is_halfmanhattan?

Signature: [const] bool is_halfmanhattan?

Description: Returns a value indicating whether the polygon is half-manhattan

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?

Signature: [const] bool is_rectilinear?

Description: Returns a value indicating whether the polygon is rectilinear

minkowski_sum

(1) Signature: [const] Polygon minkowski_sum (const Edge e, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and an edge

e:The edge.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum with the edge e.

The Minkowski sum of a polygon and an edge basically results in the area covered when "dragging" the polygon along the line given by the edge. The effect is similar to drawing the line with a pencil that has the shape of the given polygon.

This method was introduced in version 0.22.

(2) Signature: [const] Polygon minkowski_sum (const Polygon b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a polygon

p:The first argument.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and p.

This method was introduced in version 0.22.

(3) Signature: [const] Polygon minkowski_sum (const Box b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a box

b:The box.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and the box.

This method was introduced in version 0.22.

(4) Signature: [const] Polygon minkowski_sum (Point[] b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a contour of points (a trace)

b:The contour (a series of points forming the trace).
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and the contour.

This method was introduced in version 0.22.

minkowsky_sum

(1) Signature: [const] Polygon minkowsky_sum (const Edge e, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and an edge

e:The edge.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum with the edge e.

Use of this method is deprecated. Use minkowski_sum instead

The Minkowski sum of a polygon and an edge basically results in the area covered when "dragging" the polygon along the line given by the edge. The effect is similar to drawing the line with a pencil that has the shape of the given polygon.

This method was introduced in version 0.22.

(2) Signature: [const] Polygon minkowsky_sum (const Polygon b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a polygon

p:The first argument.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and p.

Use of this method is deprecated. Use minkowski_sum instead

This method was introduced in version 0.22.

(3) Signature: [const] Polygon minkowsky_sum (const Box b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a box

b:The box.
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and the box.

Use of this method is deprecated. Use minkowski_sum instead

This method was introduced in version 0.22.

(4) Signature: [const] Polygon minkowsky_sum (Point[] b, bool resolve_holes)

Description: Computes the Minkowski sum of the polygon and a contour of points (a trace)

b:The contour (a series of points forming the trace).
resolve_holes:If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.
Returns:The new polygon representing the Minkowski sum of self and the contour.

Use of this method is deprecated. Use minkowski_sum instead

This method was introduced in version 0.22.

move

(1) Signature: Polygon move (const Vector p)

Description: Moves the polygon.

p:The distance to move the polygon.
Returns:The moved polygon (self).

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.

(2) Signature: Polygon move (int x, int y)

Description: Moves the polygon.

x:The x distance to move the polygon.
y:The y distance to move the polygon.
Returns:The moved polygon (self).

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

moved

(1) Signature: [const] Polygon moved (const Vector p)

Description: Returns the moved polygon (does not modify self)

p:The distance to move the polygon.
Returns:The moved polygon.

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.

(2) Signature: [const] Polygon moved (int x, int y)

Description: Returns the moved polygon (does not modify self)

x:The x distance to move the polygon.
y:The y distance to move the polygon.
Returns:The moved polygon.

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

(1) Signature: [static] new Polygon ptr new (const DPolygon dpolygon)

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

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

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

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

Description: Creates an empty (invalid) polygon

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

(3) Signature: [static] new Polygon ptr new (const SimplePolygon sp)

Description: Creates a polygon from a simple polygon

sp:The simple polygon that is converted into the polygon

This method was introduced in version 0.22.

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

(4) Signature: [static] new Polygon ptr new (Point[] pts, bool raw = false)

Description: Creates a polygon from a point array for the hull

pts:The points forming the polygon hull
raw:If true, the point list won't be modified (see assign_hull)

The 'raw' argument was added in version 0.24.

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

(5) Signature: [static] new Polygon ptr new (const Box box)

Description: Creates a polygon from a box

box:The box to convert to a polygon

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

num_points

Signature: [const] unsigned long num_points

Description: Gets the total number of points (hull plus holes)

This method was introduced in version 0.18.

num_points_hole

Signature: [const] unsigned long num_points_hole (unsigned int n)

Description: Gets the number of points of the given 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

Signature: [const] unsigned long num_points_hull

Description: Gets the number of points of the hull

perimeter

Signature: [const] unsigned long perimeter

Description: Gets the perimeter of the polygon

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

Signature: [const] Point point_hole (unsigned int n, unsigned long p)

Description: Gets a specific point of a hole

n:The index of the hole to which the points should be assigned
p:The index of the point to get

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

Signature: [const] Point point_hull (unsigned long p)

Description: Gets a specific point of the hull

p:The index of the point to get

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

resolve_holes

Signature: void resolve_holes

Description: Resolve holes by inserting cut lines and joining the holes with the hull

This method modifies the polygon. The out-of-place version is resolved_holes. This method was introduced in version 0.22.

resolved_holes

Signature: [const] Polygon resolved_holes

Description: Returns a polygon without holes

Returns:The new polygon without holes.

This method does not modify the polygon but return a new polygon. This method was introduced in version 0.22.

round_corners

Signature: [const] Polygon round_corners (double rinner, double router, unsigned int n)

Description: Rounds the corners of the polygon

rinner:The circle radius of inner corners (in database units).
router:The circle radius of outer corners (in database units).
n:The number of points per full circle.
Returns:The new polygon.

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

(1) Signature: void size (int dx, int dy, unsigned int mode)

Description: Sizes the polygon (biasing)

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)

(2) Signature: void size (const Vector dv, unsigned int mode = 2)

Description: Sizes the polygon (biasing)

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.

(3) Signature: void size (int d, unsigned int mode = 2)

Description: Sizes the polygon (biasing)

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

(1) Signature: [const] Polygon sized (int dx, int dy, unsigned int mode)

Description: Sizes the polygon (biasing) without modifying self

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.

(2) Signature: [const] Polygon sized (const Vector dv, unsigned int mode = 2)

Description: Sizes the polygon (biasing) without modifying self

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.

(3) Signature: [const] Polygon sized (int d, unsigned int mode = 2)

Description: Sizes the polygon (biasing) without modifying self

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

sized(d, d, mode)

See size and sized for a detailed description.

smooth

Signature: [const] Polygon smooth (int d, bool keep_hv = false)

Description: Smooths a polygon

d:The smoothing "roughness".
keep_hv:If true, horizontal and vertical edges will be preserved always.
Returns:The smoothed polygon.

Remove vertices that deviate by more than the distance d from the average contour. The value d is basically the roughness which is removed.

This method was introduced in version 0.23. The 'keep_hv' optional parameter was added in version 0.27.

sort_holes

Signature: void sort_holes

Description: Brings the holes in a specific order

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

Signature: [const] Polygon[] split

Description: Splits the polygon into two or more parts

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_dtype

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

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

The database unit can be specified to translate the integer-coordinate polygon into a floating-point coordinate polygon 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

Description: Returns a string representing the polygon

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

to_simple_polygon

Signature: [const] SimplePolygon to_simple_polygon

Description: Converts a polygon to a simple polygon

Returns:The simple polygon.

If the polygon contains holes, these will be resolved. This operation requires a well-formed polygon. Reflecting edges, self-intersections and coincident points will be removed.

This method was introduced in version 0.22.

touches?

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

Description: Returns true, if the polygon touches the given box.

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.

(2) Signature: [const] bool touches? (const Edge edge)

Description: Returns true, if the polygon touches the given edge.

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.

(3) Signature: [const] bool touches? (const Polygon polygon)

Description: Returns true, if the polygon touches the other polygon.

The polygons touch if they overlap or their contours share at least one point.

This method was introduced in version 0.25.1.

(4) Signature: [const] bool touches? (const SimplePolygon simple_polygon)

Description: Returns true, if the polygon touches the other polygon.

The polygons touch if they overlap or their contours share at least one point.

This method was introduced in version 0.25.1.

transform

(1) Signature: Polygon ptr transform (const ICplxTrans t)

Description: Transforms the polygon with a complex transformation (in-place)

t:The transformation to apply.

Transforms the polygon with the given complex transformation. This version modifies self and will return self as the modified polygon. An out-of-place version which does not modify self is transformed.

This method was introduced in version 0.24.

(2) Signature: Polygon ptr transform (const Trans t)

Description: Transforms the polygon (in-place)

t:The transformation to apply.

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

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

Description: Transforms the polygon with a complex transformation

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

Use of this method is deprecated

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

This method was introduced in version 0.18.

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

Description: Transforms the polygon

t:The transformation to apply.
Returns:The transformed polygon.

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

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

Description: Transforms the polygon with a complex transformation

t:The transformation to apply.
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

Signature: [const] DPolygon transformed_cplx (const CplxTrans t)

Description: Transforms the polygon with a complex transformation

t:The transformation to apply.
Returns:The transformed polygon.

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.