API reference - Class SimplePolygon

Notation used in Ruby API documentation

Description: A simple polygon class

A simple polygon consists of an outer hull only. To support polygons with holes, use Polygon. The hull 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.

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.

The SimplePolygon class stores coordinates in integer format. A class that stores floating-point coordinates is DSimplePolygon.

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

Public constructors

new SimplePolygon ptrnewDefault constructor: creates an empty (invalid) polygon
new SimplePolygon ptrnew(Point[] pts,
bool raw = false)
Constructor given the points of the simple polygon
new SimplePolygon ptrnew(const Box box)Constructor converting a box to a polygon

Public methods

[const]bool!=(const SimplePolygon p)Inequality test
[const]SimplePolygon*(double f)Scaling by some factor
[const]bool==(const SimplePolygon p)Equality test
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]longareaThe area of the polygon
voidassign(const SimplePolygon other)Assigns another object to self
[const]BoxbboxReturn the bounding box of the simple polygon
voidcompress(bool remove_reflected)Compress the simple polygon.
[const]new SimplePolygon ptrdupCreates a copy of self
[iter]Edgeeach_edgeIterate over the edges that make up the simple polygon
[const,iter]Pointeach_pointIterate over the points that make up the simple polygon
[const]boolinside?(Point p)Test, if the given point is inside the polygon
[const]boolis_box?Returns true, if the polygon is a simple box.
[const]Polygonminkowsky_sum(const Edge a,
bool b)
Compute the Minkowsky sum of a polygon and an edge
[const]Polygonminkowsky_sum(const SimplePolygon 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)
SimplePolygonmove(const Point p)Moves the simple polygon.
SimplePolygonmove(int x,
int y)
Moves the polygon.
[const]SimplePolygonmoved(const Point p)Returns the moved simple polygon
[const]SimplePolygonmoved(int x,
int y)
Returns the moved polygon (does not modify self)
unsigned longnum_pointsGet the number of points
[const]intperimeterThe perimeter of the polygon
Pointpoint(unsigned long arg1)Get a specific point of the contour@args p
voidpoints=(Point[] pts)Set the points of the simple polygon
[const]Polygonround_corners(double rinner,
double router,
unsigned int n)
Round the corners of the polygon
voidset_points(Point[] pts,
bool raw = false)
Set the points of the simple polygon
[const]stringto_sConvert to a string
SimplePolygon ptrtransform(const Trans t)Transforms the simple polygon (in-place)
SimplePolygon ptrtransform(const ICplxTrans t)Transforms the simple polygon with a complex transformation (in-place)
[const]SimplePolygontransformed(const Trans t)Transforms the simple polygon.
[const]DSimplePolygontransformed(const CplxTrans t)Transforms the simple polygon.
[const]SimplePolygontransformed(const ICplxTrans t)Transform the simple polygon.

Public static methods and constants

new SimplePolygon ptrellipse(const Box box,
int n)
Creates a simple polygon appoximating an ellipse
SimplePolygonfrom_dpoly(const DSimplePolygon double_poly)Construct an integer-coordinate polygon from a floating-point coordinate one
new SimplePolygon ptrfrom_s(string s)Creates an object 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
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead
[static]new SimplePolygon ptrnew_b(const Box box)Use of this method is deprecated. Use new instead
[static]new SimplePolygon ptrnew_p(Point[] pts,
bool raw = false)
Use of this method is deprecated. Use new instead
unsigned longpointsUse of this method is deprecated. Use num_points instead
SimplePolygon ptrtransform_cplx(const ICplxTrans t)Use of this method is deprecated. Use transform instead
[const]DSimplePolygontransformed_cplx(const CplxTrans t)Use of this method is deprecated. Use transformed instead
[const]SimplePolygontransformed_cplx(const ICplxTrans t)Use of this method is deprecated. Use transformed instead

Detailed description

[const] bool !=(const SimplePolygon p)

Description: Inequality test

p:The object to compare against

[const] SimplePolygon *(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 SimplePolygon p)

Description: Equality test

p:The object to compare against

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

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.

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

