Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d753cb

Browse files
committed
Document limitations of Path.contains_point() and clarify its semantics
1 parent 1ed5c91 commit 5d753cb

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lib/matplotlib/path.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,11 @@ def transformed(self, transform):
496496

497497
def contains_point(self, point, transform=None, radius=0.0):
498498
"""
499-
Return whether the (closed) path contains the given point.
499+
Return whether the area enclosed by the path contains the given points.
500+
501+
The path is always treated as closed; i.e. if the last code is not
502+
CLOSEPOLY an implicit segment connecting the last vertex to the first
503+
vertex is assumed.
500504
501505
Parameters
502506
----------
@@ -517,6 +521,17 @@ def contains_point(self, point, transform=None, radius=0.0):
517521
Returns
518522
-------
519523
bool
524+
525+
Notes
526+
-----
527+
The current algorithm has some limitations:
528+
529+
- The result is undefined for points exactly at the boundary
530+
(including *radius*).
531+
- The result is undefined if there is no enclosed area, i.e. all
532+
vertices are on a straight line.
533+
- If bounding lines start to cross each other due to *radius* shift,
534+
the result is not guaranteed to be correct.
520535
"""
521536
if transform is not None:
522537
transform = transform.frozen()
@@ -531,7 +546,11 @@ def contains_point(self, point, transform=None, radius=0.0):
531546

532547
def contains_points(self, points, transform=None, radius=0.0):
533548
"""
534-
Return whether the (closed) path contains the given point.
549+
Return whether the area enclosed by the path contains the given point.
550+
551+
The path is always treated as closed; i.e. if the last code is not
552+
CLOSEPOLY an implicit segment connecting the last vertex to the first
553+
vertex is assumed.
535554
536555
Parameters
537556
----------
@@ -541,7 +560,7 @@ def contains_points(self, points, transform=None, radius=0.0):
541560
If not ``None``, *points* will be compared to ``self`` transformed
542561
by *transform*; i.e. for a correct check, *transform* should
543562
transform the path into the coordinate system of *points*.
544-
radius : float, default: 0.
563+
radius : float, default: 0
545564
Add an additional margin on the path in coordinates of *points*.
546565
The path is extended tangentially by *radius/2*; i.e. if you would
547566
draw the path with a linewidth of *radius*, all points on the line
@@ -552,6 +571,17 @@ def contains_points(self, points, transform=None, radius=0.0):
552571
Returns
553572
-------
554573
length-N bool array
574+
575+
Notes
576+
-----
577+
The current algorithm has some limitations:
578+
579+
- The result is undefined for points exactly at the boundary
580+
(including *radius*).
581+
- The result is undefined if there is no enclosed area, i.e. all
582+
vertices are on a straight line.
583+
- If bounding lines start to cross each other due to *radius* shift,
584+
the result is not guaranteed to be correct.
555585
"""
556586
if transform is not None:
557587
transform = transform.frozen()

0 commit comments

Comments
 (0)