base_data.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef __BASE_DATA__
  2. #define __BASE_DATA__
  3. #include <map>
  4. #include <list>
  5. #include <deque>
  6. #include <vector>
  7. #include <cmath>
  8. struct point_2
  9. {
  10. double x_;
  11. double y_;
  12. point_2()
  13. :x_(0x12345678)
  14. ,y_(0x87654321)
  15. {
  16. }
  17. point_2(double x,double y)
  18. :x_(x),y_(y)
  19. {}
  20. void setX(double x)
  21. {
  22. x_ = x;
  23. }
  24. void setY(double y)
  25. {
  26. y_ = y;
  27. }
  28. static inline bool is_valid(const point_2&p)
  29. {
  30. const point_2 &pt=invalid_point();
  31. return pt.x_!=p.x_ || pt.y_!=p.y_;
  32. }
  33. static inline const point_2& invalid_point()
  34. {
  35. static const point_2 pt;
  36. return pt;
  37. }
  38. static inline double sqr(double x)
  39. {
  40. return x*x;
  41. }
  42. double dist_to(double x,double y)
  43. {
  44. return std::sqrt(sqr(x-x_)+sqr(y-y_));
  45. }
  46. double dist_to(const point_2&pt)
  47. {
  48. return dist_to(pt.x_,pt.y_);
  49. }
  50. };
  51. struct st_coord :point_2
  52. {
  53. uint64_t gen_time_;
  54. uint16_t m_ct;//ct
  55. void clear()
  56. {
  57. gen_time_ = 0;
  58. m_ct = 0;
  59. x_ = 0;
  60. y_ = 0;
  61. }
  62. void setTime(uint64_t t)
  63. {
  64. gen_time_ = t;
  65. }
  66. void setCT(uint16_t t)
  67. {
  68. m_ct = t;
  69. }
  70. };
  71. #endif