TPoint2D.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace CommonUI.Gemo
  6. {
  7. public struct TPoint2D
  8. {
  9. public float X;
  10. public float Y;
  11. public TPoint2D(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 TPoint2D(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(TPoint2D p1, TPoint2D 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. private readonly static TPoint2D c_Zero = new TPoint2D();
  43. public static TPoint2D Zero
  44. {
  45. get
  46. {
  47. return c_Zero;
  48. }
  49. }
  50. }
  51. }