Class DPolygon (version 0.18)

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.

Class overview

Index

Method Overview

[static] DPolygon newDefault constructor: creates an empty (invalid) polygon
[static] DPolygon new( DPoint pts[ ] )Constructor given the points of the polygon hull
[static] DPolygon new( DBox box )Constructor converting a box to a polygon
[const] bool <( DPolygon p )Less operator
[const] bool ==( DPolygon p )Equality test
[const] bool !=( DPolygon p )Inequality test
hull=( DPoint p[ ] )Set the points of the hull of polygon
assign_hole( unsigned int n, DPoint p[ ] )Set the points of the given hole of the polygon
unsigned int pointsGet the total number of points (hull plus holes)
DPoint point_hull( unsigned int p )Get a specific point of the hull@args p
DPoint point_hole( unsigned int n, unsigned int p )Get a specific point of a hole@args n,p
unsigned int points_hullGet the number of points of the hull
unsigned int points_hole( unsigned int n )Get the number of points of the given hole
insert_hole( DPoint p[ ] )Insert a hole with the given points
[const] yield DPoint each_point_hullIterate over the points that make up the hull
[const] yield DPoint each_point_hole( unsigned int n )Iterate over the points that make up the nth hole
size( double dx, double dy, unsigned int mode )Sizing (biasing)
size( double d, unsigned int mode )Sizing (biasing)
[const] unsigned int holesGet the number of holes
yield DEdge each_edgeIterate over the edges that make up the polygon
[const] bool inside( DPoint p )Test, if the given point is inside the polygon
compress( bool remove_reflected )Compress the polygon.
ref DPolygon move( DPoint p )Moves the polygon.
[const] DPolygon moved( DPoint p )Returns the moved polygon
[const] DPolygon transformed( DTrans t )Transform the polygon
[const] DPolygon transformed_cplx( DCplxTrans t )Transform the polygon with a complex transformation
[const] string to_sConvert to a string
[const] double areaThe area of the polygon
[const] const ref DBox bboxReturn the bounding box of the polygon
[static] DPolygon from_ipoly( Polygon int_poly )Construct a floating-point coordinate polygon from an integer coordinate one
assign( DPolygon other )Assign the contents of another object to self
[const] DPolygon dupCreates a copy of self.
destroyExplicitly destroy the object
[const] bool destroyedTell, if the object was destroyed

[const] bool !=( DPolygon p )

Description: Inequality test

p:The object to compare against

[const] bool <( DPolygon p )

Description: Less operator

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

p:The object to compare against

[const] bool ==( DPolygon p )

Description: Equality test

p:The object to compare against

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

assign( DPolygon 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.

assign_hole( unsigned int n, DPoint p[ ] )

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.

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

[const] const ref DBox bbox

Description: Return the bounding box of the polygon

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.

remove_reflected:See description of the functionality.

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: Tell, if the object was 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] DPolygon dup

Description: Creates a copy of self.

yield DEdge each_edge

Description: Iterate over the edges that make up the polygon

[const] yield DPoint 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] yield DPoint each_point_hull

Description: Iterate over the points that make up the hull

[static] DPolygon from_ipoly( Polygon int_poly )

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

This method has been added in version 0.15.

[const] unsigned int holes

Description: Get the number of holes

hull=( DPoint p[ ] )
synonym: assign_hull( DPoint p[ ] )

Description: Set the points of the hull of polygon

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

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

insert_hole( DPoint p[ ] )

Description: Insert a hole with the given points

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

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

ref DPolygon move( DPoint p )

Description: Moves the polygon.

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

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

[const] DPolygon moved( DPoint p )

Description: Returns the moved polygon

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

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

[static] DPolygon new( DPoint pts[ ] )
synonym: [static] DPolygon new_p( DPoint pts[ ] )

Description: Constructor given the points of the polygon hull

pts:The points forming the polygon hull

[static] DPolygon new( DBox box )
synonym: [static] DPolygon new_b( DBox box )

Description: Constructor converting a box to a polygon

box:The box to convert to a polygon

[static] DPolygon new

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

DPoint point_hole( unsigned int n, unsigned int p )

Description: Get a specific point of a hole@args n,p

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.

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

DPoint point_hull( unsigned int p )

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

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

p:The index of the point to get

unsigned int points

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

This method was introduced in version 0.18.

unsigned int 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 points_hull

Description: Get the number of points of the hull

size( double dx, double 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)

size( double 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] DPolygon transformed( DTrans t )

Description: Transform the polygon

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

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

[const] DPolygon transformed_cplx( DCplxTrans t )

Description: Transform the polygon with a complex transformation

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

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