Skip to content

Commit

Permalink
Merge pull request #250 from enthought/refactor/hit-testing
Browse files Browse the repository at this point in the history
Move points_in_polygon to Cython
  • Loading branch information
corranwebster authored May 26, 2017
2 parents f3ad09b + b170a17 commit e09da89
Show file tree
Hide file tree
Showing 16 changed files with 19,360 additions and 231 deletions.
7 changes: 3 additions & 4 deletions enable/primitives/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from numpy import array

# Enthought library imports.
from kiva.constants import EOF_FILL_STROKE, FILL, FILL_STROKE
from kiva.agg import points_in_polygon
from traits.api import Any, Event, Float, HasTraits, Instance, List, \
Property, Trait, Tuple
from kiva.api import EOF_FILL_STROKE, FILL, FILL_STROKE, points_in_polygon
from traits.api import (Any, Event, Float, HasTraits, Instance, List,
Property, Trait, Tuple)
from traitsui.api import Group, View

# Local imports.
Expand Down
18 changes: 9 additions & 9 deletions examples/kiva/agg/polygon_hit_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import numpy

from kiva import agg
from kiva.api import points_in_polygon

poly = numpy.array((( 0.0, 0.0),
(10.0, 0.0),
(10.0, 10.0),
( 0.0, 10.0)))

print(agg.point_in_polygon(-1,-1,poly))
print(agg.point_in_polygon(0.0,0.0,poly))
print(agg.point_in_polygon(5,5,poly))
print(agg.point_in_polygon(10,10,poly))
print(agg.point_in_polygon(15,15,poly))
print(point_in_polygon(-1,-1,poly))
print(point_in_polygon(0.0,0.0,poly))
print(point_in_polygon(5,5,poly))
print(point_in_polygon(10,10,poly))
print(point_in_polygon(15,15,poly))

pts = numpy.array(((-1.0, -1.0),
( 0.1, 0.0),
Expand All @@ -21,15 +21,15 @@
( 10.0, 10.0),
( 15.0, 15.0)))

results = agg.points_in_polygon(pts, poly)
results = points_in_polygon(pts, poly)

print(results)

pts = numpy.random.random_sample((20000, 2))*12.5-2.5

import time
t1 = time.clock()
results = agg.points_in_polygon(pts, poly)
results = points_in_polygon(pts, poly)
t2 = time.clock()
print('points_in_polygon() for %d pts in %d point polygon (sec): %f' % \
(len(pts), len(poly), t2-t1))
Expand All @@ -51,7 +51,7 @@
( 0.0, 10.0)))

t1 = time.clock()
results = agg.points_in_polygon(pts, poly)
results = points_in_polygon(pts, poly)
t2 = time.clock()
print('points_in_polygon() for %d pts in %d point polygon (sec): %f' % \
(len(pts), len(poly), t2-t1))
Expand Down
Loading

0 comments on commit e09da89

Please sign in to comment.