예제 #1
0
        public void OnUnite()
        {
            /*if (IsLowest)
             * {
             *  if (IsRoot)
             *      return;
             *
             *  Parents.OnUnite();
             * }
             * else if (IsSecondLowest)
             * {
             *  HandleOnUnite();
             * }
             * else
             * {
             *  Face2D secondLowest = FindSecondLowestChild();
             *
             *  if (secondLowest != null)
             *  {
             *      secondLowest.OnUnite();
             *  }
             * }*/

            Face2D lastChild = FindLastSecondLowestChild();

            if (lastChild != null)
            {
                lastChild.HandleOnUnite();
            }
        }
예제 #2
0
        public static void UnitTest()
        {
            Face2D face_0 = new Face2D("0");

            Face2D face_0_0 = new Face2D("0_0");
            Face2D face_0_1 = new Face2D("0_1");
            Face2D face_0_2 = new Face2D("0_2");

            face_0.DivideTo(face_0_0, face_0_1, face_0_2);

            Face2D face_0_0_0 = new Face2D("0_0_0");
            Face2D face_0_0_1 = new Face2D("0_0_1");
            Face2D face_0_0_2 = new Face2D("0_0_2");

            face_0_0.DivideTo(face_0_0_0, face_0_0_1, face_0_0_2);

            Face2D face_0_2_0 = new Face2D("0_2_0");
            Face2D face_0_2_1 = new Face2D("0_2_1");
            Face2D face_0_2_2 = new Face2D("0_2_2");

            face_0_2.DivideTo(face_0_2_0, face_0_2_1, face_0_2_2);

            Face2D face_0_2_0_0 = new Face2D("0_2_0_0");
            Face2D face_0_2_0_1 = new Face2D("0_2_0_1");
            Face2D face_0_2_0_2 = new Face2D("0_2_0_2");

            face_0_2_0.DivideTo(face_0_2_0_0, face_0_2_0_1, face_0_2_0_2);



            Debug.Log(face_0.ToString());

            face_0_1.OnUnite();
        }
예제 #3
0
        protected Face2D FindSecondLowestChild()
        {
            if (IsLowest)
            {
                return(null);
            }

            foreach (var child in Childern)
            {
                if (child.IsLowest)
                {
                    continue;
                }
                if (child.IsSecondLowest)
                {
                    return(child);
                }
                Face2D face = child.FindSecondLowestChild();
                if (face != null)
                {
                    return(face);
                }
            }
            return(null);
        }
예제 #4
0
 public void AddFaces(Face2D face)
 {
     if (Faces.Contains(face))
     {
         throw new InvalidOperationException("Edge already contains face!");
     }
     Faces.Add(face);
 }
예제 #5
0
        public void RemoveFace(Face2D face)
        {
            Faces.Remove(face);

            _lazyExitedEdges.isValeChanged = true;
            _lazyAllEdges.isValeChanged    = true;
            _lazyAllPoints.isValeChanged   = true;
            //face.BasicEdges.ForEach(e => e.Faces.Remove(face));

            /*_lazyAllEdges.isValeChanged = true;
             * _lazyAllPoints.isValeChanged = true;*/
        }
예제 #6
0
 public Face2D AddFace(Face2D face)
 {
     if (Faces.Any(f => f.IsMatchFor(face)))
     {
         //throw new InvalidOperationException("There is already such a face in the shape!");
         Debug.Log("There is already such a face in the shape!");
         return(face);
     }
     Faces.Add(face);
     face.Shape = this;
     _lazyExitedEdges.isValeChanged = true;
     _lazyAllEdges.isValeChanged    = true;
     _lazyAllPoints.isValeChanged   = true;
     return(face);
 }
예제 #7
0
        public void OnDivide()
        {
            if (Scale < 0.5f)
            {
                return;
            }

            if (!IsLowest)
            {
                throw new System.Exception("This face has divided!");
            }

            CenterPoint = new Point2D(Center, "Center");
            CenterPoint.AddRigidbody();

            List <Point2D> division = DivideBasicEdges();

            /*Face2D f0 = Shape.AddPoints(division[0], division[1], division[2], division[3], CenterPoint, division[11]);
             * Face2D f1 = Shape.AddPoints(CenterPoint, division[3], division[4], division[5], division[6], division[7]);
             * Face2D f2 = Shape.AddPoints(division[10], division[11], CenterPoint, division[7], division[8], division[9]);*/

            /*Face2D f0 = Shape.AddPoints(division[11], division[0], division[1], division[2], division[3], CenterPoint);
             * Face2D f1 = Shape.AddPoints(division[3], division[4], division[5], division[6], division[7], CenterPoint);
             * Face2D f2 = Shape.AddPoints( division[7], division[8], division[9], division[10], division[11], CenterPoint);*/

            Face2D f0 = Shape.AddPoints(division[1], division[2], division[3], division[4], division[5], CenterPoint);
            Face2D f1 = Shape.AddPoints(division[5], division[6], division[7], division[8], division[9], CenterPoint);
            Face2D f2 = Shape.AddPoints(division[9], division[10], division[11], division[0], division[1], CenterPoint);

            f0.Name = Name + "-0";
            f1.Name = Name + "-1";
            f2.Name = Name + "-2";

            Shape.RemoveFace(this);

            DivideTo(f0, f1, f2);
        }
예제 #8
0
        protected Face2D FindLastSecondLowestChild()
        {
            if (!IsRoot)
            {
                return(Root.FindLastSecondLowestChild());
            }

            if (IsLowest)
            {
                return(null);
            }

            //List<Face2D> allSecondLowestChild = new List<Face2D>();

            Face2D result   = this;
            float  minScale = Scale;

            foreach (var child in Childern)
            {
                if (child.IsLowest)
                {
                    continue;
                }
                if (child.IsSecondLowest && child.Scale < minScale)
                {
                    result = child;  minScale = child.Scale;
                }
                Face2D face = child.FindSecondLowestChild();
                if (face != null && face.Scale < minScale)
                {
                    result = face; minScale = face.Scale;
                }
            }

            return(result);
        }
예제 #9
0
 public bool IsMatchFor(Face2D face)
 {
     return(face.BasicEdges.All(e => BasicEdges.Contains(e)));
 }