public void Analyze() { //we analyze each triangle here int j = _triangles.Count; bones = new List <GlyphBone>(); List <GlyphTriangle> usedTriList = new List <GlyphTriangle>(); for (int i = 0; i < j; ++i) { GlyphTriangle tri = _triangles[i]; if (i > 0) { //check the new tri is connected with latest tri or not? int foundIndex = FindLatestConnectedTri(usedTriList, tri); if (foundIndex > -1) { usedTriList.Add(tri); bones.Add(new GlyphBone(usedTriList[foundIndex], tri)); } else { //not found //? } } else { usedTriList.Add(tri); } } if (j > 1) { //connect the last tri to the first tri //if it is connected GlyphTriangle firstTri = _triangles[0]; GlyphTriangle lastTri = _triangles[j - 1]; if (firstTri.IsConnectedWith(lastTri)) { bones.Add(new GlyphBone(lastTri, firstTri)); } } //---------------------------------------- int boneCount = bones.Count; for (int i = 0; i < boneCount; ++i) { //each bone has 2 triangles at its ends //we analyze both triangles' roles //eg... //left -right //top-bottom GlyphBone bone = bones[i]; bone.Analyze(); } //---------------------------------------- }
int FindLatestConnectedTri(List <GlyphTriangle> usedTriList, GlyphTriangle tri) { //search back *** for (int i = usedTriList.Count - 1; i >= 0; --i) { GlyphTriangle t = usedTriList[i]; if (t.IsConnectedWith(tri)) { return(i); } } return(-1); }