mohsen62sm Posted October 21, 2013 Posted October 21, 2013 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 Quote
RICVBA Posted October 21, 2013 Posted October 21, 2013 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. Quote
BlackBox Posted October 21, 2013 Posted October 21, 2013 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 Quote
Recommended Posts
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.