# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):


import sys, numpy, types, pickle, time, math
import logging
import condor.utils.linalg
from .log import log_and_raise_error,log_warning,log_info,log_debug
        # The reference states this:
        #e1 = -numpy.arcsin(v3r[i1])
        # The tests only pass with the inverse sign, so I guess this is a typo.
        e1 = numpy.arcsin(v3r[i1])
    q1 = numpy.array([numpy.cos(e0/2.), 0., 0., 0.])
    q1[1+i1] = numpy.sin(e0/2.)
    q2 = numpy.array([numpy.cos(e1/2.), 0., 0., 0.])
    q2[1+i2] = numpy.sin(e1/2.)
    q12 = quat_mult(q1, q2)
    v3n = numpy.array([0.,0.,0.])
    v3n[(i3+1)%3] = 1.
    v3n12 = quat_vec_mult(q12, v3n)
    v3nG = quat_vec_mult(q, v3n)
    dprod = condor.utils.linalg.dotproduct(v3n12,v3nG)
    if abs(dprod) > 1.:
        dprod = numpy.sign(dprod)
    e2_mag = numpy.arccos(dprod)
    vc = condor.utils.linalg.crossproduct(v3n12, v3nG)
    m = condor.utils.linalg.dotproduct(vc, v3r)
    e2 = numpy.sign(m) * e2_mag
    return numpy.array([e0,e1,e2])



# CONVERSIONS FOR UNIQUE REPRESENTATION

def make_euler_unique_repax(euler):
    r"""
    Make Euler angles for roations with a repeated axis (zxz, zyz, yzy, yxy, xzx, xyx) unique (such that three euler angles uniquely define a rotation).


# Path: condor/utils/log.py
# def log(logger, message, lvl, exception=None, rollback=1):
# def log_execution_time(logger):
#     def st_time(func):
#         def st_func(*args, **keyArgs):


# Path: condor/utils/rotation.py
import sys, numpy, types, pickle, time, math
import logging
import condor.utils.linalg
from .log import log_and_raise_error,log_warning,log_info,log_debug

        # The reference states this:
        #e1 = -numpy.arcsin(v3r[i1])
        # The tests only pass with the inverse sign, so I guess this is a typo.
        e1 = numpy.arcsin(v3r[i1])
    q1 = numpy.array([numpy.cos(e0/2.), 0., 0., 0.])
    q1[1+i1] = numpy.sin(e0/2.)
    q2 = numpy.array([numpy.cos(e1/2.), 0., 0., 0.])
    q2[1+i2] = numpy.sin(e1/2.)
    q12 = quat_mult(q1, q2)
    v3n = numpy.array([0.,0.,0.])
    v3n[(i3+1)%3] = 1.
    v3n12 = quat_vec_mult(q12, v3n)
    v3nG = quat_vec_mult(q, v3n)
    dprod = condor.utils.linalg.dotproduct(v3n12,v3nG)
    if abs(dprod) > 1.:
        dprod = numpy.sign(dprod)
    e2_mag = numpy.arccos(dprod)
    vc = condor.utils.linalg.crossproduct(v3n12, v3nG)
    m = condor.utils.linalg.dotproduct(vc, v3r)
    e2 = numpy.sign(m) * e2_mag
    return numpy.array([e0,e1,e2])



# CONVERSIONS FOR UNIQUE REPRESENTATION

def make_euler_unique_repax(euler):
    r"""
    Make Euler angles for roations with a repeated axis (zxz, zyz, yzy, yxy, xzx, xyx) unique (such that three euler angles uniquely define a rotation).


    *There are the following ambiguities:*