# Path: e3d/model_management/pygeom/face3.py
# class Face3:
#     def __init__(self, a, b, c, normals=None):
#         if normals is None:
#             normals = []
#         self.a = a
#         self.b = b
#         self.c = c
#         self.vertexNormals = normals
#         self.normal = vec3()
# 
#     def abcVec3(self):
#         return vec3(self.a, self.b, self.c)
# 
#     def __repr__(self):
#         return '{},{},{}'.format(self.a, self.b, self.c)


from cycgkit.cgtypes import vec3, mat4
from uuid import uuid1
from .face3 import Face3
import math
    def mergeVertices(self):
        verticesMap = {}  # Hashmap for looking up vertice by position coordinates (and making sure they are unique)
        unique = []
        changes = {}

        precisionPoints = 4  # number of decimal points, eg. 4 for epsilon of 0.0001
        precision = math.pow(10, precisionPoints)

        for i in range(len(self.vertices)):
            v = self.vertices[i]
            key = '{}_{}_{}'.format(round(v.x * precision), round(v.y * precision), round(v.z * precision))

            if verticesMap.get(key) is None:
                verticesMap[key] = i
                unique.append(self.vertices[i])
                changes[i] = len(unique) - 1
            else:
                # console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key])
                changes[i] = changes[verticesMap[key]]

        # if faces are completely degenerate after merging vertices, we
        # have to remove them from the geometry.
        faceIndicesToRemove = []

        for i in range(len(self.faces)):

            face = self.faces[i]

            face.a = changes[face.a]
            face.b = changes[face.b]

# Path: e3d/model_management/pygeom/face3.py
# class Face3:
#     def __init__(self, a, b, c, normals=None):
#         if normals is None:
#             normals = []
#         self.a = a
#         self.b = b
#         self.c = c
#         self.vertexNormals = normals
#         self.normal = vec3()
# 
#     def abcVec3(self):
#         return vec3(self.a, self.b, self.c)
# 
#     def __repr__(self):
#         return '{},{},{}'.format(self.a, self.b, self.c)


# Path: e3d/model_management/pygeom/Geometry.py
from cycgkit.cgtypes import vec3, mat4
from uuid import uuid1
from .face3 import Face3
import math

    def mergeVertices(self):
        verticesMap = {}  # Hashmap for looking up vertice by position coordinates (and making sure they are unique)
        unique = []
        changes = {}

        precisionPoints = 4  # number of decimal points, eg. 4 for epsilon of 0.0001
        precision = math.pow(10, precisionPoints)

        for i in range(len(self.vertices)):
            v = self.vertices[i]
            key = '{}_{}_{}'.format(round(v.x * precision), round(v.y * precision), round(v.z * precision))

            if verticesMap.get(key) is None:
                verticesMap[key] = i
                unique.append(self.vertices[i])
                changes[i] = len(unique) - 1
            else:
                # console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key])
                changes[i] = changes[verticesMap[key]]

        # if faces are completely degenerate after merging vertices, we
        # have to remove them from the geometry.
        faceIndicesToRemove = []

        for i in range(len(self.faces)):

            face = self.faces[i]

            face.a = changes[face.a]
            face.b = changes[face.b]

            face.c = changes[face.c]