# Path: e3d/commonValues.py
# def scaleNumber(val, src, dst):
#     """
#     http://stackoverflow.com/a/4155197
# 
#     Scale the given value from the scale of src to the scale of dst.
# 
#     @rtype : int
#     @type dst: list
#     @type src: list
#     @type val: int
# 
#     Examples:
#     >> scaleNumber(0, (0.0, 99.0), (-1.0, 1.0))
#     -1.0
#     >> scaleNumber(99, (0.0, 99.0), (-1.0, 1.0))
#     1
#     >> scaleNumber(1, (0.0, 2.0), (0.0, 1.0))
#     0.5
#     """
#     try:
#         return ((val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]
#     except ZeroDivisionError:
#         return dst[1] / 2.0


from collections import defaultdict
from cycgkit.cgtypes import *
from cycgkit.boundingbox import BoundingBox
from numpy import arccos, arctan2, array, float32, ndarray, pi, sqrt, uint32
from ..commonValues import scaleNumber
import numpy as np
    def calculatePlanarUVS(groupedVertices, normal):
        if isinstance(normal, list):
            if normal.__len__() > 1:
                normal = vec3(normal[0])
            else:
                normal = vec3(normal)

        uvs = []
        bbox = BoundingBox()
        M = mat3.fromToRotation(normal, vec3(0, 0, 1))
        newverts = []

        for v in groupedVertices:
            faceverts = []
            for vv in v:
                ver = M * vec3(vv)
                faceverts.append(ver)
            newverts.append(faceverts)

        for v in newverts:
            for vv in v:
                bbox.addPoint(vv)

        src1, src2 = bbox.getBounds()
        srcU = [src1.x, src2.x]
        srcV = [src1.y, src2.y]

        for v in newverts:
            for ver in v:
                U = scaleNumber(ver.x, srcU, [0.0, 1.0])

# Path: e3d/commonValues.py
# def scaleNumber(val, src, dst):
#     """
#     http://stackoverflow.com/a/4155197
# 
#     Scale the given value from the scale of src to the scale of dst.
# 
#     @rtype : int
#     @type dst: list
#     @type src: list
#     @type val: int
# 
#     Examples:
#     >> scaleNumber(0, (0.0, 99.0), (-1.0, 1.0))
#     -1.0
#     >> scaleNumber(99, (0.0, 99.0), (-1.0, 1.0))
#     1
#     >> scaleNumber(1, (0.0, 2.0), (0.0, 1.0))
#     0.5
#     """
#     try:
#         return ((val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]
#     except ZeroDivisionError:
#         return dst[1] / 2.0


# Path: e3d/model_management/MeshClass.py
from collections import defaultdict
from cycgkit.cgtypes import *
from cycgkit.boundingbox import BoundingBox
from numpy import arccos, arctan2, array, float32, ndarray, pi, sqrt, uint32
from ..commonValues import scaleNumber
import numpy as np

    def calculatePlanarUVS(groupedVertices, normal):
        if isinstance(normal, list):
            if normal.__len__() > 1:
                normal = vec3(normal[0])
            else:
                normal = vec3(normal)

        uvs = []
        bbox = BoundingBox()
        M = mat3.fromToRotation(normal, vec3(0, 0, 1))
        newverts = []

        for v in groupedVertices:
            faceverts = []
            for vv in v:
                ver = M * vec3(vv)
                faceverts.append(ver)
            newverts.append(faceverts)

        for v in newverts:
            for vv in v:
                bbox.addPoint(vv)

        src1, src2 = bbox.getBounds()
        srcU = [src1.x, src2.x]
        srcV = [src1.y, src2.y]

        for v in newverts:
            for ver in v:
                U = scaleNumber(ver.x, srcU, [0.0, 1.0])

                V = scaleNumber(ver.y, srcV, [0.0, 1.0])