API reference - Class PolygonNotation 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 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
Public methods
Public static methods and constants
Deprecated methods (protected, public, static, non-static and constructors)
Detailed description[const] bool !=(const Polygon p)Description: Inequality test
[const] Polygon *(double f)Description: Scaling by some factor Returns the scaled object. All coordinates are multiplied with the given factor and if necessary rounded. [const] bool <(const Polygon p)Description: Less operator
This operator is provided to establish some, not necessarily a certain sorting order [const] bool ==(const Polygon p)Description: Equality test
void _createDescription: 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 _destroyDescription: 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. [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] 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. void _manageDescription: 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. void _unmanageDescription: 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. [const] long areaDescription: 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. void assign(const Polygon other)Description: Assigns another object to self void assign_hole(unsigned int n,Point[] p,bool raw = false)Description: Set the points of the given hole of the polygon
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. void assign_hole(unsigned int n,const Box b)Description: Set the box as the given hole of the polygon
If the hole index is not valid, this method does nothing. This method was introduced in version 0.23. void assign_hull(Point[] p,bool raw = false)Description: Set the points of the hull of polygon
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. [const] Box bboxDescription: Return the bounding box of the polygon The bounding box is the box enclosing all points of the polygon. void compress(bool remove_reflected)Description: Compress the polygon.
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 createDescription: Ensures the C++ object is created Use of this method is deprecated. Use _create instead void destroyDescription: Explicitly destroys the object Use of this method is deprecated. Use _destroy instead [const] bool destroyed?Description: Returns a value indicating whether the object was already destroyed Use of this method is deprecated. Use _destroyed? instead [const] new Polygon ptr dupDescription: Creates a copy of self [iter] Edge each_edgeDescription: Iterate 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 egdes are oriented clockwise. [iter] Edge each_edge(unsigned int contour)Description: Iterate over the edges of one contour of the polygon
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 egdes are oriented clockwise. This method was introduced in version 0.24. [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_hullDescription: Iterate over the points that make up the hull [static] new Polygon ptr ellipse(const Box box,int n)Description: Creates a simple polygon appoximating an ellipse
This method has been introduced in version 0.23. [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. [static] new Polygon ptr from_s(string s)Description: Creates an 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. [const] unsigned int holesDescription: Returns the number of holes void hull=(Point[] p)Description: Set the points of the hull of polygon
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. void insert_hole(Point[] p,bool raw = false)Description: Insert a hole with the given points
The 'raw' argument was added in version 0.24. void insert_hole(const Box b)Description: Insert a hole from the given box
This method was introduced in version 0.23. [const] bool inside?(Point p)Description: Test, 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. [const] bool is_box?Description: Returns true, if the polygon is a simple box.
A polygon is a box if it is identical to it's bounding box. This method was introduced in version 0.23. [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 [const] Polygon minkowsky_sum(const Edge e,bool resolve_holes)Description: Computes the Minkowsky sum of the polygon and an edge
The Minkowsky 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. [const] Polygon minkowsky_sum(const Polygon p,bool resolve_holes)Description: Computes the Minkowsky sum of the polygon and a polygon
This method was introduced in version 0.22. [const] Polygon minkowsky_sum(const Box b,bool resolve_holes)Description: Computes the Minkowsky sum of the polygon and a box
This method was introduced in version 0.22. [const] Polygon minkowsky_sum(Point[] b,bool resolve_holes)Description: Computes the Minkowsky sum of the polygon and a contour of points (a trace)
This method was introduced in version 0.22. Polygon move(const Point p)Description: Moves the polygon.
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. Polygon move(int x,int y)Description: Moves the 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 (does not modify self)
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. [const] Polygon moved(int x,int y)Description: Returns the moved polygon (does not modify self)
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. [static] new Polygon ptr newDescription: Default constructor: creates an empty (invalid) polygon Python specific notes:This method is the default initializer of the object [static] new Polygon ptr new(const SimplePolygon sp)Description: Constructor from a simple polygon
This method was introduced in version 0.22. Python specific notes:This method is the default initializer of the object [static] new Polygon ptr new(Point[] pts,bool raw = false)Description: Constructor given the points of the polygon hull
The 'raw' argument was added in version 0.24. Python specific notes:This method is the default initializer of the object [static] new Polygon ptr new(const Box box)Description: Constructor converting a box to a polygon
Python specific notes:This method is the default initializer of the object [static] new Polygon ptr new_b(const Box box)Description: Constructor converting a box to a polygon
Use of this method is deprecated. Use new instead [static] new Polygon ptr new_p(Point[] pts,bool raw = false)Description: Constructor given the points of the polygon hull
Use of this method is deprecated. Use new instead unsigned long num_pointsDescription: Get the total number of points (hull plus holes) This method was introduced in version 0.18. unsigned long 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 long num_points_hullDescription: Get the number of points of the hull [const] int perimeterDescription: 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 point_hole(unsigned int n,unsigned long p)Description: Get a specific point of a 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 point_hull(unsigned long p)Description: Get a specific point of the 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. unsigned long pointsDescription: Get the total number of points (hull plus holes) Use of this method is deprecated. Use num_points instead unsigned long points_hole(unsigned int n)Description: Get the number of points of the given hole Use of this method is deprecated. Use num_points_hole instead unsigned long points_hullDescription: Get the number of points of the hull Use of this method is deprecated. Use num_points_hull instead void resolve_holesDescription: 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_holesDescription: Returns a 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: Rounds the corners of the 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). 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) void size(int d,unsigned int mode)Description: Sizing (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. void size(int d)Description: Sizing (biasing) Shifts the contour outwards (d>0) or inwards (d<0). This method is equivalent to size(d, d, 2) See size for a detailed description. [const] Polygon sized(int dx,int dy,unsigned int mode)Description: Sizing (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. [const] Polygon sized(int d,unsigned int mode)Description: Sizing (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. [const] Polygon sized(int d)Description: Sizing (biasing) without modifying self This method is equivalent to sized(d, d, 2) See size and sized for a detailed description. [const] Polygon smooth(int d)Description: Smoothes a 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. [const] string to_sDescription: Convert to a string Python specific notes:This method is also available as 'str(object)' [const] SimplePolygon to_simple_polygonDescription: Converts a polygon to a 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. Polygon ptr transform(const Trans t)Description: Transforms the polygon (in-place)
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. Polygon ptr transform(const ICplxTrans t)Description: Transforms the polygon with a complex transformation (in-place)
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. Polygon ptr transform_cplx(const ICplxTrans t)Description: Transforms the polygon with a complex transformation (in-place)
Use of this method is deprecated. Use transform instead [const] Polygon transformed(const Trans t)Description: Transforms the polygon
Transforms the polygon with the given transformation. Does not modify the polygon but returns the transformed polygon. [const] DPolygon transformed(const CplxTrans t)Description: Transforms the polygon with a complex transformation
Transforms the polygon with the given complex transformation. Does not modify the polygon but returns the transformed polygon. [const] Polygon transformed(const ICplxTrans t)Description: Transforms the polygon with a complex transformation
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. [const] DPolygon transformed_cplx(const CplxTrans t)Description: Transforms the polygon with a complex transformation
Use of this method is deprecated. Use transformed instead [const] Polygon transformed_cplx(const ICplxTrans t)Description: Transforms the polygon with a complex transformation
Use of this method is deprecated. Use transformed instead |