Skip to content

Instantly share code, notes, and snippets.

@eddieberklee
Created December 22, 2015 23:51
Show Gist options
  • Save eddieberklee/55c6679f94b533b83283 to your computer and use it in GitHub Desktop.
Save eddieberklee/55c6679f94b533b83283 to your computer and use it in GitHub Desktop.
Android Detecting Intersection of a Touch Point with a Path
float padding = Util.dpToPx(1);
RectF touchPoint = new RectF(x, y, x + padding, y + padding);
Path touchPointPath = new Path();
touchPointPath.addRect(touchPoint, Path.Direction.CW);
for (int i = 0; i < mHourPaths.length; i++) {
hourPath = mHourPaths[i];
touchPointPath.addCircle(x, y, padding, Path.Direction.CW);
touchPointPath.close();
Path hourPathCopy = new Path(hourPath);
boolean intersectResult = hourPathCopy.op(touchPointPath, Path.Op.INTERSECT);
touchPointPath.reset();
RectF bounds = new RectF();
hourPathCopy.computeBounds(bounds, true);
// Log.d(TAG, "intersectResult: " + intersectResult + " different?: " + bounds.left+","+bounds.top+","+bounds.right+","+bounds.bottom);
if (bounds.left != 0.0 && bounds.top != 0.0 && bounds.right != 0.0 && bounds.bottom != 0.0) {
return i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment