//
        //  R
        //  |  (root tip pointing to child)
        //  C
        //
        protected List <UniqueSpriteBone> GenerateNormalTwoBoneRawData()
        {
            var rawData = new List <UniqueSpriteBone>();

            var root = new UniqueSpriteBone();

            root.name     = "root";
            root.position = Vector2.one;
            root.rotation = Quaternion.Euler(0.0f, 0.0f, 270.0f);
            root.length   = 0.5f;
            root.parentId = -1;

            var child = new UniqueSpriteBone();

            child.name     = "child";
            child.position = Vector2.right;
            child.rotation = Quaternion.Euler(0.0f, 0.0f, 45.0f);
            child.length   = 1.5f;
            child.parentId = 0;

            rawData.Add(root);
            rawData.Add(child);

            return(rawData);
        }
        public void CreateNewRoot_CreateAChild_GetCorrectData()
        {
            var root  = m_Model.CreateNewRoot(Vector2.zero);
            var child = m_Model.CreateNewChildBone(root, Vector2.one);

            var expectedRawData = new List <UniqueSpriteBone>();

            var sbRoot = new UniqueSpriteBone();

            sbRoot.name     = "root";
            sbRoot.position = Vector2.zero;
            sbRoot.rotation = Quaternion.identity;
            sbRoot.length   = 0.0f;
            sbRoot.parentId = -1;

            var sbChild = new UniqueSpriteBone();

            sbChild.name     = child.name;
            sbChild.position = Vector2.one;
            sbChild.rotation = Quaternion.identity;
            sbChild.length   = 0.0f;
            sbChild.parentId = 0;

            expectedRawData.Add(sbRoot);
            expectedRawData.Add(sbChild);

            var actualRawData = m_Model.GetRawData();

            VerifyApproximatedSpriteBones(expectedRawData, actualRawData);
        }
        public void LoadExistingHierarchy_CreatingNewBone_NameCounterCountinueFromLargest()
        {
            var rawData = new List <UniqueSpriteBone>();

            var root = new UniqueSpriteBone();

            root.name     = "root";
            root.position = Vector2.up;
            root.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            root.length   = 1f;
            root.parentId = -1;

            var child1 = new UniqueSpriteBone();

            child1.name     = "bone_1";
            child1.position = Vector2.one;
            child1.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child1.length   = 1.0f;
            child1.parentId = 0;

            var child2 = new UniqueSpriteBone();

            child2.name     = "bone_100";
            child2.position = Vector2.one + Vector2.right;
            child2.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child2.length   = 1.0f;
            child2.parentId = 1;

            var child3 = new UniqueSpriteBone();

            child3.name     = "bone_2";
            child3.position = Vector2.right;
            child3.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child3.length   = 1.0f;
            child3.parentId = 1;

            var child4 = new UniqueSpriteBone();

            child4.name     = "bone_54";
            child4.position = Vector2.right * 2;
            child4.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child4.length   = 1.0f;
            child4.parentId = 3;

            rawData.Add(root);
            rawData.Add(child1);
            rawData.Add(child2);
            rawData.Add(child3);
            rawData.Add(child4);

            m_Model.SetRawData(rawData, Vector2.zero);

            var rootBone = m_Model.bones.ElementAt(0);
            var bone101  = m_Model.CreateNewChildBone(rootBone, Vector3.one);

            Assert.AreEqual("bone_101", bone101.name);
        }
        //
        //  R--C1--C2--
        //      |(C1 tip pointed to C2, C2 & C3 are children of C1)
        //     C3--C4--
        //
        protected List <UniqueSpriteBone> GenerateComplexBoneRawData()
        {
            var rawData = new List <UniqueSpriteBone>();

            var root = new UniqueSpriteBone();

            root.name     = "root";
            root.position = Vector2.up;
            root.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            root.length   = 1f;
            root.parentId = -1;

            var child1 = new UniqueSpriteBone();

            child1.name     = "child1";
            child1.position = Vector2.one;
            child1.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child1.length   = 1.0f;
            child1.parentId = 0;

            var child2 = new UniqueSpriteBone();

            child2.name     = "child2";
            child2.position = Vector2.one + Vector2.right;
            child2.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child2.length   = 1.0f;
            child2.parentId = 1;

            var child3 = new UniqueSpriteBone();

            child3.name     = "child3";
            child3.position = Vector2.right;
            child3.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child3.length   = 1.0f;
            child3.parentId = 1;

            var child4 = new UniqueSpriteBone();

            child4.name     = "child4";
            child4.position = Vector2.right * 2;
            child4.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
            child4.length   = 1.0f;
            child4.parentId = 3;

            rawData.Add(root);
            rawData.Add(child1);
            rawData.Add(child2);
            rawData.Add(child3);
            rawData.Add(child4);

            return(rawData);
        }
        public void SetNewData_ApplyWillSetTheNewBone()
        {
            var data    = m_CacheManager.GetSpriteBoneRawData(m_ID1);
            var newBone = new UniqueSpriteBone();

            newBone.name = "root";
            data.Add(newBone);

            m_CacheManager.SetSpriteBoneRawData(m_ID1, data);
            m_CacheManager.Apply();

            m_BoneDPMock.ReceivedWithAnyArgs(1).SetBones(Arg.Any <GUID>(), Arg.Any <List <SpriteBone> >());
            m_BoneDPMock.Received(1).SetBones(m_ID1, Arg.Is <List <SpriteBone> >(x => x[0].name == "root"));
        }
        public void CreateNewRootInBlank_GetARootWithDefaultValue()
        {
            m_Model.CreateNewRoot(Vector2.left);

            var expectedRawData = new List <UniqueSpriteBone>();
            var root            = new UniqueSpriteBone();

            root.name     = "root";
            root.position = Vector2.left;
            root.rotation = Quaternion.identity;
            root.length   = 0.0f;
            root.parentId = -1;
            expectedRawData.Add(root);

            var actualRawData = m_Model.GetRawData();

            VerifyApproximatedSpriteBones(expectedRawData, actualRawData);
        }
        public void CreateNewRootInBlank_DefineANewTip_GetARotatedAndLengthenRoot()
        {
            var root = m_Model.CreateNewRoot(Vector2.zero);

            m_Model.MoveTip(root, Vector2.up);

            var expectedRawData = new List <UniqueSpriteBone>();
            var sbRoot          = new UniqueSpriteBone();

            sbRoot.name     = "root";
            sbRoot.position = Vector2.zero;
            sbRoot.rotation = Quaternion.Euler(0.0f, 0.0f, 90.0f);
            sbRoot.length   = 1.0f;
            sbRoot.parentId = -1;
            expectedRawData.Add(sbRoot);

            var actualRawData = m_Model.GetRawData();

            VerifyApproximatedSpriteBones(expectedRawData, actualRawData);
        }
        public void MoveBoneTipToOppositeDirection_RotateAlongZAxisCorrectly()
        {
            var root = m_Model.CreateNewRoot(Vector2.zero);

            // This will trigger a 180 degree rotation, as bone is pointed at Vector.right.
            // this rotation must happen on Z axis.
            m_Model.MoveTip(root, Vector2.left);

            var expectedRawData = new List <UniqueSpriteBone>();
            var sbRoot          = new UniqueSpriteBone();

            sbRoot.name     = "root";
            sbRoot.position = Vector2.zero;
            sbRoot.rotation = Quaternion.Euler(0.0f, 0.0f, 180.0f);
            sbRoot.length   = 1.0f;
            sbRoot.parentId = -1;
            expectedRawData.Add(sbRoot);

            var actualRawData = m_Model.GetRawData();

            VerifyApproximatedSpriteBones(expectedRawData, actualRawData);
        }
        public void CreateNewRootInBlankTwice_ThrowException_GetOnlyOneRoot()
        {
            m_Model.CreateNewRoot(Vector2.zero);

            Assert.Throws <InvalidOperationException>(
                () => { m_Model.CreateNewRoot(Vector2.one); },
                "Creating a new root when there are bones in this sprite");

            var expectedRawData = new List <UniqueSpriteBone>();
            var sbRoot          = new UniqueSpriteBone();

            sbRoot.name     = "root";
            sbRoot.position = Vector2.zero;
            sbRoot.rotation = Quaternion.identity;
            sbRoot.length   = 0.0f;
            sbRoot.parentId = -1;
            expectedRawData.Add(sbRoot);

            var actualRawData = m_Model.GetRawData();

            VerifyApproximatedSpriteBones(expectedRawData, actualRawData);
        }