Results 1 to 14 of 14

Thread: Idea how to solve one problem

Threaded View

  1. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Idea how to solve one problem

    Well , what can I say sorry for misunderstanding

    I already started writing the code , but I have one little glitch and I post it here if someone is able to help me.
    So I am trying to sort with my custom function List<Point>:
    Code:
      public class PointSort : IComparer
            {
                public enum Mode
                {
                    sinus,
                    cos
                }
    
                Mode currentMode = Mode.sinus;
    
                public PointSort(Mode mode)
                {
                    currentMode = mode;
                }
    
            
                int IComparer.Compare(object a, object b)
                {
                    Point one = (Point)a;
                    Point two = (Point)b;
                    if ((one.x - sx) / (Math.Sqrt(Math.Pow(one.x - sx, 2) + Math.Pow(one.y - sy, 2))) > (two.x - sx) / (Math.Sqrt(Math.Pow(two.x - sx, 2) + Math.Pow(two.y - sy, 2))))
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
    
                }
            }
    and then I just use this in order to sort:
    Code:
     Array.Sort(masiv, new PointSort(PointSort.Mode.sinus));
    and the error is:

    Where masiv is List<Point> and here my struct for Point:
    Code:
     public struct Point
            {
                public int x, y;
    
                public Point(int p1, int p2)
                {
                    x = p1;
                    y = p2;
                }
            }
    Last edited by mitko29; Mar 30th, 2012 at 04:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width