__copyright__ = "Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved."
__license__ = """
NVIDIA CORPORATION and its licensors retain all intellectual property
and proprietary rights in and to this software, related documentation
and any modifications thereto. Any use, reproduction, disclosure or
distribution of this software and related documentation without an express
license agreement from NVIDIA CORPORATION is strictly prohibited.
"""

import omni.kit.test
import copy
import math
import os
import platform
import sys
import time
import unittest

from . import TestRtScenegraph, tc_logger, update_path_and_load_usd


def setUpModule():
    # pre-load USD before anything else to prevent crash
    # from weird carb conflict
    # FIXME ^^^
    update_path_and_load_usd()


class TestGfRangeCopy(TestRtScenegraph):
    """Test copy and deepcopy support for Gf.Range* classes"""

    @tc_logger
    def test_copy(self):
        """Test __copy__"""
        from usdrt import Gf

        x = Gf.Range3d()
        y = x
        self.assertTrue(y is x)

        y.min[0] = 10
        self.assertEqual(x.min[0], 10)

        z = copy.copy(y)
        self.assertFalse(z is y)
        y.min[0] = 100
        self.assertEqual(z.min[0], 10)

        x = Gf.Range2d()
        y = x
        self.assertTrue(y is x)

        y.min[0] = 20
        self.assertEqual(x.min[0], 20)

        z = copy.copy(y)
        self.assertFalse(z is y)
        y.min[0] = 200
        self.assertEqual(z.min[0], 20)

        x = Gf.Range1d()
        y = x
        self.assertTrue(y is x)

        y.min = 30
        self.assertEqual(x.min, 30)

        z = copy.copy(y)
        self.assertFalse(z is y)
        y.min = 300
        self.assertEqual(z.min, 30)

    @tc_logger
    def test_deepcopy(self):
        """Test __deepcopy__"""
        from usdrt import Gf

        x = Gf.Range3d()
        y = x
        self.assertTrue(y is x)

        y.min[0] = 10
        self.assertEqual(x.min[0], 10)

        z = copy.deepcopy(y)
        self.assertFalse(z is y)
        y.min[0] = 100
        self.assertEqual(z.min[0], 10)

        x = Gf.Range2d()
        y = x
        self.assertTrue(y is x)

        y.min[0] = 20
        self.assertEqual(x.min[0], 20)

        z = copy.deepcopy(y)
        self.assertFalse(z is y)
        y.min[0] = 200
        self.assertEqual(z.min[0], 20)

        x = Gf.Range1d()
        y = x
        self.assertTrue(y is x)

        y.min = 30
        self.assertEqual(x.min, 30)

        z = copy.deepcopy(y)
        self.assertFalse(z is y)
        y.min = 300
        self.assertEqual(z.min, 30)


class TestGfRangeDebugging(TestRtScenegraph):
    """Test human readable output functions for debugging"""

    @tc_logger
    def test_repr_representation(self):
        """Test __repr__"""
        from usdrt import Gf

        test_min = Gf.Vec3d(1, 2, 3)
        test_max = Gf.Vec3d(4, 5, 6)
        test_range = Gf.Range3d(test_min, test_max)
        expected = "Gf.Range3d(Gf.Vec3d(1.0, 2.0, 3.0), Gf.Vec3d(4.0, 5.0, 6.0))"

        self.assertEqual(repr(test_range), expected)
