1

I'm a newbie and I'm asking for patience if you find this question stupid. But I really need help to sort this out. I have a list of lines with startpoint and endpoint, but I need to eliminate one if a startpoint and endpoint is the same with the endpoint and startpoint of others. Thank you for those who will answer this question. This site has been a great help to me.

 private void sample()
    {
        SampleLine sl = new SampleLine();
        List<SampleLine> listLines = new List<SampleLine>();
        listLines.Add(new SampleLine { StartPoint = new Point(0, 250), EndPoint = new Point(150, 100)});    //[0]
        listLines.Add(new SampleLine { StartPoint = new Point(100, 350), EndPoint = new Point(250, 200) }); //[1]
        listLines.Add(new SampleLine { StartPoint = new Point(200, 500), EndPoint = new Point(350, 650) }); //[2]
        listLines.Add(new SampleLine { StartPoint = new Point(300, 550), EndPoint = new Point(450, 400) }); //[3]
        listLines.Add(new SampleLine { StartPoint = new Point(350, 650), EndPoint = new Point(200, 500) }); //[4]
        listLines.Add(new SampleLine { StartPoint = new Point(500, 750), EndPoint = new Point(650, 600) }); //[5]


        //From Above, index 2 and index 4 should be treated as the same and index 4 be deleted in the list
        /*
        listLines.Add(new SampleLine { StartPoint = new Point(200, 500), EndPoint = new Point(350, 650) }); //[2]
        listLines.Add(new SampleLine { StartPoint = new Point(350, 650), EndPoint = new Point(200, 500) }); //[4] startpoint[4] is equal to endpoint[2] and endpoint[4] is equal to startpoint[2]
        //index [4] should be deleted since it is cross equal with index[2]
        */
    }
Oscar
  • 9
  • 3
  • Start 2 nested iterators and check for your condition. If matched, use remove function somewhat like https://stackoverflow.com/questions/17279519/removing-items-from-list-in-java – Pushan Gupta Jun 09 '17 at 05:45
  • It is a very ugly O(n!) problem, it quickly becomes unsolvable for modest values of n. Really rather best to not have to solve it and just let the lines overdraw each other. That tends to mean you can't use anti-aliasing. – Hans Passant Sep 28 '17 at 07:36

0 Answers0