API reference - Class DSimplePolygon

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

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

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

Public constructors

new DSimplePolygonnewDefault constructor: creates an empty (invalid) polygon
new DSimplePolygonnew(DPoint[] pts)Constructor given the points of the simple polygon
new DSimplePolygonnew(const DBox box)Constructor converting a box to a polygon

Public methods

[const]bool!=(const DSimplePolygon arg1)Inequality test
[const]DSimplePolygon*(double f)Scaling by some factor
[const]bool==(const DSimplePolygon arg1)Equality test
[const]doubleareaThe area of the polygon
[const]voidassign(const DSimplePolygon other)Assign the contents of another object to self
[const]DBoxbboxReturn the bounding box of the simple polygon
voidcompress(bool remove_reflected)Compress the simple polygon.
voidcreateEnsures the C++ object is created
voiddestroyExplicitly destroy the object
[const]booldestroyed?Returns a value indicating whether the object was already destroyed
[const]DSimplePolygondupCreates a copy of self
[iter]DEdgeeach_edgeIterate over the edges that make up the simple polygon
[const,iter]DPointeach_pointIterate over the points that make up the simple polygon
[const]boolinside?(DPoint p)Test, if the given point is inside the polygon
[const]boolis_box?Returns true, if the polygon is a simple box.
[const]boolis_const_object?Returns a value indicating whether the reference is a const reference
DSimplePolygonmove(const DPoint p)Moves the simple polygon.
DSimplePolygonmove(double x,
double y)
Moves the polygon.
[const]DSimplePolygonmoved(const DPoint p)Returns the moved simple polygon
[const]DSimplePolygonmoved(double x,
double y)
Returns the moved polygon (does not modify self)
unsigned intnum_pointsGet the number of points
[const]doubleperimeterThe perimeter of the polygon
DPointpoint(unsigned int arg1)Get a specific point of the contour@args p
voidpoints=(DPoint[] p)Set the points of the simple polygon
[const]stringto_sConvert to a string
[const]DSimplePolygontransformed(const DTrans t)Transform the simple polygon.
[const]DSimplePolygontransformed(const DCplxTrans t)Transform the simple polygon.

Public static methods and constants

new DSimplePolygonellipse(const DBox box,
int n)
Creates a simple polygon appoximating an ellipse
DSimplePolygonfrom_ipoly(const SimplePolygon int_poly)Construct a floating-point coordinate polygon from an integer coordinate one
new DSimplePolygonfrom_s(string s)Creates an object from a string

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

[const]boolinside(DPoint p)Use of this method is deprecated. Use inside? instead
[static]new DSimplePolygonnew_b(const DBox box)Use of this method is deprecated. Use new instead
[static]new DSimplePolygonnew_p(DPoint[] pts)Use of this method is deprecated. Use new instead
unsigned intpointsUse of this method is deprecated. Use num_points instead
[const]DSimplePolygontransformed_cplx(const DCplxTrans t)Use of this method is deprecated. Use transformed instead

Detailed description

[const] bool !=(const DSimplePolygon arg1)

Description: Inequality test

[const] DSimplePolygon *(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 DSimplePolygon arg1)

Description: Equality test

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

[const] DBox 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 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] DSimplePolygon dup

Description: Creates a copy of self

[iter] DEdge each_edge

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

[const,iter] DPoint each_point

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

[static] new DSimplePolygon ellipse(const DBox 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] DSimplePolygon from_ipoly(const SimplePolygon int_poly)

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

This method has been added in version 0.15.

[static] new DSimplePolygon 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(DPoint p)

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

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

[const] bool inside?(DPoint 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

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

DSimplePolygon move(const DPoint 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.

DSimplePolygon move(double x,double 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] DSimplePolygon moved(const DPoint 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] DSimplePolygon moved(double x,double 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 DSimplePolygon new

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

[static] new DSimplePolygon new(DPoint[] pts)

Description: Constructor given the points of the simple polygon

pts:The points forming the simple polygon

[static] new DSimplePolygon new(const DBox box)

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

[static] new DSimplePolygon new_b(const DBox 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 DSimplePolygon new_p(DPoint[] pts)

Description: Constructor given the points of the simple polygon

pts:The points forming the simple polygon

This method is deprecated. Use method 'new' instead

unsigned int num_points

Description: Get the number of points

[const] double perimeter

Description: The perimeter of the polygon

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

DPoint point(unsigned int 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 int points

Description: Get the number of points

This method is deprecated. Use method 'num_points' instead

void points=(DPoint[] p)

Description: Set the points of the simple polygon

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

[const] string to_s

Description: Convert to a string

[const] DSimplePolygon transformed(const DTrans t)

Description: Transform 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 DCplxTrans t)

Description: Transform 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] DSimplePolygon transformed_cplx(const DCplxTrans t)

Description: Transform the simple polygon.

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

This method is deprecated. Use method 'transformed' instead