Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How do i remove from a List dupilcate coordinates ?

$
0
0

This is the code:

private static void RemoveSamePoints()
        {
            List<Point> PointsInt = new List<Point>();
            for (int i = 0; i < extendedPoints.Count; i++)
            {
                PointsInt.Add(new Point(Convert.ToInt32(extendedPoints[i].X), Convert.ToInt32(extendedPoints[i].Y)));
            }
            for (int i = 0; i < PointsInt.Count - 1; i++)
            {
                if (PointsInt[i] == PointsInt[i + 1])
                {
                    PointsInt.Remove(PointsInt[i]);
                }
            }
        }

extendedPoints is a List<PointF> and the format of the List for example is:

Index0: {X = 120 , Y = 130.4545}

Index1: {X = 120 , Y = 130.1111}

Now in the first loop i convert all the coordinates values in the List to int so now in PointsInt i will see:

Index0: {X = 120 , Y = 130}

Index1: {X = 120 , Y = 130}

Index45: {X = 233 , Y = 250}

Ibdex46: {X = 233 , Y = 250}

Now in the second loop i want to remove from the PointsInt List all the coordinates(indexs) that are the same.

For example index 0 and index 1 are the same so remove one of them.

And if for example index 0 1 2 3 4 and 5 are the same remove 4 of them and leave only one of them.

So from each same coordinates leave only one.

So in the end for example the List will look like:

Index0: {X = 120 , Y = 130}

Index1: {X = 222 , Y = 233}

Index2: {X = 250 , Y = 260}

Before the changes there were more from each of them but now only one.

The way i did now the second loop remove some indexs but not giving me the result i wanted still many coordinates are the same.



Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>