Jump to content
mohsen62sm

find two match point in a point2dcollection

Recommended Posts

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

{

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 this post


Link to post
Share on other sites
RICVBA
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 this post


Link to post
Share on other sites
BlackBox

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:

 

http://through-the-interface.typepad.com/through_the_interface/2011/01/sorting-an-autocad-point2dcollection-or-point3dcollection-using-net.html

 

Cheers

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...