On 16-Dec-2013 14:52, mathog wrote:
On 16-Dec-2013 14:45, mathog wrote:
This is sort of a follow up question to my previous one about circles. Is there in 2geom a set of methods along the lines of:
isRect(path)
Note that isRect() should be true for both
In the patch for bug 1263242 here
https://bugs.launchpad.net/inkscape/+bug/1263242
these 3 functions were added to emf-print.cpp.
Geom::Path pathv_to_simple_polygon(Geom::PathVector const &pathv, int *vertices); Geom::Path pathv_to_rect(Geom::PathVector const &pathv, bool *is_rect, double *angle); Geom::Point get_pathrect_corner(Geom::Path pathRect, double angle, int corner);
They probably should be in src/helper/geom.cpp, but at the moment the only code that uses them is in emf-print.cpp, so there they are. (The names are maybe not exactly right for what these do.)
The first function returns a path in which any points on a polygonal path (stored in a PathVector) that are not at a vertex have been eliminated. It also eliminates one point where two fall within epsilon of each other. (Duplicate points, not sure what the technical term for them is.) If the pathvector holds more than one path or has any curves that are not linear then it returns an empty path.
The second analyzes a PathVector to see if it is a rectangle. It does this by first calling the preceding function, then checking that the path has 4 sides and that each side is 90 degrees from its two neighbors. If that is the case is_rect comes back true. The angle returned is that of the minimal rotation that will align the sides of the rectangle with the X and Y axes.
The third returns the coordinates of the Upper Left, Upper Right, Lower Right, and Lower Left corners of the rectangle, as determined by the value of "corner", given the rotation angle and path returned by the preceding function.
It would not surprise me to learn that these functions are already somewhere in Inkscape, but when I looked I could not find them.
Regards,
David Mathog mathog@...1176... Manager, Sequence Analysis Facility, Biology Division, Caltech