point_well_formed_traits.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <boost/geometry/core/cs.hpp>
  12. #include "function_requiring_a_point.hpp"
  13. struct point
  14. {
  15. point(): x(), y() {}
  16. float x, y;
  17. };
  18. namespace boost { namespace geometry { namespace traits {
  19. template <>
  20. struct tag<point>
  21. {
  22. typedef point_tag type;
  23. };
  24. template <>
  25. struct coordinate_type<point>
  26. {
  27. typedef float type;
  28. };
  29. template <>
  30. struct coordinate_system<point>
  31. {
  32. typedef bg::cs::cartesian type;
  33. };
  34. template <>
  35. struct dimension<point>
  36. {
  37. enum { value = 2 };
  38. };
  39. template <>
  40. struct access<point, 0>
  41. {
  42. static float get(point const& p)
  43. {
  44. return p.x;
  45. }
  46. static void set(point& p, float value)
  47. {
  48. p.x = value;
  49. }
  50. };
  51. template <>
  52. struct access<point, 1>
  53. {
  54. static float get(point const& p)
  55. {
  56. return p.y;
  57. }
  58. static void set(point& p, float value)
  59. {
  60. p.y = value;
  61. }
  62. };
  63. }}} // namespace bg::traits
  64. int main()
  65. {
  66. point p1;
  67. const point p2;
  68. test::function_requiring_a_point(p1, p2);
  69. return 0;
  70. }