KLayout Manual: Main Index » Class Index » API reference - Class Polygon

API reference - Class Polygon

Notation used in Ruby API documentation

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 over- lapping. This must be ensured by the user of the object when filling the contours.

Public constructors

new PolygonnewDefault constructor: creates an empty (invalid) polygon
new Polygonnew(const SimplePolygon sp)Constructor from a simple polygon
new Polygonnew(Point[] pts)Constructor given the points of the polygon hull
new Polygonnew(const Box box)Constructor converting a box to a polygon

Public methods

[const]bool!=(const Polygon p)Inequality test
[const]bool<(const Polygon p)Less operator
[const]bool==(const Polygon p)Equality test
[const]long longareaThe area of the polygon
[const]voidassign(const Polygon other)Assign the contents of another object to self
voidassign_hole(unsigned int n,
Point[] p)
Set the points of the given hole of the polygon
voidassign_hull(Point[] p)Set the points of the hull of polygon
[const]BoxbboxReturn the bounding box of the polygon
voidcompress(bool remove_reflected)Compress the polygon.
voidcreateEnsures the C++ object is created
voiddestroyExplicitly destroy the object
[const]booldestroyed?Returns a value indicating whether the object was already destroyed
[const]PolygondupCreates a copy of self
[iter]Edgeeach_edgeIterate over the edges that make up the polygon
[const,iter]Pointeach_point_hole(unsigned int n)Iterate over the points that make up the nth hole
[const,iter]Pointeach_point_hullIterate over the points that make up the hull
[const]unsigned intholesGet the number of holes
voidhull=(Point[] p)Set the points of the hull of polygon
voidinsert_hole(Point[] p)Insert a hole with the given points
[const]boolinside?(Point p)Test, if the given point is inside the polygon
[const]boolis_const_object?Returns a value indicating whether the reference is a const reference
[const]Polygonminkowsky_sum(const Edge a,
bool b)
Compute the Minkowsky sum of a polygon and an edge
[const]Polygonminkowsky_sum(const Polygon a,
bool b)
Compute the Minkowsky sum of a polygon and a polygon
[const]Polygonminkowsky_sum(const Box a,
bool b)
Compute the Minkowsky sum of a polygon and a box
[const]Polygonminkowsky_sum(Point[] a,
bool b)
Compute the Minkowsky sum of a polygon and a contour of points (a trace)
Polygonmove(const Point p)Moves the polygon.
[const]Polygonmoved(const Point p)Returns the moved polygon
unsigned intnum_pointsGet the total number of points (hull plus holes)
unsigned intnum_points_hole(unsigned int n)Get the number of points of the given hole
unsigned intnum_points_hullGet the number of points of the hull
Pointpoint_hole(unsigned int n,
unsigned int p)
Get a specific point of a hole
Pointpoint_hull(unsigned int p)Get 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)
Round the corners of the polygon
voidsize(int dx,
int dy,
unsigned int mode)
Sizing (biasing)
voidsize(int d,
unsigned int mode)
Sizing (biasing)
[const]stringto_sConvert to a string
[const]SimplePolygonto_simple_polygonConverts a polygon to a simple polygon
[const]Polygontransformed(const Trans t)Transform the polygon
[const]DPolygontransformed_cplx(const CplxTrans t)Transform the polygon with a complex transformation
[const]Polygontransformed_cplx(const ICplxTrans t)Transform the polygon with a complex transformation

Public static methods and constants

Polygonfrom_dpoly(const DPolygon double_poly)Construct an integer-coordinate polygon from a floating-point coordinate one

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

[const]boolinside(Point p)Use of this method is deprecated. Use inside? instead
[static]new Polygonnew_b(const Box box)Use of this method is deprecated. Use new instead
[static]new Polygonnew_p(Point[] pts)Use of this method is deprecated. Use new instead
unsigned intpointsUse of this method is deprecated. Use num_points instead
unsigned intpoints_hole(unsigned int n)Use of this method is deprecated. Use num_points_hole instead
unsigned intpoints_hullUse of this method is deprecated. Use num_points_hull instead

Detailed description

[const] bool !=(const Polygon p)

Description: Inequality test

p:The object to compare against

[const] bool <(const Polygon p)

Description: Less operator

p:The object to compare against

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

[const] bool ==(const Polygon p)

Description: Equality test

p:The object to compare against

[const] long long area

Description: The area of the polygon

The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise.

[const] void assign(const Polygon other)

Description: Assign the contents of another object to self

This method assigns the contents of another object to self. This is a deep copy that does not only copy the reference but the actual content.

void assign_hole(unsigned int n,Point[] p)

