# find two match point in a point2dcollection

## Recommended Posts

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

{

for (int nCnt2 = 0; 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

##### Share on other sites

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

{

for (int nCnt2 = 0; 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

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.

##### Share on other sites

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

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.