"""
This is the implementation of the OGN node defined in OgnATan2.ogn
"""

import math

import omni.graph.core as og


class OgnATan2:
    """
    Calculates the arc tangent of A,B.  This is the angle in radians between the ray ending at the origin and
    passing through the point (B, A).
    """

    @staticmethod
    def compute(db) -> bool:
        """Compute the outputs from the current input"""
        try:
            db.outputs.result.value = math.degrees(math.atan2(db.inputs.a.value, db.inputs.b.value))
        except TypeError as error:
            db.log_error(f"atan2 could not be performed: {error}")
            return False
        return True

    @staticmethod
    def on_connection_type_resolve(node) -> None:
        aattr = node.get_attribute("inputs:a")
        battr = node.get_attribute("inputs:b")
        resultattr = node.get_attribute("outputs:result")

        og.resolve_fully_coupled([aattr, battr, resultattr])
