Test if mouse clic inside an ofPath shape

Hello,

I am working with shapes as ofPath. I would like to select a shape with the mouse so i need to test if the mouse is clicked inside the shape.

I know there is a function inside(x, y) but tied to the class ofPolyline.

Is there a way to access such a method from within ofPath or do i have to convert the path to a polyline everytime i need to test the mouse clic ?

thank you

If you are OK with Processing code:

  
// based on http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
  // check if input is inside polygon
  // points is an array of polygon points; input is point to check if its iside polygon
  boolean checkPointInsidePolygon(Point[] points, PVector input)
  {
    int i, j;
    boolean c = false;
    for (i = 0, j = points.length-1; i < points.length; j = i++) {
      if ( ((points[i].y>input.y) != (points[j].y>input.y)) &&
        (input.x < (points[j].x-points[i].x) * (input.y-points[i].y) / (points[j].y-points[i].y) + points[i].x) )
        c = !c;
    }
    return c;
  }
}

pass ofPath points instead of Point[] points as a parameter

Hey, thanks for the tip.
I was more looking for an oF integrated solution (if it exists)
I will have a look at it. Quite theoretical though, but really interesting.

For now i am just converting the path into an ofPolyline when needed in order to be able to use the inside() method… but seems a messy solution…

Your method with polyline is probably the easiest as of right now.