# Thread: find two match point in a point2dcollection

1. ## find two match point in a point2dcollection

Registered forum members do not see this ad.

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

2. 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.

3. Registered forum members do not see this ad.

Linq may offer a more expedient means by which to perform the desired comparison, but thinking linearly, one could simply iterate the Collection, and compare both the Point2d, and its IndexOf to others within the Collection.

This may also be of use:

Cheers