Point2D.cs 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. namespace CommonUI.Gemo
  3. {
  4. public class Point2D
  5. {
  6. public float x;
  7. public float y;
  8. public Point2D()
  9. {
  10. }
  11. public Point2D(float x, float y)
  12. {
  13. this.x = x;
  14. this.y = y;
  15. }
  16. public float Length
  17. {
  18. get { return Distance(this, new Point2D(0, 0)); }
  19. }
  20. /// <summary>
  21. /// make x y swap
  22. /// </summary>
  23. public void swap()
  24. {
  25. float t = x;
  26. this.x = y;
  27. this.y = t;
  28. }
  29. public void flip()
  30. {
  31. this.x = -x;
  32. this.y = -y;
  33. }
  34. public static float Distance(Point2D p1, Point2D p2)
  35. {
  36. double a = p2.x - p1.x;
  37. double b = p2.y - p1.y;
  38. double rlt = Math.Pow(a, 2) + Math.Pow(b, 2);
  39. rlt = Math.Sqrt(rlt);
  40. return (float)rlt;
  41. }
  42. }
  43. }