Skip to content

Commit

Permalink
Move point_in_polygon back to kiva
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiggins committed Dec 30, 2016
1 parent de0d236 commit 338b3c0
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 105 deletions.
2 changes: 0 additions & 2 deletions enable/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@
from .viewport import Viewport
from .window import Window

from ._cython_speedups import points_in_polygon

from .primitives.api import Annotater, Box, Line, Polygon
4 changes: 2 additions & 2 deletions enable/primitives/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from numpy import array

# Enthought library imports.
from kiva.constants import EOF_FILL_STROKE, FILL, FILL_STROKE
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.
from enable.api import border_size_trait, points_in_polygon, Component
from enable.api import border_size_trait, Component
from enable.colors import ColorTrait


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
156 changes: 78 additions & 78 deletions enable/_cython_speedups.cpp → kiva/_cython_speedups.cpp

Large diffs are not rendered by default.

File renamed without changes.
2 changes: 1 addition & 1 deletion enable/_hit_test.cpp → kiva/_hit_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "_hit_test.h"

namespace enable
namespace kiva
{
// Adapted from: http://www.alienryderflex.com/polygon/
//
Expand Down
6 changes: 3 additions & 3 deletions enable/_hit_test.h → kiva/_hit_test.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ENABLE_HIT_TEST_H
#define ENABLE_HIT_TEST_H
#ifndef KIVA_HIT_TEST_H
#define KIVA_HIT_TEST_H

namespace enable
namespace kiva
{
bool point_in_polygon(double x, double y,
double* poly_pts, int Npoly_pts);
Expand Down
2 changes: 1 addition & 1 deletion enable/_hit_test.pxd → kiva/_hit_test.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


cdef extern from "_hit_test.h" namespace "enable":
cdef extern from "_hit_test.h" namespace "kiva":
void points_in_polygon(double* pts, int Npts,
double* poly_pts, int Npoly_pts,
unsigned char* results, int Nresults)
Expand Down
23 changes: 23 additions & 0 deletions kiva/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# flake8: noqa
from .affine import (
affine_identity, affine_from_values, affine_from_scale,
affine_from_rotation, affine_from_translation,
scale, rotate, translate, concat, invert, is_identity, affine_params,
tsr_factor, trs_factor, transform_point, transform_points, IDENTITY
)
from .constants import (
NO_DASH, CAP_ROUND, CAP_BUTT, CAP_SQUARE,
JOIN_ROUND, JOIN_BEVEL, JOIN_MITER,
FILL, EOF_FILL, STROKE, FILL_STROKE, EOF_FILL_STROKE,
NORMAL, BOLD, ITALIC, BOLD_ITALIC, DEFAULT,
SWISS, ROMAN, MODERN, DECORATIVE, SCRIPT, TELETYPE,
TEXT_FILL, TEXT_STROKE, TEXT_FILL_STROKE, TEXT_INVISIBLE, TEXT_FILL_CLIP,
TEXT_STROKE_CLIP, TEXT_FILL_STROKE_CLIP, TEXT_CLIP, TEXT_OUTLINE,
POINT, LINE, LINES, RECT, CLOSE, CURVE_TO, QUAD_CURVE_TO, ARC, ARC_TO,
SCALE_CTM, TRANSLATE_CTM, ROTATE_CTM, CONCAT_CTM, LOAD_CTM,
NO_MARKER, SQUARE_MARKER, DIAMOND_MARKER, CIRCLE_MARKER,
CROSSED_CIRCLE_MARKER, CROSS_MARKER, TRIANGLE_MARKER,
INVERTED_TRIANGLE_MARKER, PLUS_MARKER, DOT_MARKER, PIXEL_MARKER
)
from ._cython_speedups import points_in_polygon
from .fonttools import Font
11 changes: 8 additions & 3 deletions kiva/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Copyright (c) 2005, Enthought, Inc.
# All rights reserved.
#
Expand All @@ -11,10 +11,11 @@
#
# Author: Enthought, Inc.
# Description: <Enthought kiva package project>
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------

import sys
import os

from numpy import get_include


def configuration(parent_package=None, top_path=None):
Expand All @@ -39,4 +40,8 @@ def configuration(parent_package=None, top_path=None):

config.get_version()

ext_sources = ['_cython_speedups.cpp', '_hit_test.cpp']
config.add_extension('kiva._cython_speedups', sources=ext_sources,
include_dirs=['.', get_include()])

return config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from numpy import array, allclose

from enable.api import points_in_polygon
from kiva.api import points_in_polygon


class TestPointsInPolygon(unittest.TestCase):
Expand Down
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import shutil
import subprocess

from numpy import get_include
from numpy.distutils.core import setup
from numpy.distutils.misc_util import is_string

Expand Down Expand Up @@ -136,10 +135,6 @@ def configuration(parent_package='', top_path=None):
quiet=True,
)

ext_sources = ['enable/_cython_speedups.cpp', 'enable/_hit_test.cpp']
config.add_extension('enable._cython_speedups', sources=ext_sources,
include_dirs=['enable', get_include()])

config.add_subpackage('kiva')

return config
Expand Down

0 comments on commit 338b3c0

Please sign in to comment.