A few utility functions

Polygon#is_rectilinear?, Polygon#is_empty?
and same for SimplePolygon
This commit is contained in:
matthias 2019-07-13 22:45:22 +02:00
parent 5f27341995
commit 8b17a4da4f
3 changed files with 192 additions and 214 deletions

View File

@ -75,6 +75,16 @@ struct simple_polygon_defs
return c->hull ().size (); return c->hull ().size ();
} }
static bool is_rectilinear (C *c)
{
return c->hull ().is_rectilinear ();
}
static bool is_empty (C *c)
{
return c->hull ().size () == 0;
}
static C *from_string (const char *s) static C *from_string (const char *s)
{ {
tl::Extractor ex (s); tl::Extractor ex (s);
@ -260,39 +270,32 @@ struct simple_polygon_defs
"\n" "\n"
"The 'raw' argument has been added in version 0.24.\n" "The 'raw' argument has been added in version 0.24.\n"
) + ) +
constructor ("new", &new_b, constructor ("new", &new_b, gsi::arg ("box"),
"@brief Constructor converting a box to a polygon\n" "@brief Constructor converting a box to a polygon\n"
"\n" "\n"
"@args box\n"
"\n"
"@param box The box to convert to a polygon\n" "@param box The box to convert to a polygon\n"
) + ) +
constructor ("ellipse", &ellipse, constructor ("ellipse", &ellipse, gsi::arg ("box"), gsi::arg ("n"),
"@brief Creates a simple polygon appoximating an ellipse\n" "@brief Creates a simple polygon appoximating an ellipse\n"
"\n" "\n"
"@args box, n\n"
"\n"
"@param box The bounding box of the ellipse\n" "@param box The bounding box of the ellipse\n"
"@param n The number of points that will be used to approximate the ellipse\n" "@param n The number of points that will be used to approximate the ellipse\n"
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method ("<", &C::less, method ("<", &C::less, gsi::arg ("p"),
"@brief Less operator\n" "@brief Returns a value indicating whether self is less than p\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
"This operator is provided to establish some, not necessarily a certain sorting order\n" "This operator is provided to establish some, not necessarily a certain sorting order\n"
"\n" "\n"
"This method has been introduced in version 0.25." "This method has been introduced in version 0.25."
) + ) +
method ("==", &C::equal, method ("==", &C::equal, gsi::arg ("p"),
"@brief Equality test\n" "@brief Returns a value indicating whether self is equal to p\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
) + ) +
method ("!=", &C::not_equal, method ("!=", &C::not_equal, gsi::arg ("p"),
"@brief Inequality test\n" "@brief Returns a value indicating whether self is not equal to p\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
) + ) +
method_ext ("hash", &hash_value, method_ext ("hash", &hash_value,
@ -301,16 +304,15 @@ struct simple_polygon_defs
"\n" "\n"
"This method has been introduced in version 0.25.\n" "This method has been introduced in version 0.25.\n"
) + ) +
method_ext ("points=", &set_points1, method_ext ("points=", &set_points1, gsi::arg ("pts"),
"@brief Set the points of the simple polygon\n" "@brief Sets the points of the simple polygon\n"
"\n" "\n"
"@args pts\n"
"@param pts An array of points to assign to the simple polygon\n" "@param pts An array of points to assign to the simple polygon\n"
"\n" "\n"
"See the constructor description for details about raw mode.\n" "See the constructor description for details about raw mode.\n"
) + ) +
method_ext ("set_points", &set_points, gsi::arg ("pts"), gsi::arg ("raw", false), method_ext ("set_points", &set_points, gsi::arg ("pts"), gsi::arg ("raw", false),
"@brief Set the points of the simple polygon\n" "@brief Sets the points of the simple polygon\n"
"\n" "\n"
"@param pts An array of points to assign to the simple polygon\n" "@param pts An array of points to assign to the simple polygon\n"
"@param raw If true, the points are taken as they are\n" "@param raw If true, the points are taken as they are\n"
@ -319,31 +321,34 @@ struct simple_polygon_defs
"\n" "\n"
"This method has been added in version 0.24.\n" "This method has been added in version 0.24.\n"
) + ) +
method_ext ("point", &point, method_ext ("point", &point, gsi::arg ("p"),
"@brief Get a specific point of the contour" "@brief Gets a specific point of the contour"
"@args p\n"
"@param p The index of the point to get\n" "@param p The index of the point to get\n"
"If the index of the point is not a valid index, a default value is returned.\n" "If the index of the point is not a valid index, a default value is returned.\n"
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
) + ) +
method_ext ("num_points", &num_points, method_ext ("num_points", &num_points,
"@brief Get the number of points" "@brief Gets the number of points"
) + ) +
iterator ("each_point", &C::begin_hull, &C::end_hull, iterator ("each_point", &C::begin_hull, &C::end_hull,
"@brief Iterate over the points that make up the simple polygon" "@brief Iterates over the points that make up the simple polygon"
) + ) +
iterator ("each_edge", &C::begin_edge, iterator ("each_edge", &C::begin_edge,
"@brief Iterate over the edges that make up the simple polygon" "@brief Iterates over the edges that make up the simple polygon"
) + ) +
method_ext ("inside?", &inside, method_ext ("is_empty?", &is_empty,
"@brief Test, if the given point is inside the polygon\n" "@brief Returns a value indicating whether the polygon is empty\n"
"@args p\n" ) +
method_ext ("is_rectilinear?", &is_rectilinear,
"@brief Returns a value indicating whether the polygon is rectilinear\n"
) +
method_ext ("inside?", &inside, gsi::arg ("p"),
"@brief Gets a value indicating whether the given point is inside the polygon\n"
"If the given point is inside or on the edge the polygon, true is returned. " "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. " "This tests works well only if the polygon is not self-overlapping and oriented clockwise. "
) + ) +
method_ext ("compress", &compress, method_ext ("compress", &compress, gsi::arg ("remove_reflected"),
"@brief Compress the simple polygon.\n" "@brief Compressed the simple polygon.\n"
"@args remove_reflected\n"
"\n" "\n"
"This method removes redundant points from the polygon, such as points being on a line formed by two other points.\n" "This method removes redundant points from the polygon, such as points being on a line formed by two other points.\n"
"If remove_reflected is true, points are also removed if the two adjacent edges form a spike.\n" "If remove_reflected is true, points are also removed if the two adjacent edges form a spike.\n"
@ -353,7 +358,7 @@ struct simple_polygon_defs
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
) + ) +
method ("is_box?", &C::is_box, method ("is_box?", &C::is_box,
"@brief Returns true, if the polygon is a simple box.\n" "@brief Returns a value indicating whether the polygon is a simple box.\n"
"\n" "\n"
"A polygon is a box if it is identical to it's bounding box.\n" "A polygon is a box if it is identical to it's bounding box.\n"
"\n" "\n"
@ -361,17 +366,14 @@ struct simple_polygon_defs
"\n" "\n"
"This method was introduced in version 0.23.\n" "This method was introduced in version 0.23.\n"
) + ) +
method_ext ("*", &scale, method_ext ("*", &scale, gsi::arg ("f"),
"@brief Scaling by some factor\n" "@brief Scales the polygon by some factor\n"
"\n"
"@args f\n"
"\n" "\n"
"Returns the scaled object. All coordinates are multiplied with the given factor and if " "Returns the scaled object. All coordinates are multiplied with the given factor and if "
"necessary rounded." "necessary rounded."
) + ) +
method ("move", &C::move, method ("move", &C::move, gsi::arg ("p"),
"@brief Moves the simple polygon.\n" "@brief Moves the simple polygon.\n"
"@args p\n"
"\n" "\n"
"Moves the simple polygon by the given offset and returns the \n" "Moves the simple polygon by the given offset and returns the \n"
"moved simple polygon. The polygon is overwritten.\n" "moved simple polygon. The polygon is overwritten.\n"
@ -380,9 +382,8 @@ struct simple_polygon_defs
"\n" "\n"
"@return The moved simple polygon.\n" "@return The moved simple polygon.\n"
) + ) +
method_ext ("move", &move_xy, method_ext ("move", &move_xy, gsi::arg ("x"), gsi::arg ("y"),
"@brief Moves the polygon.\n" "@brief Moves the polygon.\n"
"@args x,y\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is overwritten.\n" "moved polygon. The polygon is overwritten.\n"
@ -392,9 +393,8 @@ struct simple_polygon_defs
"\n" "\n"
"@return The moved polygon (self).\n" "@return The moved polygon (self).\n"
) + ) +
method ("moved", &C::moved, method ("moved", &C::moved, gsi::arg ("p"),
"@brief Returns the moved simple polygon\n" "@brief Returns the moved simple polygon\n"
"@args p\n"
"\n" "\n"
"Moves the simple polygon by the given offset and returns the \n" "Moves the simple polygon by the given offset and returns the \n"
"moved simple polygon. The polygon is not modified.\n" "moved simple polygon. The polygon is not modified.\n"
@ -403,9 +403,8 @@ struct simple_polygon_defs
"\n" "\n"
"@return The moved simple polygon.\n" "@return The moved simple polygon.\n"
) + ) +
method_ext ("moved", &moved_xy, method_ext ("moved", &moved_xy, gsi::arg ("x"), gsi::arg ("y"),
"@brief Returns the moved polygon (does not modify self)\n" "@brief Returns the moved polygon (does not modify self)\n"
"@args x,y\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is not modified.\n" "moved polygon. The polygon is not modified.\n"
@ -417,9 +416,8 @@ struct simple_polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("transform", &transform, method_ext ("transform", &transform, gsi::arg ("t"),
"@brief Transforms the simple polygon (in-place)\n" "@brief Transforms the simple polygon (in-place)\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given transformation.\n" "Transforms the simple polygon with the given transformation.\n"
"Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n" "Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n"
@ -428,9 +426,8 @@ struct simple_polygon_defs
"\n" "\n"
"This method has been introduced in version 0.24.\n" "This method has been introduced in version 0.24.\n"
) + ) +
method_ext ("transformed", &transformed, method_ext ("transformed", &transformed, gsi::arg ("t"),
"@brief Transforms the simple polygon.\n" "@brief Transforms the simple polygon.\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given transformation.\n" "Transforms the simple polygon with the given transformation.\n"
"Does not modify the simple polygon but returns the transformed polygon.\n" "Does not modify the simple polygon but returns the transformed polygon.\n"
@ -439,9 +436,8 @@ struct simple_polygon_defs
"\n" "\n"
"@return The transformed simple polygon.\n" "@return The transformed simple polygon.\n"
) + ) +
method_ext ("transformed|#transformed_cplx", &transformed_cplx, method_ext ("transformed|#transformed_cplx", &transformed_cplx, gsi::arg ("t"),
"@brief Transforms the simple polygon.\n" "@brief Transforms the simple polygon.\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given complex transformation.\n" "Transforms the simple polygon with the given complex transformation.\n"
"Does not modify the simple polygon but returns the transformed polygon.\n" "Does not modify the simple polygon but returns the transformed polygon.\n"
@ -453,19 +449,17 @@ struct simple_polygon_defs
"With version 0.25, the original 'transformed_cplx' method is deprecated and " "With version 0.25, the original 'transformed_cplx' method is deprecated and "
"'transformed' takes both simple and complex transformations." "'transformed' takes both simple and complex transformations."
) + ) +
constructor ("from_s", &from_string, constructor ("from_s", &from_string, gsi::arg ("s"),
"@brief Creates an object from a string\n" "@brief Creates an object from a string\n"
"@args s\n"
"Creates the object from a string representation (as returned by \\to_s)\n" "Creates the object from a string representation (as returned by \\to_s)\n"
"\n" "\n"
"This method has been added in version 0.23.\n" "This method has been added in version 0.23.\n"
) + ) +
method ("to_s", (std::string (C::*) () const) &C::to_string, method ("to_s", (std::string (C::*) () const) &C::to_string,
"@brief Convert to a string\n" "@brief Returns a string representing the polygon\n"
) + ) +
method_ext ("round_corners", &round_corners, method_ext ("round_corners", &round_corners, gsi::arg ("rinner"), gsi::arg ("router"), gsi::arg ("n"),
"@brief Round the corners of the polygon\n" "@brief Rounds the corners of the polygon\n"
"@args rinner, router, n\n"
"\n" "\n"
"Replaces the corners of the polygon with circle segments.\n" "Replaces the corners of the polygon with circle segments.\n"
"\n" "\n"
@ -516,15 +510,15 @@ struct simple_polygon_defs
"This method has been introduced in version 0.25.3." "This method has been introduced in version 0.25.3."
) + ) +
method_ext ("area", &area, method_ext ("area", &area,
"@brief The area of the polygon\n" "@brief Gets the area of the polygon\n"
"The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise." "The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise."
) + ) +
method ("perimeter", &C::perimeter, method ("perimeter", &C::perimeter,
"@brief The perimeter of the polygon\n" "@brief Gets the perimeter of the polygon\n"
"The perimeter is sum of the lengths of all edges making up the polygon." "The perimeter is sum of the lengths of all edges making up the polygon."
) + ) +
method ("bbox", &C::box, method ("bbox", &C::box,
"@brief Return the bounding box of the simple polygon" "@brief Returns the bounding box of the simple polygon"
) + ) +
method_ext ("touches?", &touches_box, gsi::arg ("box"), method_ext ("touches?", &touches_box, gsi::arg ("box"),
"@brief Returns true, if the polygon touches the given box.\n" "@brief Returns true, if the polygon touches the given box.\n"
@ -625,57 +619,48 @@ Class<db::SimplePolygon> decl_SimplePolygon ("db", "SimplePolygon",
"\n" "\n"
"This method has been introduced in version 0.25." "This method has been introduced in version 0.25."
) + ) +
method_ext ("minkowsky_sum", &sp_minkowsky_sum_pe, method_ext ("minkowsky_sum", &sp_minkowsky_sum_pe, gsi::arg ("e"), gsi::arg ("resolve_holes"),
"@brief Compute the Minkowsky sum of a polygon and an edge\n" "@brief Computes the Minkowsky sum of a polygon and an edge\n"
"@args a, b, resolve_holes\n"
"\n" "\n"
"@param a The first argument.\n" "@param e The edge.\n"
"@param b The second argument.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
"\n" "\n"
"@return The new polygon representing the Minkowsky sum of a and b.\n" "@return The new polygon representing the Minkowsky sum of self and e.\n"
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &sp_minkowsky_sum_pp, method_ext ("minkowsky_sum", &sp_minkowsky_sum_pp, gsi::arg ("p"), gsi::arg ("resolve_holes"),
"@brief Compute the Minkowsky sum of a polygon and a polygon\n" "@brief Computes the Minkowsky sum of a polygon and a polygon\n"
"@args a, b, resolve_holes\n"
"\n" "\n"
"@param a The first argument.\n" "@param p The other polygon.\n"
"@param b The second argument.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
"\n" "\n"
"@return The new polygon representing the Minkowsky sum of a and b.\n" "@return The new polygon representing the Minkowsky sum of self and p.\n"
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &sp_minkowsky_sum_pb, method_ext ("minkowsky_sum", &sp_minkowsky_sum_pb, gsi::arg ("b"), gsi::arg ("resolve_holes"),
"@brief Compute the Minkowsky sum of a polygon and a box\n" "@brief Computes the Minkowsky sum of a polygon and a box\n"
"@args a, b, resolve_holes\n"
"\n" "\n"
"@param a The first argument.\n" "@param b The box.\n"
"@param b The second argument.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
"\n" "\n"
"@return The new polygon representing the Minkowsky sum of a and b.\n" "@return The new polygon representing the Minkowsky sum of self and b.\n"
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &sp_minkowsky_sum_pc, method_ext ("minkowsky_sum", &sp_minkowsky_sum_pc, gsi::arg ("c"), gsi::arg ("resolve_holes"),
"@brief Compute the Minkowsky sum of a polygon and a contour of points (a trace)\n" "@brief Computes the Minkowsky sum of a polygon and a contour of points (a trace)\n"
"@args a, b, resolve_holes\n"
"\n" "\n"
"@param a The first argument.\n" "@param c The contour (a series of points forming the trace).\n"
"@param b The second argument (a series of points forming the trace).\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
"\n" "\n"
"@return The new polygon representing the Minkowsky sum of a and b.\n" "@return The new polygon representing the Minkowsky sum of self and c.\n"
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("transform", &transform_icplx_sp, method_ext ("transform", &transform_icplx_sp, gsi::arg ("t"),
"@brief Transforms the simple polygon with a complex transformation (in-place)\n" "@brief Transforms the simple polygon with a complex transformation (in-place)\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given complex transformation.\n" "Transforms the simple polygon with the given complex transformation.\n"
"Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n" "Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n"
@ -684,9 +669,8 @@ Class<db::SimplePolygon> decl_SimplePolygon ("db", "SimplePolygon",
"\n" "\n"
"This method has been introduced in version 0.24.\n" "This method has been introduced in version 0.24.\n"
) + ) +
method_ext ("transformed", &transformed_icplx_sp, method_ext ("transformed", &transformed_icplx_sp, gsi::arg ("t"),
"@brief Transform the simple polygon.\n" "@brief Transforms the simple polygon.\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given complex transformation.\n" "Transforms the simple polygon with the given complex transformation.\n"
"Does not modify the simple polygon but returns the transformed polygon.\n" "Does not modify the simple polygon but returns the transformed polygon.\n"
@ -747,9 +731,8 @@ Class<db::DSimplePolygon> decl_DSimplePolygon ("db", "DSimplePolygon",
"\n" "\n"
"This method has been introduced in version 0.25." "This method has been introduced in version 0.25."
) + ) +
method_ext ("transform", &transform_cplx_sp, method_ext ("transform", &transform_cplx_sp, gsi::arg ("t"),
"@brief Transforms the simple polygon with a complex transformation (in-place)\n" "@brief Transforms the simple polygon with a complex transformation (in-place)\n"
"@args t\n"
"\n" "\n"
"Transforms the simple polygon with the given complex transformation.\n" "Transforms the simple polygon with the given complex transformation.\n"
"Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n" "Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n"
@ -758,11 +741,9 @@ Class<db::DSimplePolygon> decl_DSimplePolygon ("db", "DSimplePolygon",
"\n" "\n"
"This method has been introduced in version 0.24.\n" "This method has been introduced in version 0.24.\n"
) + ) +
method_ext ("transformed", &transformed_vplx_sp, method_ext ("transformed", &transformed_vplx_sp, gsi::arg ("t"),
"@brief Transforms the polygon with the given complex transformation\n" "@brief Transforms the polygon with the given complex transformation\n"
"\n" "\n"
"@args t\n"
"\n"
"@param t The magnifying transformation to apply\n" "@param t The magnifying transformation to apply\n"
"@return The transformed polygon (in this case an integer coordinate polygon)\n" "@return The transformed polygon (in this case an integer coordinate polygon)\n"
"\n" "\n"
@ -873,6 +854,16 @@ struct polygon_defs
return c->vertices (); return c->vertices ();
} }
static bool is_rectilinear (C *c)
{
return c->is_rectilinear ();
}
static bool is_empty (C *c)
{
return c->vertices () == 0;
}
static point_type point_hull (C *c, size_t p) static point_type point_hull (C *c, size_t p)
{ {
if (c->hull ().size () > p) { if (c->hull ().size () > p) {
@ -1089,71 +1080,67 @@ struct polygon_defs
{ {
return return
constructor ("new", &new_v, constructor ("new", &new_v,
"@brief Default constructor: creates an empty (invalid) polygon" "@brief Creates an empty (invalid) polygon"
) + ) +
constructor ("new", &p_from_sp, constructor ("new", &p_from_sp, gsi::arg ("sp"),
"@brief Constructor from a simple polygon\n" "@brief Creates a polygon from a simple polygon\n"
"@args sp\n"
"@param sp The simple polygon that is converted into the polygon\n" "@param sp The simple polygon that is converted into the polygon\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
constructor ("new", &new_p, gsi::arg ("pts"), gsi::arg ("raw", false), constructor ("new", &new_p, gsi::arg ("pts"), gsi::arg ("raw", false),
"@brief Constructor given the points of the polygon hull\n" "@brief Creates a polygon from a point array for the hull\n"
"\n" "\n"
"@param pts The points forming the polygon hull\n" "@param pts The points forming the polygon hull\n"
"@param raw If true, the point list won't be modified (see \\assign_hull)\n" "@param raw If true, the point list won't be modified (see \\assign_hull)\n"
"\n" "\n"
"The 'raw' argument was added in version 0.24.\n" "The 'raw' argument was added in version 0.24.\n"
) + ) +
constructor ("new", &new_b, constructor ("new", &new_b, gsi::arg ("box"),
"@brief Constructor converting a box to a polygon\n" "@brief Creates a polygon from a box\n"
"\n"
"@args box\n"
"\n" "\n"
"@param box The box to convert to a polygon\n" "@param box The box to convert to a polygon\n"
) + ) +
constructor ("ellipse", &ellipse, constructor ("ellipse", &ellipse, gsi::arg ("box"), gsi::arg ("n"),
"@brief Creates a simple polygon appoximating an ellipse\n" "@brief Creates a simple polygon appoximating an ellipse\n"
"\n" "\n"
"@args box, n\n"
"\n"
"@param box The bounding box of the ellipse\n" "@param box The bounding box of the ellipse\n"
"@param n The number of points that will be used to approximate the ellipse\n" "@param n The number of points that will be used to approximate the ellipse\n"
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method ("<", &C::less, method ("<", &C::less, gsi::arg ("p"),
"@brief Less operator\n" "@brief Returns a value indicating whether self is less than p\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
"This operator is provided to establish some, not necessarily a certain sorting order\n" "This operator is provided to establish some, not necessarily a certain sorting order\n"
) + ) +
method ("==", &C::equal, method ("==", &C::equal, gsi::arg ("p"),
"@brief Equality test\n" "@brief Returns a value indicating whether the polygons are equal\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
) + ) +
method ("!=", &C::not_equal, method ("!=", &C::not_equal, gsi::arg ("p"),
"@brief Inequality test\n" "@brief Returns a value indicating whether the polygons are not equal\n"
"@args p\n"
"@param p The object to compare against\n" "@param p The object to compare against\n"
) + ) +
method_ext ("is_empty?", &is_empty,
"@brief Returns a value indicating whether the polygon is empty\n"
) +
method_ext ("is_rectilinear?", &is_rectilinear,
"@brief Returns a value indicating whether the polygon is rectilinear\n"
) +
method_ext ("hash", &hash_value, method_ext ("hash", &hash_value,
"@brief Computes a hash value\n" "@brief Computes a hash value\n"
"Returns a hash value for the given polygon. This method enables polygons as hash keys.\n" "Returns a hash value for the given polygon. This method enables polygons as hash keys.\n"
"\n" "\n"
"This method has been introduced in version 0.25.\n" "This method has been introduced in version 0.25.\n"
) + ) +
method_ext ("hull=", &set_hull1, method_ext ("hull=", &set_hull1, gsi::arg ("p"),
"@brief Set the points of the hull of polygon\n" "@brief Sets the points of the hull of polygon\n"
"@args p\n"
"@param p An array of points to assign to the polygon's hull" "@param p An array of points to assign to the polygon's hull"
"\n" "\n"
"The 'assign_hull' variant is provided in analogy to 'assign_hole'.\n" "The 'assign_hull' variant is provided in analogy to 'assign_hole'.\n"
) + ) +
method_ext ("assign_hull", &set_hull, gsi::arg ("p"), gsi::arg ("raw", false), method_ext ("assign_hull", &set_hull, gsi::arg ("p"), gsi::arg ("raw", false),
"@brief Set the points of the hull of polygon\n" "@brief Sets the points of the hull of polygon\n"
"@args p\n"
"@param p An array of points to assign to the polygon's hull\n" "@param p An array of points to assign to the polygon's hull\n"
"@param raw If true, the points won't be compressed\n" "@param raw If true, the points won't be compressed\n"
"\n" "\n"
@ -1171,7 +1158,7 @@ struct polygon_defs
"The 'raw' argument was added in version 0.24.\n" "The 'raw' argument was added in version 0.24.\n"
) + ) +
method_ext ("assign_hole", &set_hole, gsi::arg ("n"), gsi::arg ("p"), gsi::arg ("raw", false), method_ext ("assign_hole", &set_hole, gsi::arg ("n"), gsi::arg ("p"), gsi::arg ("raw", false),
"@brief Set the points of the given hole of the polygon\n" "@brief Sets the points of the given hole of the polygon\n"
"@param n The index of the hole to which the points should be assigned\n" "@param n The index of the hole to which the points should be assigned\n"
"@param p An array of points to assign to the polygon's hole\n" "@param p An array of points to assign to the polygon's hole\n"
"@param raw If true, the points won't be compressed (see \\assign_hull)\n" "@param raw If true, the points won't be compressed (see \\assign_hull)\n"
@ -1180,66 +1167,59 @@ struct polygon_defs
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
"The 'raw' argument was added in version 0.24.\n" "The 'raw' argument was added in version 0.24.\n"
) + ) +
method_ext ("assign_hole", &set_hole_box, method_ext ("assign_hole", &set_hole_box, gsi::arg ("n"), gsi::arg ("b"),
"@brief Set the box as the given hole of the polygon\n" "@brief Sets the box as the given hole of the polygon\n"
"@args n,b\n"
"@param n The index of the hole to which the points should be assigned\n" "@param n The index of the hole to which the points should be assigned\n"
"@param b The box to assign to the polygon's hole\n" "@param b The box to assign to the polygon's hole\n"
"If the hole index is not valid, this method does nothing.\n" "If the hole index is not valid, this method does nothing.\n"
"This method was introduced in version 0.23.\n" "This method was introduced in version 0.23.\n"
) + ) +
method_ext ("num_points", &num_points, method_ext ("num_points", &num_points,
"@brief Get the total number of points (hull plus holes)\n" "@brief Gets the total number of points (hull plus holes)\n"
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
) + ) +
method_ext ("point_hull", &point_hull, method_ext ("point_hull", &point_hull, gsi::arg ("p"),
"@brief Get a specific point of the hull\n" "@brief Gets a specific point of the hull\n"
"@args p\n"
"@param p The index of the point to get\n" "@param p The index of the point to get\n"
"If the index of the point is not a valid index, a default value is returned.\n" "If the index of the point is not a valid index, a default value is returned.\n"
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
) + ) +
method_ext ("point_hole", &point_hole, method_ext ("point_hole", &point_hole, gsi::arg ("n"), gsi::arg ("p"),
"@brief Get a specific point of a hole\n" "@brief Gets a specific point of a hole\n"
"@args n,p\n"
"@param n The index of the hole to which the points should be assigned\n" "@param n The index of the hole to which the points should be assigned\n"
"@param p The index of the point to get\n" "@param p The index of the point to get\n"
"If the index of the point or of the hole is not valid, a default value is returned.\n" "If the index of the point or of the hole is not valid, a default value is returned.\n"
"This method was introduced in version 0.18.\n" "This method was introduced in version 0.18.\n"
) + ) +
method_ext ("num_points_hull", &num_points_hull, method_ext ("num_points_hull", &num_points_hull,
"@brief Get the number of points of the hull\n" "@brief Gets the number of points of the hull\n"
) + ) +
method_ext ("num_points_hole", &num_points_hole, method_ext ("num_points_hole", &num_points_hole, gsi::arg ("n"),
"@brief Get the number of points of the given hole\n" "@brief Gets the number of points of the given hole\n"
"@args n\n"
"The argument gives the index of the hole of which the number of points " "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). " "are requested. The index must be less than the number of holes (see \\holes). "
) + ) +
method_ext ("insert_hole", &insert_hole, gsi::arg ("p"), gsi::arg ("raw", false), method_ext ("insert_hole", &insert_hole, gsi::arg ("p"), gsi::arg ("raw", false),
"@brief Insert a hole with the given points\n" "@brief Inserts a hole with the given points\n"
"@param p An array of points to insert as a new hole\n" "@param p An array of points to insert as a new hole\n"
"@param raw If true, the points won't be compressed (see \\assign_hull)\n" "@param raw If true, the points won't be compressed (see \\assign_hull)\n"
"\n" "\n"
"The 'raw' argument was added in version 0.24.\n" "The 'raw' argument was added in version 0.24.\n"
) + ) +
method_ext ("insert_hole", &insert_hole_box, method_ext ("insert_hole", &insert_hole_box, gsi::arg ("b"),
"@brief Insert a hole from the given box\n" "@brief Inserts a hole from the given box\n"
"@args b\n"
"@param b The box to insert as a new hole\n" "@param b The box to insert as a new hole\n"
"This method was introduced in version 0.23.\n" "This method was introduced in version 0.23.\n"
) + ) +
iterator ("each_point_hull", &C::begin_hull, &C::end_hull, iterator ("each_point_hull", &C::begin_hull, &C::end_hull,
"@brief Iterate over the points that make up the hull" "@brief Iterates over the points that make up the hull"
) + ) +
iterator ("each_point_hole", &C::begin_hole, &C::end_hole, iterator ("each_point_hole", &C::begin_hole, &C::end_hole, gsi::arg ("n"),
"@brief Iterate over the points that make up the nth hole\n" "@brief Iterates over the points that make up the nth hole\n"
"@args n\n"
"The hole number must be less than the number of holes (see \\holes)" "The hole number must be less than the number of holes (see \\holes)"
) + ) +
method_ext ("size", &size_xy, method_ext ("size", &size_xy, gsi::arg ("dx"), gsi::arg ("dy"), gsi::arg ("mode"),
"@brief Sizing (biasing)\n" "@brief Sizes the polygon (biasing)\n"
"@args dx, dy, mode\n"
"\n" "\n"
"Shifts the contour outwards (dx,dy>0) or inwards (dx,dy<0).\n" "Shifts the contour outwards (dx,dy>0) or inwards (dx,dy<0).\n"
"dx is the sizing in x-direction and dy is the sizing in y-direction. The sign of dx and dy should be identical.\n" "dx is the sizing in x-direction and dy is the sizing in y-direction. The sign of dx and dy should be identical.\n"
@ -1261,9 +1241,8 @@ struct polygon_defs
"result = ep.simple_merge_p2p([ poly ], false, false, 1)\n" "result = ep.simple_merge_p2p([ poly ], false, false, 1)\n"
"@/code\n" "@/code\n"
) + ) +
method_ext ("size", &size_dm, method_ext ("size", &size_dm, gsi::arg ("d"), gsi::arg ("mode"),
"@brief Sizing (biasing)\n" "@brief Sizes the polygon (biasing)\n"
"@args d, mode\n"
"\n" "\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n" "Shifts the contour outwards (d>0) or inwards (d<0).\n"
"This method is equivalent to\n" "This method is equivalent to\n"
@ -1275,9 +1254,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("sized", &sized_xy, method_ext ("sized", &sized_xy, gsi::arg ("dx"), gsi::arg ("dy"), gsi::arg ("mode"),
"@brief Sizing (biasing) without modifying self\n" "@brief Sizes the polygon (biasing) without modifying self\n"
"@args dx, dy, mode\n"
"\n" "\n"
"This method applies sizing to the polygon but does not modify self. Instead a sized copy " "This method applies sizing to the polygon but does not modify self. Instead a sized copy "
"is returned.\n" "is returned.\n"
@ -1285,9 +1263,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("sized", &sized_dm, method_ext ("sized", &sized_dm, gsi::arg ("d"), gsi::arg ("mode"),
"@brief Sizing (biasing) without modifying self\n" "@brief Sizes the polygon (biasing) without modifying self\n"
"@args d, mode\n"
"\n" "\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n" "Shifts the contour outwards (d>0) or inwards (d<0).\n"
"This method is equivalent to\n" "This method is equivalent to\n"
@ -1297,9 +1274,8 @@ struct polygon_defs
"\n" "\n"
"See \\size and \\sized for a detailed description.\n" "See \\size and \\sized for a detailed description.\n"
) + ) +
method_ext ("sized", &sized_d, method_ext ("sized", &sized_d, gsi::arg ("d"),
"@brief Sizing (biasing)\n" "@brief Sizes the polygon (biasing)\n"
"@args d\n"
"\n" "\n"
"@brief Sizing (biasing) without modifying self\n" "@brief Sizing (biasing) without modifying self\n"
"This method is equivalent to\n" "This method is equivalent to\n"
@ -1309,9 +1285,8 @@ struct polygon_defs
"\n" "\n"
"See \\size and \\sized for a detailed description.\n" "See \\size and \\sized for a detailed description.\n"
) + ) +
method_ext ("size", &size_d, method_ext ("size", &size_d, gsi::arg ("d"),
"@brief Sizing (biasing)\n" "@brief Sizes the polygon (biasing)\n"
"@args d\n"
"\n" "\n"
"Shifts the contour outwards (d>0) or inwards (d<0).\n" "Shifts the contour outwards (d>0) or inwards (d<0).\n"
"This method is equivalent to\n" "This method is equivalent to\n"
@ -1325,15 +1300,14 @@ struct polygon_defs
"@brief Returns the number of holes" "@brief Returns the number of holes"
) + ) +
iterator ("each_edge", (typename C::polygon_edge_iterator (C::*)() const) (&C::begin_edge), iterator ("each_edge", (typename C::polygon_edge_iterator (C::*)() const) (&C::begin_edge),
"@brief Iterate over the edges that make up the polygon\n" "@brief Iterates over the edges that make up the polygon\n"
"\n" "\n"
"This iterator will deliver all edges, including those of the holes. " "This iterator will deliver all edges, including those of the holes. "
"Hole edges are oriented counterclockwise while hull edges are oriented clockwise.\n" "Hole edges are oriented counterclockwise while hull edges are oriented clockwise.\n"
) + ) +
iterator ("each_edge", (typename C::polygon_edge_iterator (C::*)(unsigned int) const) (&C::begin_edge), iterator ("each_edge", (typename C::polygon_edge_iterator (C::*)(unsigned int) const) (&C::begin_edge), gsi::arg ("contour"),
"@brief Iterate over the edges of one contour of the polygon\n" "@brief Iterates over the edges of one contour of the polygon\n"
"\n" "\n"
"@args contour\n"
"@param contour The contour number (0 for hull, 1 for first hole ...)\n" "@param contour The contour number (0 for hull, 1 for first hole ...)\n"
"\n" "\n"
"This iterator will deliver all edges of the contour specified by the contour parameter. " "This iterator will deliver all edges of the contour specified by the contour parameter. "
@ -1342,15 +1316,13 @@ struct polygon_defs
"\n" "\n"
"This method was introduced in version 0.24." "This method was introduced in version 0.24."
) + ) +
method_ext ("inside?", &inside, method_ext ("inside?", &inside, gsi::arg ("p"),
"@brief Test, if the given point is inside the polygon\n" "@brief Tests, if the given point is inside the polygon\n"
"@args p\n"
"If the given point is inside or on the edge of the polygon, true is returned. " "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. " "This tests works well only if the polygon is not self-overlapping and oriented clockwise. "
) + ) +
method_ext ("compress", &compress, method_ext ("compress", &compress, gsi::arg ("remove_reflected"),
"@brief Compress the polygon.\n" "@brief Compresses the polygon.\n"
"@args remove_reflected\n"
"\n" "\n"
"This method removes redundant points from the polygon, such as points being on a line formed by two other points.\n" "This method removes redundant points from the polygon, such as points being on a line formed by two other points.\n"
"If remove_reflected is true, points are also removed if the two adjacent edges form a spike.\n" "If remove_reflected is true, points are also removed if the two adjacent edges form a spike.\n"
@ -1368,17 +1340,14 @@ struct polygon_defs
"\n" "\n"
"This method was introduced in version 0.23.\n" "This method was introduced in version 0.23.\n"
) + ) +
method_ext ("*", &scale, method_ext ("*", &scale, gsi::arg ("f"),
"@brief Scaling by some factor\n" "@brief Scales the polygon by some factor\n"
"\n"
"@args f\n"
"\n" "\n"
"Returns the scaled object. All coordinates are multiplied with the given factor and if " "Returns the scaled object. All coordinates are multiplied with the given factor and if "
"necessary rounded." "necessary rounded."
) + ) +
method ("move", &C::move, method ("move", &C::move, gsi::arg ("p"),
"@brief Moves the polygon.\n" "@brief Moves the polygon.\n"
"@args p\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is overwritten.\n" "moved polygon. The polygon is overwritten.\n"
@ -1389,9 +1358,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("move", &move_xy, method_ext ("move", &move_xy, gsi::arg ("x"), gsi::arg ("y"),
"@brief Moves the polygon.\n" "@brief Moves the polygon.\n"
"@args x,y\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is overwritten.\n" "moved polygon. The polygon is overwritten.\n"
@ -1401,9 +1369,8 @@ struct polygon_defs
"\n" "\n"
"@return The moved polygon (self).\n" "@return The moved polygon (self).\n"
) + ) +
method ("moved", &C::moved, method ("moved", &C::moved, gsi::arg ("p"),
"@brief Returns the moved polygon (does not modify self)\n" "@brief Returns the moved polygon (does not modify self)\n"
"@args p\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is not modified.\n" "moved polygon. The polygon is not modified.\n"
@ -1414,9 +1381,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("moved", &moved_xy, method_ext ("moved", &moved_xy, gsi::arg ("x"), gsi::arg ("y"),
"@brief Returns the moved polygon (does not modify self)\n" "@brief Returns the moved polygon (does not modify self)\n"
"@args x,y\n"
"\n" "\n"
"Moves the polygon by the given offset and returns the \n" "Moves the polygon by the given offset and returns the \n"
"moved polygon. The polygon is not modified.\n" "moved polygon. The polygon is not modified.\n"
@ -1428,9 +1394,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.23.\n" "This method has been introduced in version 0.23.\n"
) + ) +
method_ext ("transform", &transform, method_ext ("transform", &transform, gsi::arg ("t"),
"@brief Transforms the polygon (in-place)\n" "@brief Transforms the polygon (in-place)\n"
"@args t\n"
"\n" "\n"
"Transforms the polygon with the given transformation.\n" "Transforms the polygon with the given transformation.\n"
"Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n" "Modifies self and returns self. An out-of-place version which does not modify self is \\transformed.\n"
@ -1439,9 +1404,8 @@ struct polygon_defs
"\n" "\n"
"This method has been introduced in version 0.24.\n" "This method has been introduced in version 0.24.\n"
) + ) +
method_ext ("transformed", &transformed, method_ext ("transformed", &transformed, gsi::arg ("t"),
"@brief Transforms the polygon\n" "@brief Transforms the polygon\n"
"@args t\n"
"\n" "\n"
"Transforms the polygon with the given transformation.\n" "Transforms the polygon with the given transformation.\n"
"Does not modify the polygon but returns the transformed polygon.\n" "Does not modify the polygon but returns the transformed polygon.\n"
@ -1450,9 +1414,8 @@ struct polygon_defs
"\n" "\n"
"@return The transformed polygon.\n" "@return The transformed polygon.\n"
) + ) +
method_ext ("transformed|#transformed_cplx", &transformed_cplx, method_ext ("transformed|#transformed_cplx", &transformed_cplx, gsi::arg ("t"),
"@brief Transforms the polygon with a complex transformation\n" "@brief Transforms the polygon with a complex transformation\n"
"@args t\n"
"\n" "\n"
"Transforms the polygon with the given complex transformation.\n" "Transforms the polygon with the given complex transformation.\n"
"Does not modify the polygon but returns the transformed polygon.\n" "Does not modify the polygon but returns the transformed polygon.\n"
@ -1464,19 +1427,17 @@ struct polygon_defs
"With version 0.25, the original 'transformed_cplx' method is deprecated and " "With version 0.25, the original 'transformed_cplx' method is deprecated and "
"'transformed' takes both simple and complex transformations." "'transformed' takes both simple and complex transformations."
) + ) +
constructor ("from_s", &from_string, constructor ("from_s", &from_string, gsi::arg ("s"),
"@brief Creates an object from a string\n" "@brief Creates a polygon from a string\n"
"@args s\n"
"Creates the object from a string representation (as returned by \\to_s)\n" "Creates the object from a string representation (as returned by \\to_s)\n"
"\n" "\n"
"This method has been added in version 0.23.\n" "This method has been added in version 0.23.\n"
) + ) +
method ("to_s", (std::string (C::*) () const) &C::to_string, method ("to_s", (std::string (C::*) () const) &C::to_string,
"@brief Convert to a string\n" "@brief Returns a string representing the polygon\n"
) + ) +
method_ext ("round_corners", &round_corners, method_ext ("round_corners", &round_corners, gsi::arg ("rinner"), gsi::arg ("router"), gsi::arg ("n"),
"@brief Rounds the corners of the polygon\n" "@brief Rounds the corners of the polygon\n"
"@args rinner, router, n\n"
"\n" "\n"
"Replaces the corners of the polygon with circle segments.\n" "Replaces the corners of the polygon with circle segments.\n"
"\n" "\n"
@ -1527,18 +1488,18 @@ struct polygon_defs
"This method has been introduced in version 0.25.3." "This method has been introduced in version 0.25.3."
) + ) +
method_ext ("area", &area, method_ext ("area", &area,
"@brief The area of the polygon\n" "@brief Gets the area of the polygon\n"
"The area is correct only if the polygon is not self-overlapping and the polygon is oriented clockwise." "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.\n" "Orientation is ensured automatically in most cases.\n"
) + ) +
method ("perimeter", &C::perimeter, method ("perimeter", &C::perimeter,
"@brief The perimeter of the polygon\n" "@brief Gets the perimeter of the polygon\n"
"The perimeter is sum of the lengths of all edges making up the polygon.\n" "The perimeter is sum of the lengths of all edges making up the polygon.\n"
"\n" "\n"
"This method has been introduce in version 0.23.\n" "This method has been introduce in version 0.23.\n"
) + ) +
method ("bbox", &C::box, method ("bbox", &C::box,
"@brief Return the bounding box of the polygon\n" "@brief Returns the bounding box of the polygon\n"
"The bounding box is the box enclosing all points of the polygon.\n" "The bounding box is the box enclosing all points of the polygon.\n"
) + ) +
method_ext ("touches?", &touches_box, gsi::arg ("box"), method_ext ("touches?", &touches_box, gsi::arg ("box"),
@ -1788,9 +1749,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("smooth", &smooth, method_ext ("smooth", &smooth, gsi::arg ("d"),
"@brief Smoothes a polygon\n" "@brief Smoothes a polygon\n"
"@args d\n"
"\n" "\n"
"Remove vertices that deviate by more than the distance d from the average contour.\n" "Remove vertices that deviate by more than the distance d from the average contour.\n"
"The value d is basically the roughness which is removed.\n" "The value d is basically the roughness which is removed.\n"
@ -1801,9 +1761,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.23.\n" "This method was introduced in version 0.23.\n"
) + ) +
method_ext ("minkowsky_sum", &minkowsky_sum_pe, method_ext ("minkowsky_sum", &minkowsky_sum_pe, gsi::arg ("e"), gsi::arg ("resolve_holes"),
"@brief Computes the Minkowsky sum of the polygon and an edge\n" "@brief Computes the Minkowsky sum of the polygon and an edge\n"
"@args e, resolve_holes\n"
"\n" "\n"
"@param e The edge.\n" "@param e The edge.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
@ -1816,9 +1775,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &minkowsky_sum_pp, method_ext ("minkowsky_sum", &minkowsky_sum_pp, gsi::arg ("b"), gsi::arg ("resolve_holes"),
"@brief Computes the Minkowsky sum of the polygon and a polygon\n" "@brief Computes the Minkowsky sum of the polygon and a polygon\n"
"@args p, resolve_holes\n"
"\n" "\n"
"@param p The first argument.\n" "@param p The first argument.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
@ -1827,9 +1785,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &minkowsky_sum_pb, method_ext ("minkowsky_sum", &minkowsky_sum_pb, gsi::arg ("b"), gsi::arg ("resolve_holes"),
"@brief Computes the Minkowsky sum of the polygon and a box\n" "@brief Computes the Minkowsky sum of the polygon and a box\n"
"@args b, resolve_holes\n"
"\n" "\n"
"@param b The box.\n" "@param b The box.\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
@ -1838,9 +1795,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("minkowsky_sum", &minkowsky_sum_pc, method_ext ("minkowsky_sum", &minkowsky_sum_pc, gsi::arg ("b"), gsi::arg ("resolve_holes"),
"@brief Computes the Minkowsky sum of the polygon and a contour of points (a trace)\n" "@brief Computes the Minkowsky sum of the polygon and a contour of points (a trace)\n"
"@args b, resolve_holes\n"
"\n" "\n"
"@param b The contour (a series of points forming the trace).\n" "@param b The contour (a series of points forming the trace).\n"
"@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n" "@param resolve_holes If true, the output polygon will not contain holes, but holes are resolved by joining the holes with the hull.\n"
@ -1849,9 +1805,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.22.\n" "This method was introduced in version 0.22.\n"
) + ) +
method_ext ("transform", &transform_icplx_dp, method_ext ("transform", &transform_icplx_dp, gsi::arg ("t"),
"@brief Transforms the polygon with a complex transformation (in-place)\n" "@brief Transforms the polygon with a complex transformation (in-place)\n"
"@args t\n"
"\n" "\n"
"Transforms the polygon with the given complex transformation.\n" "Transforms the polygon with the given complex transformation.\n"
"This version modifies self and will return self as the modified polygon. An out-of-place version " "This version modifies self and will return self as the modified polygon. An out-of-place version "
@ -1861,9 +1816,8 @@ Class<db::Polygon> decl_Polygon ("db", "Polygon",
"\n" "\n"
"This method was introduced in version 0.24.\n" "This method was introduced in version 0.24.\n"
) + ) +
method_ext ("transformed", &transformed_icplx_dp, method_ext ("transformed", &transformed_icplx_dp, gsi::arg ("t"),
"@brief Transforms the polygon with a complex transformation\n" "@brief Transforms the polygon with a complex transformation\n"
"@args t\n"
"\n" "\n"
"Transforms the polygon with the given complex transformation.\n" "Transforms the polygon with the given complex transformation.\n"
"Does not modify the polygon but returns the transformed polygon.\n" "Does not modify the polygon but returns the transformed polygon.\n"

View File

@ -32,6 +32,8 @@ class DBPolygon_TestClass < TestBase
assert_equal( a.to_s, "()" ) assert_equal( a.to_s, "()" )
assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s ) assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( a.is_box?, false ) assert_equal( a.is_box?, false )
assert_equal( a.is_empty?, true )
assert_equal( a.is_rectilinear?, false )
b = a.dup b = a.dup
a = RBA::DPolygon::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ), RBA::DPoint::new( 5, 5 ) ] ) a = RBA::DPolygon::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ), RBA::DPoint::new( 5, 5 ) ] )
@ -40,6 +42,8 @@ class DBPolygon_TestClass < TestBase
assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s ) assert_equal( RBA::DPolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( a.is_box?, false ) assert_equal( a.is_box?, false )
assert_equal( a.num_points_hull, 3 ) assert_equal( a.num_points_hull, 3 )
assert_equal( a.is_empty?, false )
assert_equal( a.is_rectilinear?, false )
c = a.dup c = a.dup
assert_equal( a == b, false ) assert_equal( a == b, false )
@ -49,6 +53,8 @@ class DBPolygon_TestClass < TestBase
a = RBA::DPolygon::new( RBA::DBox::new( 5, -10, 20, 15 ) ) a = RBA::DPolygon::new( RBA::DBox::new( 5, -10, 20, 15 ) )
assert_equal( a.is_box?, true ) assert_equal( a.is_box?, true )
assert_equal( a.is_empty?, false )
assert_equal( a.is_rectilinear?, true )
assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" )
assert_equal( RBA::Polygon::new(a).to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( RBA::Polygon::new(a).to_s, "(5,-10;5,15;20,15;20,-10)" )
assert_equal( a.num_points_hull, 4 ) assert_equal( a.num_points_hull, 4 )
@ -355,6 +361,8 @@ class DBPolygon_TestClass < TestBase
pts = [ RBA::Point::new(0, 0) ] pts = [ RBA::Point::new(0, 0) ]
p = RBA::Polygon::new(pts, false) p = RBA::Polygon::new(pts, false)
assert_equal(p.to_s, "()") assert_equal(p.to_s, "()")
assert_equal(p.is_empty?, true)
assert_equal(p.is_rectilinear?, false)
pts = [ RBA::Point::new(0, 0) ] pts = [ RBA::Point::new(0, 0) ]
p = RBA::Polygon::new(pts) p = RBA::Polygon::new(pts)
@ -426,17 +434,21 @@ class DBPolygon_TestClass < TestBase
pts = [ RBA::DPoint::new(0, 0) ] pts = [ RBA::DPoint::new(0, 0) ]
p = RBA::DPolygon::new(pts, true) p = RBA::DPolygon::new(pts, true)
assert_equal(p.to_s, "(0,0)") assert_equal(p.to_s, "(0,0)")
assert_equal(p.is_empty?, false)
assert_equal(p.is_rectilinear?, false)
arr = [] arr = []
p.each_edge { |e| arr.push( e.to_s ) } p.each_edge { |e| arr.push( e.to_s ) }
assert_equal( arr, ["(0,0;0,0)"] ) assert_equal( arr, ["(0,0;0,0)"] )
p = RBA::DPolygon::new(RBA::DBox::new(0, 0, 100, 100)) p = RBA::DPolygon::new(RBA::DBox::new(0, 0, 100, 100))
p.insert_hole( [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ], true ) assert_equal(p.is_empty?, false)
assert_equal(p.is_rectilinear?, true)
p.insert_hole([ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ], true)
assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)") assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)")
p.assign_hole(0, [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ] ) p.assign_hole(0, [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ])
assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)") assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)")
p.assign_hole(0, [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ], true ) p.assign_hole(0, [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ], true)
assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)") assert_equal(p.to_s, "(0,0;0,100;100,100;100,0/0,0;10,0)")
pts = [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ] pts = [ RBA::DPoint::new(0, 0), RBA::DPoint::new(10, 0) ]

View File

@ -31,6 +31,8 @@ class DBSimplePolygon_TestClass < TestBase
a = RBA::DSimplePolygon::new a = RBA::DSimplePolygon::new
assert_equal( a.to_s, "()" ) assert_equal( a.to_s, "()" )
assert_equal( RBA::DSimplePolygon::from_s(a.to_s).to_s, a.to_s ) assert_equal( RBA::DSimplePolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( a.is_empty?, true )
assert_equal( a.is_rectilinear?, false )
b = a.dup b = a.dup
a = RBA::DSimplePolygon::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ), RBA::DPoint::new( 5, 5 ) ] ) a = RBA::DSimplePolygon::new( [ RBA::DPoint::new( 0, 1 ), RBA::DPoint::new( 1, 5 ), RBA::DPoint::new( 5, 5 ) ] )
@ -46,6 +48,8 @@ class DBSimplePolygon_TestClass < TestBase
assert_equal( a != c, false ) assert_equal( a != c, false )
a = RBA::DSimplePolygon::new( RBA::DBox::new( 5, -10, 20, 15 ) ) a = RBA::DSimplePolygon::new( RBA::DBox::new( 5, -10, 20, 15 ) )
assert_equal( a.is_empty?, false )
assert_equal( a.is_rectilinear?, true )
assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" )
assert_equal( RBA::DPolygon.new(a).class.to_s, "RBA::DPolygon" ) assert_equal( RBA::DPolygon.new(a).class.to_s, "RBA::DPolygon" )
assert_equal( RBA::DPolygon.new(a).to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( RBA::DPolygon.new(a).to_s, "(5,-10;5,15;20,15;20,-10)" )
@ -107,6 +111,8 @@ class DBSimplePolygon_TestClass < TestBase
# Ellipse constructor # Ellipse constructor
p = RBA::DSimplePolygon::ellipse( RBA::DBox::new(-10000, -20000, 30000, 40000), 200 ) p = RBA::DSimplePolygon::ellipse( RBA::DBox::new(-10000, -20000, 30000, 40000), 200 )
assert_equal(p.num_points, 200) assert_equal(p.num_points, 200)
assert_equal(p.is_empty?, false)
assert_equal(p.is_rectilinear?, false)
assert_equal(p.bbox.to_s, "(-10000,-20000;30000,40000)") assert_equal(p.bbox.to_s, "(-10000,-20000;30000,40000)")
assert_equal(p.area.to_i, 1884645544) # roughly box.area*PI/4 assert_equal(p.area.to_i, 1884645544) # roughly box.area*PI/4
@ -121,6 +127,8 @@ class DBSimplePolygon_TestClass < TestBase
a = RBA::SimplePolygon::new a = RBA::SimplePolygon::new
assert_equal( a.to_s, "()" ) assert_equal( a.to_s, "()" )
assert_equal( RBA::SimplePolygon::from_s(a.to_s).to_s, a.to_s ) assert_equal( RBA::SimplePolygon::from_s(a.to_s).to_s, a.to_s )
assert_equal( a.is_empty?, true )
assert_equal( a.is_rectilinear?, false )
b = a.dup b = a.dup
a = RBA::SimplePolygon::new( [ RBA::Point::new( 0, 1 ), RBA::Point::new( 1, 5 ), RBA::Point::new( 5, 5 ) ] ) a = RBA::SimplePolygon::new( [ RBA::Point::new( 0, 1 ), RBA::Point::new( 1, 5 ), RBA::Point::new( 5, 5 ) ] )
@ -137,6 +145,8 @@ class DBSimplePolygon_TestClass < TestBase
a = RBA::SimplePolygon::new( RBA::Box::new( 5, -10, 20, 15 ) ) a = RBA::SimplePolygon::new( RBA::Box::new( 5, -10, 20, 15 ) )
assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( a.to_s, "(5,-10;5,15;20,15;20,-10)" )
assert_equal( a.is_empty?, false )
assert_equal( a.is_rectilinear?, true )
assert_equal( RBA::Polygon.new(a).class.to_s, "RBA::Polygon" ) assert_equal( RBA::Polygon.new(a).class.to_s, "RBA::Polygon" )
assert_equal( RBA::Polygon.new(a).to_s, "(5,-10;5,15;20,15;20,-10)" ) assert_equal( RBA::Polygon.new(a).to_s, "(5,-10;5,15;20,15;20,-10)" )
assert_equal( a.num_points, 4 ) assert_equal( a.num_points, 4 )
@ -227,6 +237,8 @@ class DBSimplePolygon_TestClass < TestBase
# Ellipse constructor # Ellipse constructor
p = RBA::SimplePolygon::ellipse( RBA::Box::new(-10000, -20000, 30000, 40000), 200 ) p = RBA::SimplePolygon::ellipse( RBA::Box::new(-10000, -20000, 30000, 40000), 200 )
assert_equal(p.num_points, 200) assert_equal(p.num_points, 200)
assert_equal(p.is_empty?, false)
assert_equal(p.is_rectilinear?, false)
assert_equal(p.bbox.to_s, "(-10000,-20000;30000,40000)") assert_equal(p.bbox.to_s, "(-10000,-20000;30000,40000)")
assert_equal(p.area, 1884651158) # roughly box.area*PI/4 assert_equal(p.area, 1884651158) # roughly box.area*PI/4