title: writing a custom comparer for linq groupby
body: <p>Again this sample is a very simplified version of my actual problem involving a custom comparer for linq grouping. What have I done wrong?</p>
  
  <p>The code below produces the result below
  (1.2, 0),
  (4.1, 0), (4.1, 0),
  (1.1, 0),</p>
  
  <p>however I was expecting the following since 1.1 and 1.2 are &lt; 1.0 apart.
  (1.2, 0), (1.1, 0),
  (4.1, 0), (4.1, 0),</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          IEnumerable&lt;Point&gt; points = new List&lt;Point&gt; { 
              new Point(1.1, 0.0)
              , new Point(4.1, 0.0) 
              , new Point(1.2, 0.0)
              , new Point(4.1, 0.0)
          };
  
          foreach (var group in points.GroupBy(p =&gt; p, new PointComparer()))
          {
              foreach (var num in group)
                  Console.Write(num.ToString() + ", ");
  
              Console.WriteLine();
          }
  
          Console.ReadLine();
      }
  }
  
  class PointComparer : IEqualityComparer&lt;Point&gt;
  {
      public bool Equals(Point a, Point b)
      {
          return Math.Abs(a.X - b.X) &lt; 1.0;
      }
  
      public int GetHashCode(Point point)
      {
          return point.X.GetHashCode()
              ^ point.Y.GetHashCode();
      }
  }
  
  class Point
  {
      public double X;
      public double Y;
  
      public Point(double p1, double p2)
      {
          X = p1;
          Y = p2;
      }
  
      public override string ToString()
      {
          return "(" + X + ", " + Y + ")";
      }
  }
  </code></pre>