
Originally Posted by
mohsen62sm
Hello,
How we cad find two match point in a point2dcollection?
The following code does not work correctly.
Point2dCollection colPt = new Point2dCollection();
string sDoubleVertex ="";
for (int nCnt1 = 0; nCnt1 < (colPt.Count / 2); nCnt1++)
{
for (int nCnt2 = 0; nCnt2 < colPt.Count; nCnt2++)
{
// Step to the next iteration.
if (nCnt1 == nCnt2) continue;
if ((colPt[nCnt1].X.ToString() == colPt[nCnt2].X.ToString()) &&
(colPt[nCnt2].Y.ToString() == colPt[nCnt2].Y.ToString()))
{
sDoubleVertex = nCnt2.ToString() + "," + sDoubleVertex;
}
}
}
Thank you,
Mohsen
I use VBA so that I'm only guessing what your problem could be like.
Maybe it derives from the use of comparison between string values rather than between double ones.
And yet in my experience even using double values comparison I always found myself forced to round numbers in order to have the match I knew there should be for my needs.
For instance in VBA I use expressions like
Code:
if (Round(minExt(0), 5) = Round(maxExt(0), 5)) and (Round(minExt(1), 5) = Round(maxExt(1), 5)) then
thus declaring I'm satisfied for match up to 5 digits after the comma.
You could ask for a more precise matching, but first check the inner precision that every numeric variable type hase so as not to seek for an impossible match.
Bookmarks