struct CVertex { CPoint Point; CPoint Delta; bool Moving; }; struct CVertexLine { list::iterator Vertex1, Vertex2; }; void CDragnDropView::CheckConvexity() { VertexLines.clear(); list NewVertices; for (list::iterator iter1 = GetDocument()->Vertices.begin(); iter1 != GetDocument()->Vertices.end(); iter1++) { for (list::iterator iter2 = GetDocument()->Vertices.begin(); iter2 != GetDocument()->Vertices.end(); iter2++) { if (iter1 == iter2) continue; bool FirstPoint = true, IsValidSegment = true; bool FirstSign; for (list::iterator iter3 = GetDocument()->Vertices.begin(); iter3 != GetDocument()->Vertices.end(); iter3++) { if (iter3 == iter1 || iter3 == iter2) continue; float Val; if (iter2->Point.x == iter1->Point.x) Val = (float)(iter3->Point.y-iter1->Point.y)/(float)(iter2->Point.y-iter1->Point.y); else if (iter2->Point.y == iter1->Point.y) Val = (float)(iter3->Point.x-iter1->Point.x)/(float)(iter2->Point.x-iter1->Point.x); else Val = (float)(iter3->Point.x-iter1->Point.x)/(float)(iter2->Point.x-iter1->Point.x) - (float)(iter3->Point.y-iter1->Point.y)/(float)(iter2->Point.y-iter1->Point.y); if (Val == 0) continue; if (FirstPoint) { FirstPoint = false; FirstSign = Val > 0; } else { if ((Val > 0) != FirstSign) { IsValidSegment = false; break; } } } if (IsValidSegment) { bool Contains = false; for (list::iterator iter4 = NewVertices.begin(); iter4 != NewVertices.end(); iter4++) if (iter4->Point == iter1->Point) { Contains = true; break; } if (!Contains) NewVertices.push_back(*iter1); Contains = false; for (list::iterator iter5 = NewVertices.begin(); iter5 != NewVertices.end(); iter5++) if (iter5->Point == iter2->Point) { Contains = true; break; } if (!Contains) NewVertices.push_back(*iter2); Contains = false; for (list::iterator iter6 = VertexLines.begin(); iter6 != VertexLines.end(); iter6++) { if ((iter6->Vertex1->Point == iter1->Point && iter6->Vertex2->Point == iter2->Point) || (iter6->Vertex1->Point == iter2->Point && iter6->Vertex2->Point == iter1->Point)) { Contains = true; break; } } /*if (!Contains) { CVertexLine vl; vl.Vertex1 = iter1; vl.Vertex2 = iter2; VertexLines.push_back(vl); }*/ } } } GetDocument()->Vertices.clear(); GetDocument()->Vertices = NewVertices; }