c# - Converting Path & StrokeWidth to Geometry -
i have bit of code takes number of points , creates multiple linesegments build path.
system.windows.shapes.path pathsegment = new system.windows.shapes.path(); pathfigure pathfig = new pathfigure(); pathgeometry pathgeo = new pathgeometry(); pathfig.startpoint = new point(pointdata[0].x, pointdata[0].y); (int loop = 1; loop < pointdata.count; loop++) { linesegment ls = new linesegment(); ls.point = new point(pointdata[loop].x, pointdata[loop].y); pathfig.segments.add(ls); } pathgeo.figures.add(pathfig); pathsegment.data = pathgeo; pathsegment.stroke = brush; pathsegment.strokethickness = 22;
this creates line width of 22px (roughly). if @ actual data can see linesegement elements, gives output this, real line in black , actual displayed line in grey (excuse dodgy mspaint sketch):
now want perform strokecontains on geometry see if specified point within entire pathsegment above (grey area). though check against linesegments (the black line).
is there better way build path? or there way of converting pathsegment, including strokewidth new path?
it should work if use proper pen thickness in strokecontains call:
point point = ... pen pen = new pen { thickness = pathsegment.strokethickness }; bool contains = pathsegment.data.strokecontains(pen, point);
alternatively hit test on path:
bool contains = pathsegment.inputhittest(point) != null;
Comments
Post a Comment