I downloaded the clipper library, which allows me to inflate a polygon (offset a polygon).
"boundary_Points" is the Point array containing all vertices of the polygon. Below is the code I'm using. Unfortunately, the command "DrawPolygons()", which is used in other web examples, doesn't exist as a function. Is there any way to access this command or another way to draw? The challenge is: Clipper library uses the type IntPoint, which cannot be used in GDI+, as far as I'm concerned. Thanks
using Path = List<IntPoint>;
using Paths = List<List<IntPoint>>;
boundary_path.AddLines(boundary_Points);
Region boundary_region = new Region(boundary_path);
g.DrawPath(pen1, boundary_path);
ClipperOffset co = new ClipperOffset();
Path boundary_point_list= new Path(); //contains all IntPoints of the polygon
co.AddPath(boundary_point_list, JoinType.jtRound, EndType.etClosedPolygon);
Paths solution = new Paths(); //
co.Execute(ref solution, -7.0);
DrawPolygons(solution, 0x40808080);
g.FillPolygon(Brushes.Olive, boundary_Points);
Clipper does not provide drawing methods out-of-the-box. You'd have to convert IntPoint
to whatever format suitable for drawing manually by the drawing API that you'd like to use.
I don't use C#, but here's what I do in my code in order to convert IntPoint
to float-based type in C++:
void scale_down_polypaths(const Paths &p_polypaths_in, Vector<Vector<Point2>> &p_polypaths_out) {
p_polypaths_out.clear();
for (int i = 0; i < p_polypaths_in.size(); ++i) {
const Path &polypath_in = p_polypaths_in[i];
Vector<Vector2> polypath_out;
for (int j = 0; j < polypath_in.size(); ++j) {
polypath_out.push_back(Point2(
static_cast<real_t>(polypath_in[j].X) / SCALE_FACTOR,
static_cast<real_t>(polypath_in[j].Y) / SCALE_FACTOR));
}
p_polypaths_out.push_back(polypath_out);
}
}
The result could then be passed to the drawing API, but again, it depends on what kind of library you use. I don't have experience with GDI+.