Point2D.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. namespace FuzzyLogicPCL
  3. {
  4. /// <summary>
  5. /// Simple utility class to create, manipulate and sort 2D points
  6. /// </summary>
  7. public class Point2D : IComparable
  8. {
  9. /// <summary>
  10. /// X coordinate
  11. /// </summary>
  12. public double X { get; set; }
  13. /// <summary>
  14. /// Y coordinate
  15. /// </summary>
  16. public double Y { get; set; }
  17. /// <summary>
  18. /// Constructor
  19. /// </summary>
  20. /// <param name="x">x coordinate</param>
  21. /// <param name="y">y coordinate</param>
  22. public Point2D(double x, double y)
  23. {
  24. this.X = x;
  25. this.Y = y;
  26. }
  27. /// <summary>
  28. /// Comparison method, for the IComparable interface. The order axis used is only the x-axis.
  29. /// </summary>
  30. /// <param name="obj">The other point</param>
  31. /// <returns>0 if equals, negative if smaller, postive if bigger</returns>
  32. public int CompareTo(object obj)
  33. {
  34. return (int)(this.X - ((Point2D) obj).X);
  35. }
  36. /// <summary>
  37. /// Conversion to string
  38. /// </summary>
  39. /// <returns>Coordinates in format : (x;y)</returns>
  40. public override String ToString()
  41. {
  42. return "(" + this.X + ";" + this.Y + ")";
  43. }
  44. }
  45. }