# Path: tadlib/calfea/polygon.py
# class Polygon(ConvexHull):
#     def __init__(self, points):
#     def calarea(self):
#     def close(self):
#     def isinside(self, query, zerolike=1e-12):
# def shoelace(vertices):
# def collinear(points):


import glob, re, os, sys
import logging
import numpy as np
import scipy.special as special
from tadlib.calfea import polygon
from scipy.stats import poisson, itemfreq
from scipy.spatial import distance
from scipy.interpolate import interp1d, splrep, splev
from sklearn import cluster
                    
                    # For each cluster
                    for i in range(self.Nc):
                        extract = (self.cluster_id == i)
                        t_C = self.pos[extract]
                        
                        # Objects
                        self.clusters['obj'].append(t_C)
                        # Total object number
                        self.clusters['Cn'][i] = extract.sum()
                        
                        ## Average radius / density
                        # Core points of current cluster
                        choose = extract & cores_mask
                        cores = self.pos[choose]
                        # Distances from core points to any other points in
                        # current cluster
                        dists = distance.cdist(cores, t_C)
                        dists.sort()
                        # Average radius
                        self.clusters['radius'][i] = np.mean(dists[:, 1:self._MinPts].sum(axis = -1) / \
                                                             (self._MinPts - 1))
                        # Inverse of average radius, i.e., density
                        self.clusters['density'][i] = np.mean((self._MinPts - 1) / \
                                    dists[:, 1:self._MinPts].sum(axis = -1))
                                    
                        # Collinear test
                        judge = polygon.collinear(t_C)
                        if not judge:
                            # Represented as a convex polygon

# Path: tadlib/calfea/polygon.py
# class Polygon(ConvexHull):
#     def __init__(self, points):
#     def calarea(self):
#     def close(self):
#     def isinside(self, query, zerolike=1e-12):
# def shoelace(vertices):
# def collinear(points):


# Path: tadlib/calfea/analyze.py
import glob, re, os, sys
import logging
import numpy as np
import scipy.special as special
from tadlib.calfea import polygon
from scipy.stats import poisson, itemfreq
from scipy.spatial import distance
from scipy.interpolate import interp1d, splrep, splev
from sklearn import cluster

                    
                    # For each cluster
                    for i in range(self.Nc):
                        extract = (self.cluster_id == i)
                        t_C = self.pos[extract]
                        
                        # Objects
                        self.clusters['obj'].append(t_C)
                        # Total object number
                        self.clusters['Cn'][i] = extract.sum()
                        
                        ## Average radius / density
                        # Core points of current cluster
                        choose = extract & cores_mask
                        cores = self.pos[choose]
                        # Distances from core points to any other points in
                        # current cluster
                        dists = distance.cdist(cores, t_C)
                        dists.sort()
                        # Average radius
                        self.clusters['radius'][i] = np.mean(dists[:, 1:self._MinPts].sum(axis = -1) / \
                                                             (self._MinPts - 1))
                        # Inverse of average radius, i.e., density
                        self.clusters['density'][i] = np.mean((self._MinPts - 1) / \
                                    dists[:, 1:self._MinPts].sum(axis = -1))
                                    
                        # Collinear test
                        judge = polygon.collinear(t_C)
                        if not judge:
                            # Represented as a convex polygon

                            P = polygon.Polygon(t_C)