I'm not sure why this happens, here's some code that causes the bug. I'm using python 3.6, and the latest version from github of tripy.
import numpy as np
import tripy
import matplotlib.pyplot as plt
%matplotlib inline
poly = np.array([[ 229.28340553, 78.91250014],
[ 258.42948809, 17.98278109],
[ 132.01956999, -22.96900817],
[ 107.97774096, 23.39276058],
[ 65.85573925, 28.63846858],
[ 41.66373597, -92.78859248],
[ -5.59948763, -54.18987786],
[ -44.61508682, -69.7461117 ],
[ -28.41208894, -106.93810071],
[ -71.11899145, -125.56044277],
[-100.84787818, -88.51853387],
[-211.53564549, -160.76853269],
[-244.22754588, -147.51172179],
[-226.83717643, -42.0984372 ],
[-230.65279618, -10.5455196 ],
[-240.50239817, 70.87826746],
[ -12.48219264, 137.70176109],
[ 4.65848369, 204.21077075],
[ 176.5243417 , 193.73497584],
[ 171.13537712, 87.27009315],
[ 229.28340553, 78.91250014]])
tuplepoly = [tuple(p) for p in poly]
tris = tripy.earclip(tuplepoly)
for t in np.array(tris):
plt.plot(t[[0,1,2,0],0],t[[0,1,2,0],1])
plt.plot(poly[:,0],poly[:,1],'k-',lw=3)
![index](https://user-images.githubusercontent.com/7914304/33623580-64ed12e4-d9e9-11e7-87a6-9ab3bd40ebe1.png)
Some triangles are wrongly selected I think.
I tried making the polygon open (i.e. left the last point off), and I've also tried using the numpy array directly, and not turn it into an array of tuples. -- neither had any effect.
I found that weirdly, when using the data this came from directly, it worked. But if I transformed the array in some way it failed as above. I don't understand why that would happen...
OK, this polygon also reproduces the problem:
poly = np.array([[ 229, 78],[66, 28.7],[-244.2, -147.5],[-226, -42],[ 229, 78]])
But I found that the problem goes away if I scale the polygon by 1000, e.g.:
poly = np.array([[ 229, 78],[66, 28.7],[-244.2, -147.5],[-226, -42],[ 229, 78]])*1000
I get that there might be problems if the polygon have very weirdly narrow or zero area sections (or worse) but I think this polygon is fairly reasonable. The first polygon at the top of this issue is from the UK output area boundaries for the census.
(by the way, thanks for the module!)