From d3aff8bc3631841ed2517a9d4ab881d7da3244ea Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 9 Jun 2021 09:02:09 -0500 Subject: [PATCH] readd points_in_polygon to kiva.agg --- kiva/agg/__init__.py | 19 +++++++++++++++++++ kiva/tests/test_points_in_polygon.py | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/kiva/agg/__init__.py b/kiva/agg/__init__.py index 2a60e9785..6f569e00c 100644 --- a/kiva/agg/__init__.py +++ b/kiva/agg/__init__.py @@ -57,3 +57,22 @@ def __init__(self, size, pix_format=default_pix_format, warnings.warn("Error initializing Agg: %s" % ex, Warning, 2) GraphicsContextSystem = None + + +def points_in_polygon(pts, poly_pts, use_winding=False): + """Keep this function around for old code, but warn anyone who calls it. + """ + import inspect + import warnings + from kiva.api import points_in_polygon as new_points_in_polygon + + msg = "points_in_polygon() has moved to kiva.api" + frame = inspect.currentframe().f_back + warnings.warn_explicit( + msg, + category=DeprecationWarning, + filename=inspect.getfile(frame.f_code), + lineno=frame.f_lineno, + ) + + new_points_in_polygon(pts, poly_pts, use_winding=use_winding) diff --git a/kiva/tests/test_points_in_polygon.py b/kiva/tests/test_points_in_polygon.py index 6db3c7e7d..81ea40546 100644 --- a/kiva/tests/test_points_in_polygon.py +++ b/kiva/tests/test_points_in_polygon.py @@ -8,13 +8,27 @@ # # Thanks for using Enthought open source! import unittest +import warnings from numpy import allclose, array, zeros +from kiva.agg import points_in_polygon as points_in_polygon_deprecated from kiva.api import points_in_polygon class TestPointsInPolygon(unittest.TestCase): + def test_deprecated_import(self): + polygon = array(((0.0, 0.0), (10.0, 0.0), (0.0, 10.0))) + points = array(((5.0, 5.0),)) + + with warnings.catch_warnings(record=True) as collector: + warnings.simplefilter("always") + points_in_polygon_deprecated(points, polygon) + + assert len(collector) == 1 + warn = collector[0] + assert issubclass(warn.category, DeprecationWarning) + def test_empty_points_in_polygon(self): polygon = array(((0.0, 0.0), (10.0, 0.0), (10.0, 10.0), (0.0, 10.0))) points = zeros((0, 2))