Created
December 22, 2015 23:51
-
-
Save eddieberklee/55c6679f94b533b83283 to your computer and use it in GitHub Desktop.
Android Detecting Intersection of a Touch Point with a Path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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