Description: Set 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

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

void assign_hull(Point[] p)

Description: Set 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'.

[const] Box bbox

Description: Return the bounding box of the polygon

void compress(bool remove_reflected)

Description: Compress 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.

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.

void destroy

Description: Explicitly destroy the object

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

[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.

[const] Polygon dup

Description: Creates a copy of self

[iter] Edge each_edge

Description: Iterate over the edges that make up the polygon

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

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

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

[const,iter] Point each_point_hull

Description: Iterate over the points that make up the hull

[static] Polygon from_dpoly(const DPolygon double_poly)

Description: Construct an integer-coordinate polygon from a floating-point coordinate one

This method has been added in version 0.15.

[const] unsigned int holes

Description: Get the number of holes

void hull=(Point[] p)

Description: Set 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'.

void insert_hole(Point[] p)

Description: Insert a hole with the given points

p:An array of points to insert as a new hole

[const] bool inside(Point p)

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

This method is deprecated. Use method 'inside?' instead

[const] bool inside?(Point p)

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

If the given point is inside the polygon, true is returned. This tests works well only if the polygon is not self-overlapping and oriented clockwise.

[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.

[const] Polygon minkowsky_sum(const Edge a,bool b)

Description: Compute the Minkowsky sum of a polygon and an edge

a:The first argument.
b:The second 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 Minkowsky sum of a and b.

This method was introduced in version 0.22.

[const] Polygon minkowsky_sum(const Polygon a,bool b)

Description: Compute the Minkowsky sum of a polygon and a polygon

a:The first argument.
b:The second 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 Minkowsky sum of a and b.

This method was introduced in version 0.22.

[const] Polygon minkowsky_sum(const Box a,bool b)

Description: Compute the Minkowsky sum of a polygon and a box

a:The first argument.
b:The second 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 Minkowsky sum of a and b.

This method was introduced in version 0.22.

[const] Polygon minkowsky_sum(Point[] a,bool b)

Description: Compute the Minkowsky sum of a polygon and a contour of points (a trace)

a:The first argument.
b:The second argument (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 Minkowsky sum of a and b.

This method was introduced in version 0.22.

Polygon move(const Point p)

Description: Moves the polygon.

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 overwritten.

[const] Polygon moved(const Point p)

Description: Returns the moved polygon

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.

[static] new Polygon new

Description: Default constructor: creates an empty (invalid) polygon

[static] new Polygon new(const SimplePolygon sp)

Description: Constructor from a simple polygon

sp:The simple polygon that is converted into the polygon

This method was introduced in version 0.22.

[static] new Polygon new(Point[] pts)

Description: Constructor given the points of the polygon hull

pts:The points forming the polygon hull

[static] new Polygon new(const Box box)

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

[static] new Polygon new_b(const Box box)

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

This method is deprecated. Use method 'new' instead

[static] new Polygon new_p(Point[] pts)

Description: Constructor given the points of the polygon hull

pts:The points forming the polygon hull

This method is deprecated. Use method 'new' instead

unsigned int num_points

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

This method was introduced in version 0.18.

unsigned int num_points_hole(unsigned int n)

Description: Get 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).

unsigned int num_points_hull

Description: Get the number of points of the hull

Point point_hole(unsigned int n,unsigned int p)

Description: Get 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 point_hull(unsigned int p)

Description: Get 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.

unsigned int points

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

This method is deprecated. Use method 'num_points' instead

unsigned int points_hole(unsigned int n)

Description: Get the number of points of the given hole

This method is deprecated. Use method 'num_points_hole' instead

unsigned int points_hull

Description: Get the number of points of the hull

This method is deprecated. Use method 'num_points_hull' instead

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.

[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.

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

Description: Round 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.

void size(int dx,int dy,unsigned int mode)

Description: Sizing (biasing)

Shifts the contour outwards (dx,dy>0) or inwards (dx,dy<0). May create invalid (self-overlapping, reverse oriented) contours. The sign of dx and dy should be identical.

The mode defines at which bending angle cutoff occurs (0:>0, 1:>45, 2:>90, 3:>135, 4:>approx. 168, other:>approx. 179)

void size(int d,unsigned int mode)

Description: Sizing (biasing)

Shifts the contour outwards (d>0) or inwards (d<0). May 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)

[const] string to_s

Description: Convert to a string

[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 method was introduced in version 0.22.

[const] Polygon transformed(const Trans t)

Description: Transform 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.

[const] DPolygon transformed_cplx(const CplxTrans t)

Description: Transform 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.

[const] Polygon transformed_cplx(const ICplxTrans t)

Description: Transform the polygon with a complex transformation

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

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.