To determine whether a vertex is in a closed path, you can regard the path as a set of points, that is, the path can be considered as a polygon, the problem is to judge whether a point is in a polygon.
Http://en.wikipedia.org/wiki/point_in_polygonis used to determine whether a vertex is in a polygon.
The followingCodeDescribes a set of cable categories, which can determine whether a point is in a set of cable areas drawn by the user's finger:
/*** A polygon represents a lasso. ** @ author snow **/public class lasso {// polygon coordinatesprivate float [] mpolyx, mpolyy; // Number of size in polygonprivate int mpolysize; /*** default constructor ** @ Param PX * polygon coordinates x * @ Param py * polygon coordinates y * @ Param PS * polygon sides count */Public Lasso (float [] PX, float [] py, int PS) {This. mpolyx = px; this. mpolyy = py; this. Mpolysize = Ps;}/*** constructor ** @ Param pointfs * points list of the lasso */Public Lasso (list <pointf> pointfs) {This. mpolysize = pointfs. size (); this. mpolyx = new float [this. mpolysize]; this. mpolyy = new float [this. mpolysize]; for (INT I = 0; I <this. mpolysize; I ++) {This. mpolyx [I] = pointfs. get (I ). x; this. mpolyy [I] = pointfs. get (I ). y;} log. D ("lasso", "lasso size:" + mpolysize);}/*** check if T His polygon contains the point. ** @ Param x * point coordinate X * @ Param y * point coordinate y * @ return point is in polygon flag */Public Boolean contains (float X, float y) {boolean result = false; For (INT I = 0, j = mpolysize-1; I <mpolysize; j = I ++) {If (mpolyy [I] <Y & mpolyy [J]> = y) | (mpolyy [J] <Y & mpolyy [I]> = y )) {If (mpolyx [I] + (Y-mpolyy [I])/(mpolyy [J]-mpolyy [I]) * (MPO Lyx [J]-mpolyx [I]) <X) {result =! Result ;}} return result ;}}
When a user's finger is scratched on the screen, the point that the finger is crossed can be saved to instantiate the lasso class, or the point of the closed path object can be retrieved through the pathmeasure class after the user's finger is lifted, then instantiate the lasso class.
In the lasso class, the contains method is used to determine whether the vertex is within the polygon,Source codeSee http://stackoverflow.com/a/2922778/1969158.