1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3 
4 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
7 
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
14 
15 #include <iostream>
16 #include <sstream>
17 
18 #include <geometry_test_common.hpp>
19 
20 #include <boost/geometry/algorithms/transform.hpp>
21 #include <boost/geometry/strategies/strategies.hpp>
22 #include <boost/geometry/geometries/geometries.hpp>
23 #include <boost/geometry/geometries/point_xy.hpp>
24 
25 #include <boost/geometry/io/wkt/wkt.hpp>
26 
27 
28 // This test is a little different from transform.cpp test.
29 // This test explicitly tests all geometries, including multi*
30 // while the transform.cpp tests various strategies.
31 
32 template <typename Geometry>
test_transform(std::string const & wkt,std::string const & expected)33 void test_transform(std::string const& wkt, std::string const& expected)
34 {
35     typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
36     const std::size_t dim = bg::dimension<Geometry>::value;
37 
38     Geometry geometry_in, geometry_out;
39     bg::read_wkt(wkt, geometry_in);
40     bg::transform(geometry_in, geometry_out,
41         bg::strategy::transform::scale_transformer<coordinate_type, dim, dim>(2, 2));
42     std::ostringstream detected;
43     detected << bg::wkt(geometry_out);
44     BOOST_CHECK_EQUAL(detected.str(), expected);
45 }
46 
47 
48 template <typename T>
test_all()49 void test_all()
50 {
51     typedef bg::model::d2::point_xy<T> P;
52 
53     test_transform<P>(
54             "POINT(1 1)",
55             "POINT(2 2)");
56     test_transform<bg::model::linestring<P> >(
57             "LINESTRING(1 1,2 2)",
58             "LINESTRING(2 2,4 4)");
59     test_transform<bg::model::segment<P> >(
60             "LINESTRING(1 1,2 2)",
61             "LINESTRING(2 2,4 4)");
62     test_transform<bg::model::ring<P> >(
63             "POLYGON((0 0,0 1,1 0,0 0))",
64             "POLYGON((0 0,0 2,2 0,0 0))");
65     test_transform<bg::model::polygon<P> >(
66             "POLYGON((0 0,0 1,1 0,0 0))",
67             "POLYGON((0 0,0 2,2 0,0 0))");
68     test_transform<bg::model::box<P> >(
69             "POLYGON((0 0,0 1,1 1,1 0,0 0))",
70             "POLYGON((0 0,0 2,2 2,2 0,0 0))");
71     test_transform<bg::model::multi_point<P> >(
72             "MULTIPOINT((1 1),(2 2))",
73             "MULTIPOINT((2 2),(4 4))");
74     test_transform<bg::model::multi_linestring<bg::model::linestring<P> > >(
75             "MULTILINESTRING((1 1,2 2))",
76             "MULTILINESTRING((2 2,4 4))");
77     test_transform<bg::model::multi_polygon<bg::model::polygon<P> > >(
78             "MULTIPOLYGON(((0 0,0 1,1 0,0 0)))",
79             "MULTIPOLYGON(((0 0,0 2,2 0,0 0)))");
80 }
81 
82 
test_main(int,char * [])83 int test_main(int, char* [])
84 {
85     test_all<double>();
86 
87     return 0;
88 }
89