'Returns a measure of the triangulation triangles flatness.
The ratio of the incircle radius over the circumcircle radius is a
widely used indicator of a triangle flatness.
It is always ``<= 0.5`` and ``== 0.5`` only for equilateral
triangles. Circle ratios below 0.01 denote very flat triangles.
To avoid unduly low values due to a difference of scale between the 2
axis, the triangular mesh can first be rescaled to fit inside a unit
square with :attr:`scale_factors` (Only if *rescale* is True, which is
its default value).
Parameters
rescale : boolean, optional
If True, a rescaling will be internally performed (based on
:attr:`scale_factors`, so that the (unmasked) triangles fit
exactly inside a unit square mesh. Default is True.
Returns
circle_ratios : masked array
Ratio of the incircle radius over the
circumcircle radius, for each \'rescaled\' triangle of the
encapsulated triangulation.
Values corresponding to masked triangles are masked out.'

def circle_ratios(self, rescale=True):

    if rescale:
        (kx, ky) = self.scale_factors
    else:
        (kx, ky) = (1.0, 1.0)
    pts = np.vstack([(self._triangulation.x * kx), (self._triangulation.y * ky)]).T
    tri_pts = pts[self._triangulation.triangles]
    a = (tri_pts[:, 1, :] - tri_pts[:, 0, :])
    b = (tri_pts[:, 2, :] - tri_pts[:, 1, :])
    c = (tri_pts[:, 0, :] - tri_pts[:, 2, :])
    a = np.sqrt(((a[:, 0] ** 2) + (a[:, 1] ** 2)))
    b = np.sqrt(((b[:, 0] ** 2) + (b[:, 1] ** 2)))
    c = np.sqrt(((c[:, 0] ** 2) + (c[:, 1] ** 2)))
    s = (((a + b) + c) * 0.5)
    prod = (((s * ((a + b) - s)) * ((a + c) - s)) * ((b + c) - s))
    bool_flat = (prod == 0.0)
    if np.any(bool_flat):
        ntri = tri_pts.shape[0]
        circum_radius = np.empty(ntri, dtype=np.float64)
        circum_radius[bool_flat] = np.inf
        abc = ((a * b) * c)
        circum_radius[(~ bool_flat)] = (abc[(~ bool_flat)] / (4.0 * np.sqrt(prod[(~ bool_flat)])))
    else:
        circum_radius = (((a * b) * c) / (4.0 * np.sqrt(prod)))
    in_radius = (((a * b) * c) / ((4.0 * circum_radius) * s))
    circle_ratio = (in_radius / circum_radius)
    mask = self._triangulation.mask
    if (mask is None):
        return circle_ratio
    else:
        return np.ma.array(circle_ratio, mask=mask)