void assign(const SimplePolygon other)

Description: Assigns another object to self

[const] Box bbox

Description: Return the bounding box of the simple polygon

void compress(bool remove_reflected)

Description: Compress the simple 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 of this method is deprecated. Use _create instead

void destroy

Description: 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 SimplePolygon ptr dup

Description: Creates a copy of self

[iter] Edge each_edge

Description: Iterate over the edges that make up the simple polygon

[const,iter] Point each_point

Description: Iterate over the points that make up the simple polygon

[static] new SimplePolygon ptr ellipse(const Box box,int n)

Description: Creates a simple polygon appoximating 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.

[static] SimplePolygon from_dpoly(const DSimplePolygon 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 SimplePolygon 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] bool inside?(Point p)

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

If the given point is inside or on the edge 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.

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

SimplePolygon move(const Point p)

Description: Moves the simple polygon.

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

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

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

[const] SimplePolygon moved(const Point p)

Description: Returns the moved simple polygon

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

Moves the simple polygon by the given offset and returns the moved simple polygon. The polygon is not modified.

[const] SimplePolygon 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.

[static] new SimplePolygon ptr new

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

Python specific notes:

This method is the default initializer of the object

[static] new SimplePolygon ptr new(Point[] pts,bool raw = false)

Description: Constructor given the points of the simple polygon

pts:The points forming the simple polygon
raw:If true, the points are taken as they are (see below)

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 'raw' argument has been added in version 0.24.

Python specific notes:

This method is the default initializer of the object

[static] new SimplePolygon ptr new(const Box box)

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

Python specific notes:

This method is the default initializer of the object

[static] new SimplePolygon ptr new_b(const Box box)

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

Use of this method is deprecated. Use new instead

[static] new SimplePolygon ptr new_p(Point[] pts,bool raw = false)

Description: Constructor given the points of the simple polygon

pts:The points forming the simple polygon
raw:If true, the points are taken as they are (see below)

Use of this method is deprecated. Use new instead

unsigned long num_points

Description: Get the number of points

Python specific notes:

The object exposes a readable attribute 'points'. This is the getter.

[const] int perimeter

Description: The perimeter of the polygon

The perimeter is sum of the lengths of all edges making up the polygon.

Point point(unsigned long arg1)

Description: Get a specific point of the contour@args p

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 long points

Description: Get the number of points

Use of this method is deprecated. Use num_points instead

void points=(Point[] pts)

Description: Set the points of the simple polygon

pts:An array of points to assign to the simple polygon

See the constructor description for details about raw mode.

Python specific notes:

The object exposes a writable attribute 'points'. This is the setter.

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

void set_points(Point[] pts,bool raw = false)

Description: Set the points of the simple polygon

pts:An array of points to assign to the simple polygon
raw:If true, the points are taken as they are

See the constructor description for details about raw mode.

This method has been added in version 0.24.

[const] string to_s

Description: Convert to a string

Python specific notes:

This method is also available as 'str(object)'

SimplePolygon ptr transform(const Trans t)

Description: Transforms the simple polygon (in-place)

t:The transformation to apply.

Transforms the simple 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.

SimplePolygon ptr transform(const ICplxTrans t)

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

t:The transformation to apply.

Transforms the simple 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.

SimplePolygon ptr transform_cplx(const ICplxTrans t)

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

t:The transformation to apply.

Use of this method is deprecated. Use transform instead

[const] SimplePolygon transformed(const Trans t)

Description: Transforms the simple polygon.

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

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

[const] DSimplePolygon transformed(const CplxTrans t)

Description: Transforms the simple polygon.

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

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

[const] SimplePolygon transformed(const ICplxTrans t)

Description: Transform the simple polygon.

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

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

This method has been introduced in version 0.18.

[const] DSimplePolygon transformed_cplx(const CplxTrans t)

Description: Transforms the simple polygon.

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

Use of this method is deprecated. Use transformed instead

[const] SimplePolygon transformed_cplx(const ICplxTrans t)

Description: Transform the simple polygon.

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

Use of this method is deprecated. Use transformed instead