}}} // namespaces
-// 3: sample implementation of a shift
+// 3: sample implementation of a shift
// to convert coordinate system "cart" to "cart_shirted5"
-template <typename P1, typename P2>
struct shift
{
+ template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2& p2) const
{
namespace bg = boost::geometry;
// 4: register the default strategy to transform any cart point to any cart_shifted5 point
-namespace boost { namespace geometry { namespace strategy { namespace transform { namespace services
+namespace boost { namespace geometry { namespace strategy { namespace transform { namespace services
{
template <typename P1, typename P2>
struct default_strategy<cartesian_tag, cartesian_tag, cart, cart_shifted5, 2, 2, P1, P2>
{
- typedef shift<P1, P2> type;
+ typedef shift type;
};
}}}}} // namespaces
// 5: implement a distance strategy between the two different ones
-template <typename P1, typename P2>
struct shift_and_calc_distance
{
+ template <typename P1, typename P2>
inline double apply(P1 const& p1, P2 const& p2) const
{
P2 p1_shifted;
typedef boost::geometry::model::point<double, 2, cart_shifted5> point2;
// 7: register the distance strategy
-namespace boost { namespace geometry { namespace strategy { namespace distance { namespace services
+namespace boost { namespace geometry { namespace strategy { namespace distance { namespace services
{
- template <typename Point1, typename Point2>
- struct tag<shift_and_calc_distance<Point1, Point2> >
+ template <>
+ struct tag<shift_and_calc_distance>
{
typedef strategy_tag_distance_point_point type;
};
-
- template <typename Point1, typename Point2>
- struct return_type<shift_and_calc_distance<Point1, Point2> >
+
+ template <typename P1, typename P2>
+ struct return_type<shift_and_calc_distance, P1, P2>
{
typedef double type;
};
template <>
struct default_strategy<point_tag, point1, point2, cartesian_tag, cartesian_tag>
{
- typedef shift_and_calc_distance<point1, point2> type;
+ typedef shift_and_calc_distance type;
};
int main()
{
point1 p1_a(0, 0), p1_b(5, 5);
- point2 p2_a(2, 2), p2_b(6, 6);
+ point2 p2_a(2, 2), p2_b(6, 6);
// Distances run for points on the same coordinate system.
// This is possible by default because they are cartesian coordinate systems.
- double d1 = boost::geometry::distance(p1_a, p1_b);
- double d2 = boost::geometry::distance(p2_a, p2_b);
+ double d1 = boost::geometry::distance(p1_a, p1_b);
+ double d2 = boost::geometry::distance(p2_a, p2_b);
std::cout << d1 << " " << d2 << std::endl;
// Transform from a to b:
boost::geometry::model::point<double, 2, cart_shifted5> p1_shifted;
- boost::geometry::transform(p1_a, p1_shifted);
+ boost::geometry::transform(p1_a, p1_shifted);
// Of course this can be calculated now, same CS
- double d3 = boost::geometry::distance(p1_shifted, p2_a);
+ double d3 = boost::geometry::distance(p1_shifted, p2_a);
- // Calculate distance between them. Note that inside distance the
+ // Calculate distance between them. Note that inside distance the
// transformation is called.
- double d4 = boost::geometry::distance(p1_a, p2_a);
+ double d4 = boost::geometry::distance(p1_a, p2_a);
// The result should be the same.
std::cout << d3 << " " << d4 << std::endl;