Defines the algorithms that perform the mapping from precincts to districts.
Uses the Voronoi algorithm to assign precincts to districts.
Adds a new fiducial at
location – The fiducial location
The (assigned) ID of the fiducial.
Uses the pre-computed precinct and district maps and assigns all the precincts to districts.
Returns list of precincts, per district. Indices correspond with the district identity index in unique_ids as filled into pixel_district_map.
compute_district_pixels(fiducials, fiducials_identity, unique_ids)[source]¶
Computes the assignment of pixels to districts and creates the associated districts.
fiducials and fiducials_identity must be sorted such that they correspond to each other. All ids must be in unique ids. pixel_district_map is filled in with the index of the district identity in unique_ids to make it 0-n-1.
A list of all current
dict of tuples, each containing the
(x, y)coordinates of the fiducial at that key.
The district under the fiducial.
pos – position.
The district under the position, or None if none.
fiducialfrom its previous location to a new location.
fiducialID as returned by
location – The new fiducial location
A width by height matrix, where each item is the district index in
districtsit belongs to. Read_only (used by the thread).
A list of all the
fiducialfrom the diagram.
fiducialID as returned by
screen_size= (1920, 1080)¶
The size of the screen, in pixels, on which the districts and precincts are drawn, and on which the fiducials are drawn.
Adds the precincts to be used by the mapping.
Must be called only (or every time) after
precincts – List of
A list of tuples describing the
ycoordinates of each of the objects placed by the user at that location.
Reconstruct infinite voronoi regions in a 2D diagram to finite regions.
based on https://stackoverflow.com/a/20678647.
- regionslist of tuples
Indices of vertices in each revised Voronoi regions.
- verticeslist of tuples
Coordinates for revised Voronoi vertices. Same as coordinates of input vertices, with ‘points at infinity’ appended to the end.
The collider module contains classes which can be used to test membership of a point in some space. See individual class documentation for details.
To use it you first have to cythonize the code. To do that, cd to the directory containing collider.pyx and:
python setup.py build_ext --inplace
PolygonCollider checks whether a point is within a polygon defined by a list of corner points.
rectis (x, y, width, height)
Based on http://alienryderflex.com/polygon/
For example, a simple triangle:
>>> collider = PolygonCollider([10., 10., 20., 30., 30., 10.], ... cache=True) >>> (0.0, 0.0) in collider False >>> (20.0, 20.0) in collider True
The constructor takes a list of x,y points in the form of [x1,y1,x2,y2…] as the points argument. These points define the corners of the polygon. The boundary is linearly interpolated between each set of points. The x, and y values must be floating points. The cache argument, if True, will calculate membership for all the points so when collide_point is called it’ll just be a table lookup.
Returns the bounding box containing the polygon as 4 points (x1, y1, x2, y2), where x1, y1 is the lower left and x2, y2 is the upper right point of the rectangle.
Returns a list of all the points that are within the polygon.