コード例 #1
0
ファイル: Surface.cs プロジェクト: dmswart/Personal-Projects
        /// <summary>
        /// compares two triangles A and B
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <returns>-1 if A < B, 0 if A = B, 1 if A > B </returns>
        public static int Compare(Triangle A, Triangle B)
        {
            int tmp;
            int AMin = A.I;
            int AMid = A.J;
            int AMax = A.K;
            if (AMin > AMid) { tmp = AMin; AMin = AMid; AMid = tmp; }
            if (AMid > AMax) { tmp = AMid; AMid = AMax; AMax = tmp; }
            if (AMin > AMid) { tmp = AMin; AMin = AMid; AMid = tmp; }

            int BMin = B.I;
            int BMid = B.J;
            int BMax = B.K;
            if (BMin > BMid) { tmp = BMin; BMin = BMid; BMid = tmp; }
            if (BMid > BMax) { tmp = BMid; BMid = BMax; BMax = tmp; }
            if (BMin > BMid) { tmp = BMin; BMin = BMid; BMid = tmp; }

            if (AMin < BMin)
                return -1;
            else if (AMin > BMin)
                return 1;
            else if (AMid < BMid)
                return -1;
            else if (AMid > BMid)
                return 1;
            else if (AMax < BMax)
                return -1;
            else if (AMax > BMax)
                return 1;
            else
                return 0;
        }
コード例 #2
0
ファイル: Surface.cs プロジェクト: dmswart/Personal-Projects
        public override int AddFace(int i, int j, int k)
        {
            if( mFaces.Count() == 0 )
                return base.AddFace(i, j, k);

            Triangle newT = new Triangle(i,j,k);

            int lo = 0;
            int hi = mFaces.Count() -1;

            // Initial tests.
            int comp = Triangle.Compare( newT, mFaces[hi] );
            if (comp == 0)
            {
                mFaces.RemoveAt(hi);
                return -1;
            }
            else if (comp == 1) //greater than, add to end
            {
                mFaces.Add(newT);
                return hi + 1;
            }
            comp = Triangle.Compare(newT, mFaces[lo]);
            if (comp == 0)
            {
                mFaces.RemoveAt(lo);
                return -1;
            }
            else if (comp == -1)
            {
                mFaces.Insert(lo, newT);
                return lo;
            }

            while (hi - lo > 1)
            {
                int mid = (hi + lo) / 2;
                comp = Triangle.Compare(newT, mFaces[mid]);
                if (comp == -1)
                    hi = mid;
                else if (comp == 1)
                    lo = mid;
                else
                {
                    mFaces.RemoveAt(mid);
                    return -1;
                }
            }

            //didn't find it, insert it at hi
            mFaces.Insert(hi, newT);
            return hi;
        }
コード例 #3
0
ファイル: Surface.cs プロジェクト: dmswart/Personal-Projects
 public int AddFace(int i, int j, int k, Point3D center)
 {
     Triangle newTriangle = new Triangle(i, j, k);
     mFaces.Add(newTriangle);
     Fix(mFaces.Count - 1, center);
     return mFaces.Count - 1;
 }