isPointInPath
Summary
Returns true if the point given by the x and y coordinates passed to the method, when treated as coordinates in the canvas coordinate space unaffected by the current transformation, is inside the intended path as determined by the non-zero winding number rule; returns false otherwise. If either of the arguments is infinite or NaN, then the method returns false.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntax
var object = object.isPointInPath(x, y);
Parameters
x
- Data-type
- Number
The x-coordinate to test.
y
- Data-type
- Number
The y-coordinate to test.
Return Value
Returns an object of type DOM NodeDOM Node
Type: VARIANT_BOOL
This method can return one of these values.
Return value | Description |
---|---|
false | The point is not in the current path. |
true | The point is in the current path. |
Examples
This example simply tests whether a given point is in the current path (the previously defined rectangle) and alerts true or false.
<canvas id="myCanvas" width="300" height="150" style="border:1px solid blue;"></canvas>
<p>. . .</p>
<script>
var can = document.getElementById("myCanvas");
var ctxt = can.getContext("2d");
ctxt.rect(20, 20, 150, 100);
alert(ctxt.isPointInPath(30,50));
</script>
Related specifications
- W3C HTML Canvas 2D Context
- W3C Candidate Recommendation
Attributions
Microsoft Developer Network: Windows Internet Explorer API reference Article