diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/geometry/test/io | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/geometry/test/io')
-rw-r--r-- | src/boost/libs/geometry/test/io/Jamfile.v2 | 17 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/dsv/Jamfile.v2 | 16 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/dsv/dsv_multi.cpp | 99 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/svg/Jamfile.v2 | 15 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/svg/svg.cpp | 157 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/wkt/Jamfile.v2 | 17 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/wkt/wkt.cpp | 299 | ||||
-rw-r--r-- | src/boost/libs/geometry/test/io/wkt/wkt_multi.cpp | 126 |
8 files changed, 746 insertions, 0 deletions
diff --git a/src/boost/libs/geometry/test/io/Jamfile.v2 b/src/boost/libs/geometry/test/io/Jamfile.v2 new file mode 100644 index 00000000..28fbba1a --- /dev/null +++ b/src/boost/libs/geometry/test/io/Jamfile.v2 @@ -0,0 +1,17 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +# +# This file was modified by Oracle on 2016. +# Modifications copyright (c) 2016 Oracle and/or its affiliates. +# +# Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle +# +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +build-project wkt ; +build-project svg ; diff --git a/src/boost/libs/geometry/test/io/dsv/Jamfile.v2 b/src/boost/libs/geometry/test/io/dsv/Jamfile.v2 new file mode 100644 index 00000000..eaebe1c7 --- /dev/null +++ b/src/boost/libs/geometry/test/io/dsv/Jamfile.v2 @@ -0,0 +1,16 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +# Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland. +# +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +test-suite boost-geometry-io-dsv + : + [ run dsv_multi.cpp : : : : dsv_multi ] + ; + diff --git a/src/boost/libs/geometry/test/io/dsv/dsv_multi.cpp b/src/boost/libs/geometry/test/io/dsv/dsv_multi.cpp new file mode 100644 index 00000000..0b4bd8f2 --- /dev/null +++ b/src/boost/libs/geometry/test/io/dsv/dsv_multi.cpp @@ -0,0 +1,99 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2015 Mateusz Loskot, London, UK. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + + +#include <sstream> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/io/dsv/write.hpp> +#include <boost/geometry/io/wkt/read.hpp> + +template <typename Geometry> +void test_dsv(std::string const& wkt, std::string const& expected, bool json = false) +{ + Geometry geometry; + bg::read_wkt(wkt, geometry); + std::ostringstream out; + if (json) + { + out << bg::dsv(geometry, ", ", "[", "]", ", ", "[ ", " ]", ", "); + } + else + { + out << bg::dsv(geometry); + } + BOOST_CHECK_EQUAL(out.str(), expected); +} + + +template <typename T> +void test_all() +{ + using namespace boost::geometry; + typedef model::point<T, 2, cs::cartesian> point_type; + typedef model::multi_point<point_type> mpoint; + typedef model::multi_linestring<model::linestring<point_type> > mline; + typedef model::multi_polygon<model::polygon<point_type> > mpoly; + + test_dsv<mpoint> + ( + "multipoint((1 2),(3 4))", + "((1, 2), (3, 4))" + ); + test_dsv<mline> + ( + "multilinestring((1 1,2 2,3 3),(4 4,5 5,6 6))", + "(((1, 1), (2, 2), (3, 3)), ((4, 4), (5, 5), (6, 6)))" + ); + test_dsv<mpoly> + ( + // Multi with 2 poly's, first has hole, second is triangle + "multipolygon(((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((5 5,6 5,5 6,5 5)))", + "((((0, 0), (0, 4), (4, 4), (4, 0), (0, 0)), ((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))), (((5, 5), (6, 5), (5, 6), (5, 5))))" + ); + + // http://geojson.org/geojson-spec.html#id5 + test_dsv<mpoint> + ( + "multipoint((1 2),(3 4))", + "[ [1, 2], [3, 4] ]", + true + ); + + // http://geojson.org/geojson-spec.html#id6 + test_dsv<mline> + ( + "multilinestring((1 1,2 2,3 3),(4 4,5 5,6 6))", + "[ [ [1, 1], [2, 2], [3, 3] ], [ [4, 4], [5, 5], [6, 6] ] ]", + true + ); + + // http://geojson.org/geojson-spec.html#id7 + test_dsv<mpoly> + ( + "multipolygon(((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((5 5,6 5,5 6,5 5)))", + "[ [ [ [0, 0], [0, 4], [4, 4], [4, 0], [0, 0] ], [ [1, 1], [1, 2], [2, 2], [2, 1], [1, 1] ] ], [ [ [5, 5], [6, 5], [5, 6], [5, 5] ] ] ]", + true + ); + +} + + +int test_main(int, char* []) +{ + test_all<double>(); + test_all<int>(); + + return 0; +} + diff --git a/src/boost/libs/geometry/test/io/svg/Jamfile.v2 b/src/boost/libs/geometry/test/io/svg/Jamfile.v2 new file mode 100644 index 00000000..ed406ffd --- /dev/null +++ b/src/boost/libs/geometry/test/io/svg/Jamfile.v2 @@ -0,0 +1,15 @@ +# Boost.Geometry +# +# Copyright (c) 2016 Oracle and/or its affiliates. +# +# Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle +# +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +test-suite boost-geometry-io-svg + : + [ run svg.cpp : : : : io_svg ] + ; + diff --git a/src/boost/libs/geometry/test/io/svg/svg.cpp b/src/boost/libs/geometry/test/io/svg/svg.cpp new file mode 100644 index 00000000..10e8b4fe --- /dev/null +++ b/src/boost/libs/geometry/test/io/svg/svg.cpp @@ -0,0 +1,157 @@ +// Boost.Geometry +// Unit Test + +// Copyright (c) 2016-2017 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifdef TEST_WITH_SVG +#include <fstream> +#endif + +#include <sstream> +#include <string> + +#include <boost/variant.hpp> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/algorithms/area.hpp> +#include <boost/geometry/algorithms/correct.hpp> + +#include <boost/geometry/geometries/geometries.hpp> +#include <boost/geometry/geometries/point_xy.hpp> + +#include <boost/geometry/io/svg/svg_mapper.hpp> +#include <boost/geometry/io/svg/write.hpp> + +#include <boost/geometry/strategies/strategies.hpp> + + +template <typename R, typename T> +inline void push_back_square(R & rng, T const& mi, T const& ma) +{ + typedef typename bg::point_type<R>::type P; + rng.push_back(P(mi, mi)); + rng.push_back(P(mi, ma)); + rng.push_back(P(ma, ma)); + rng.push_back(P(ma, mi)); + rng.push_back(P(mi, mi)); +} + +template <typename P> +void test_all() +{ + typedef bg::model::box<P> box; + typedef bg::model::segment<P> segment; + typedef bg::model::linestring<P> linestring; + typedef bg::model::ring<P> ring; + typedef bg::model::polygon<P> polygon; + + typedef bg::model::multi_point<P> multi_point; + typedef bg::model::multi_linestring<linestring> multi_linestring; + typedef bg::model::multi_polygon<polygon> multi_polygon; + + P pt(0, 0); + box b(P(10, 10), P(20, 20)); + segment s(P(30, 30), P(40, 40)); + + linestring ls; + push_back_square(ls, 50, 60); + + ring r; + push_back_square(r, 70, 80); + + polygon po; + push_back_square(po.outer(), 90, 120); + po.inners().resize(1); + push_back_square(po.inners()[0], 100, 110); + bg::correct(po); + + multi_point m_pt; + m_pt.push_back(pt); + + multi_linestring m_ls; + m_ls.push_back(ls); + + multi_polygon m_po; + m_po.push_back(po); + + boost::variant<P, linestring, polygon> var; + linestring lsv; + push_back_square(lsv, 130, 140); + var = lsv; + + std::string style = "fill-opacity:0.5;fill:rgb(200,0,0);stroke:rgb(200,0,0);stroke-width:3"; + std::string m_style = "fill-opacity:0.5;fill:rgb(0,200,0);stroke:rgb(0,200,0);stroke-width:1"; + + { +#ifdef TEST_WITH_SVG + std::ofstream os("test1.svg", std::ios::trunc); +#else + std::stringstream os; +#endif + os << "<?xml version=\"1.0\" standalone=\"no\"?>" + << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" + << "<svg height=\"200\" width=\"200\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">"; + + os << bg::svg(pt, style); + os << bg::svg(b, style); + os << bg::svg(s, style); + os << bg::svg(ls, style); + os << bg::svg(r, style); + os << bg::svg(po, style); + os << bg::svg(m_pt, m_style); + os << bg::svg(m_ls, m_style); + os << bg::svg(m_po, m_style); + os << bg::svg(var, style); + + os << "</svg>"; + } + + { +#ifdef TEST_WITH_SVG + std::ofstream os("test2.svg", std::ios::trunc); +#else + std::stringstream os; +#endif + bg::svg_mapper<P> mapper(os, 500, 500); + mapper.add(pt); + mapper.add(b); + mapper.add(s); + mapper.add(ls); + mapper.add(r); + mapper.add(po); + mapper.add(m_pt); + mapper.add(m_ls); + mapper.add(m_po); + mapper.add(var); + + mapper.map(pt, style); + mapper.map(b, style); + mapper.map(s, style); + mapper.map(ls, style); + mapper.map(r, style); + mapper.map(po, style); + mapper.map(m_pt, m_style); + mapper.map(m_ls, m_style); + mapper.map(m_po, m_style); + mapper.map(var, m_style); + } +} + +int test_main(int, char* []) +{ + test_all< boost::geometry::model::d2::point_xy<double> >(); + test_all< boost::geometry::model::d2::point_xy<int> >(); + +#if defined(HAVE_TTMATH) + test_all< boost::geometry::model::d2::point_xy<ttmath_big> >(); +#endif + + return 0; +} diff --git a/src/boost/libs/geometry/test/io/wkt/Jamfile.v2 b/src/boost/libs/geometry/test/io/wkt/Jamfile.v2 new file mode 100644 index 00000000..898e8e94 --- /dev/null +++ b/src/boost/libs/geometry/test/io/wkt/Jamfile.v2 @@ -0,0 +1,17 @@ +# Boost.Geometry (aka GGL, Generic Geometry Library) +# +# Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +# Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +# Copyright (c) 2009-2015 Mateusz Loskot, London, UK. +# Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland. +# +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +test-suite boost-geometry-io-wkt + : + [ run wkt.cpp : : : : io_wkt ] + [ run wkt_multi.cpp : : : : io_wkt_multi ] + ; + diff --git a/src/boost/libs/geometry/test/io/wkt/wkt.cpp b/src/boost/libs/geometry/test/io/wkt/wkt.cpp new file mode 100644 index 00000000..2955fbba --- /dev/null +++ b/src/boost/libs/geometry/test/io/wkt/wkt.cpp @@ -0,0 +1,299 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. + +// This file was modified by Oracle on 2014. +// Modifications copyright (c) 2014 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include <sstream> +#include <string> + +#include <boost/algorithm/string.hpp> + +#include <geometry_test_common.hpp> + +#include <boost/geometry/geometries/geometries.hpp> + +#include <boost/geometry/algorithms/area.hpp> +#include <boost/geometry/algorithms/length.hpp> +#include <boost/geometry/algorithms/num_points.hpp> +#include <boost/geometry/algorithms/perimeter.hpp> +#include <boost/geometry/strategies/strategies.hpp> +#include <boost/geometry/core/point_type.hpp> +#include <boost/geometry/core/topological_dimension.hpp> +#include <boost/geometry/io/wkt/read.hpp> +#include <boost/geometry/io/wkt/write.hpp> +#include <boost/variant/variant.hpp> + +template <typename G> +void check_wkt(G const& geometry, std::string const& expected) +{ + std::ostringstream out; + out << bg::wkt(geometry); + BOOST_CHECK_EQUAL(boost::to_upper_copy(out.str()), + boost::to_upper_copy(expected)); +} + +template <typename G> +void test_wkt(std::string const& wkt, std::string const& expected, + std::size_t n, double len = 0, double ar = 0, double peri = 0) +{ + G geometry; + + bg::read_wkt(wkt, geometry); + + /* + std::cout << "n=" << bg::num_points(geometry) + << " dim=" << bg::topological_dimension<G>::value + << " length=" << bg::length(geometry) + << " area=" << bg::area(geometry) + << " perimeter=" << bg::perimeter(geometry) + << std::endl << "\t\tgeometry=" << dsv(geometry) + << std::endl; + */ + + BOOST_CHECK_EQUAL(bg::num_points(geometry), n); + if (n > 0) + { + BOOST_CHECK_CLOSE(double(bg::length(geometry)), len, 0.0001); + BOOST_CHECK_CLOSE(double(bg::area(geometry)), ar, 0.0001); + BOOST_CHECK_CLOSE(double(bg::perimeter(geometry)), peri, 0.0001); + } + + check_wkt(geometry, expected); + check_wkt(boost::variant<G>(geometry), expected); +} + +template <typename G> +void test_wkt(std::string const& wkt, + std::size_t n, double len = 0, double ar = 0, double peri = 0) +{ + test_wkt<G>(wkt, wkt, n, len, ar, peri); +} + +template <typename G> +void test_relaxed_wkt(std::string const& wkt, std::string const& expected) +{ + std::string e; + G geometry; + bg::read_wkt(wkt, geometry); + std::ostringstream out; + out << bg::wkt(geometry); + + BOOST_CHECK_EQUAL(boost::to_upper_copy(out.str()), boost::to_upper_copy(expected)); +} + + + + +template <typename G> +void test_wrong_wkt(std::string const& wkt, std::string const& start) +{ + std::string e("no exception"); + G geometry; + try + { + bg::read_wkt(wkt, geometry); + } + catch(bg::read_wkt_exception const& ex) + { + e = ex.what(); + boost::to_lower(e); + } + catch(...) + { + e = "other exception"; + } + + bool check = true; + +#if defined(HAVE_TTMATH) + // For ttmath we skip bad lexical casts + typedef typename bg::coordinate_type<G>::type ct; + + if (boost::is_same<ct, ttmath_big>::type::value + && boost::starts_with(start, "bad lexical cast")) + { + check = false; + } +#endif + + if (check) + { + BOOST_CHECK_MESSAGE(boost::starts_with(e, start), " Expected:" + << start << " Got:" << e << " with WKT: " << wkt); + } +} + +template <typename G> +void test_wkt_output_iterator(std::string const& wkt) +{ + G geometry; + bg::read_wkt<G>(wkt, std::back_inserter(geometry)); +} + + + +#ifndef GEOMETRY_TEST_MULTI +template <typename T> +void test_order_closure() +{ + using namespace boost::geometry; + typedef bg::model::point<T, 2, bg::cs::cartesian> Pt; + typedef bg::model::polygon<Pt, true, true> PCWC; + typedef bg::model::polygon<Pt, true, false> PCWO; + typedef bg::model::polygon<Pt, false, true> PCCWC; + typedef bg::model::polygon<Pt, false, false> PCCWO; + + { + std::string wkt_cwc = "POLYGON((0 0,0 2,2 2,2 0,0 0))"; + std::string wkt_cwo = "POLYGON((0 0,0 2,2 2,2 0))"; + std::string wkt_ccwc = "POLYGON((0 0,2 0,2 2,0 2,0 0))"; + std::string wkt_ccwo = "POLYGON((0 0,2 0,2 2,0 2))"; + + test_wkt<PCWC>(wkt_cwc, 5, 0, 4, 8); + test_wkt<PCWO>(wkt_cwc, 4, 0, 4, 8); + test_wkt<PCWO>(wkt_cwo, wkt_cwc, 4, 0, 4, 8); + test_wkt<PCCWC>(wkt_ccwc, 5, 0, 4, 8); + test_wkt<PCCWO>(wkt_ccwc, 4, 0, 4, 8); + test_wkt<PCCWO>(wkt_ccwo, wkt_ccwc, 4, 0, 4, 8); + } + { + std::string wkt_cwc = "POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 1,2 2,1 2,1 1))"; + std::string wkt_cwo = "POLYGON((0 0,0 3,3 3,3 0),(1 1,2 1,2 2,1 2))"; + std::string wkt_ccwc = "POLYGON((0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1))"; + std::string wkt_ccwo = "POLYGON((0 0,3 0,3 3,0 3),(1 1,1 2,2 2,2 1,1 1))"; + + test_wkt<PCWC>(wkt_cwc, 10, 0, 8, 16); + test_wkt<PCWO>(wkt_cwc, 8, 0, 8, 16); + test_wkt<PCWO>(wkt_cwo, wkt_cwc, 8, 0, 8, 16); + test_wkt<PCCWC>(wkt_ccwc, 10, 0, 8, 16); + test_wkt<PCCWO>(wkt_ccwc, 8, 0, 8, 16); + test_wkt<PCCWO>(wkt_ccwo, wkt_ccwc, 8, 0, 8, 16); + } +} + +template <typename T> +void test_all() +{ + using namespace boost::geometry; + typedef bg::model::point<T, 2, bg::cs::cartesian> P; + + test_wkt<P>("POINT(1 2)", 1); + test_wkt<bg::model::linestring<P> >("LINESTRING(1 1,2 2,3 3)", 3, 2 * sqrt(2.0)); + test_wkt<bg::model::polygon<P> >("POLYGON((0 0,0 4,4 4,4 0,0 0)" + ",(1 1,1 2,2 2,2 1,1 1),(1 1,1 2,2 2,2 1,1 1))", 15, 0, 18, 24); + + // Non OGC: a box defined by a polygon + //test_wkt<box<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 4, 0, 1, 4); + test_wkt<bg::model::ring<P> >("POLYGON((0 0,0 1,1 1,1 0,0 0))", 5, 0, 1, 4); + + // We accept empty sequences as well (much better than EMPTY)... + // ...or even POINT() (see below) + test_wkt<bg::model::linestring<P> >("LINESTRING()", 0, 0); + test_wkt<bg::model::polygon<P> >("POLYGON(())", 0); + // ... or even with empty holes + test_wkt<bg::model::polygon<P> >("POLYGON((),(),())", 0); + // which all make no valid geometries, but they can exist. + + // These WKT's are incomplete or abnormal but they are considered OK + test_relaxed_wkt<P>("POINT(1)", "POINT(1 0)"); + test_relaxed_wkt<P>("POINT()", "POINT(0 0)"); + test_relaxed_wkt<bg::model::linestring<P> >("LINESTRING(1,2,3)", + "LINESTRING(1 0,2 0,3 0)"); + test_relaxed_wkt<P>("POINT ( 1 2) ", "POINT(1 2)"); + test_relaxed_wkt<P>("POINT M ( 1 2)", "POINT(1 2)"); + test_relaxed_wkt<bg::model::box<P> >("BOX(1 1,2 2)", "POLYGON((1 1,1 2,2 2,2 1,1 1))"); + + test_relaxed_wkt<bg::model::linestring<P> >("LINESTRING EMPTY", "LINESTRING()"); + + test_relaxed_wkt<bg::model::polygon<P> >("POLYGON( ( ) , ( ) , ( ) )", + "POLYGON((),(),())"); + + // Wrong WKT's + test_wrong_wkt<P>("POINT(1 2", "expected ')'"); + test_wrong_wkt<P>("POINT 1 2)", "expected '('"); + test_wrong_wkt<P>("POINT(1 2,)", "expected ')'"); + test_wrong_wkt<P>("POINT(1 2)foo", "too many tokens at 'foo'"); + test_wrong_wkt<P>("POINT(1 2 3)", "expected ')'"); + test_wrong_wkt<P>("POINT(a 2 3)", "bad lexical cast"); + test_wrong_wkt<P>("POINT 2 3", "expected '('"); + test_wrong_wkt<P>("POINT Z (1 2 3)", "z only allowed"); + + test_wrong_wkt<P>("PIONT (1 2)", "should start with 'point'"); + + test_wrong_wkt<bg::model::linestring<P> >("LINESTRING())", "too many tokens"); + + test_wrong_wkt<bg::model::polygon<P> >("POLYGON((1 1,1 4,4 4,4 1,1 1)" + ",((2 2,2 3,3 3,3 2,2 2))", "bad lexical cast"); + + test_wrong_wkt<bg::model::box<P> >("BOX(1 1,2 2,3 3)", "box should have 2"); + test_wrong_wkt<bg::model::box<P> >("BOX(1 1,2 2) )", "too many tokens"); + + if ( BOOST_GEOMETRY_CONDITION(boost::is_floating_point<T>::type::value + || ! boost::is_fundamental<T>::type::value ) ) + { + test_wkt<P>("POINT(1.1 2.1)", 1); + } + + // Deprecated: + // test_wkt_output_iterator<bg::model::linestring<P> >("LINESTRING(1 1,2 2,3 3)"); + // test_wkt_output_iterator<bg::model::ring<P> >("POLYGON((1 1,2 2,3 3))"); + + test_order_closure<T>(); +} +#endif + +int test_main(int, char* []) +{ + test_all<double>(); + test_all<int>(); + +#if defined(HAVE_TTMATH) + test_all<ttmath_big>(); +#endif + + return 0; +} + +/* + +Results can be checked in PostGIS by query below, +or by MySQL (but replace length by glength and remove the perimeter) + +Note: +- PostGIS gives "3" for a numpoints of a multi-linestring of 6 points in total (!) + --> "npoints" should be taken for all geometries +- SQL Server 2008 gives "6" + select geometry::STGeomFromText('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))',0).STNumPoints() +- MySQL gives "NULL" + +select 1 as code,'np p' as header,npoints(geomfromtext('POINT(1 2)')) as contents +union select 2,'length point', length(geomfromtext('POINT(1 2)')) +union select 3,'peri point', perimeter(geomfromtext('POINT(1 2)')) +union select 4,'area point',area(geomfromtext('POINT(1 2)')) + + +union select 5,'# ls',npoints(geomfromtext('LINESTRING(1 1,2 2,3 3)')) +union select 6,'length ls',length(geomfromtext('LINESTRING(1 1,2 2,3 3)')) +union select 7,'peri ls',perimeter(geomfromtext('LINESTRING(1 1,2 2,3 3)')) +union select 8,'aera ls',area(geomfromtext('LINESTRING(1 1,2 2,3 3)')) + +union select 9,'# poly',npoints(geomfromtext('POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1),(1 1,1 2,2 2,2 1,1 1))')) +union select 10,'length poly',length(geomfromtext('POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1),(1 1,1 2,2 2,2 1,1 1))')) +union select 11,'peri poly',perimeter(geomfromtext('POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1),(1 1,1 2,2 2,2 1,1 1))')) +union select 12,'area poly',area(geomfromtext('POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,1 2,2 2,2 1,1 1),(1 1,1 2,2 2,2 1,1 1))')) + +*/ diff --git a/src/boost/libs/geometry/test/io/wkt/wkt_multi.cpp b/src/boost/libs/geometry/test/io/wkt/wkt_multi.cpp new file mode 100644 index 00000000..81471745 --- /dev/null +++ b/src/boost/libs/geometry/test/io/wkt/wkt_multi.cpp @@ -0,0 +1,126 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// Unit Test + +// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2015 Bruno Lalande, Paris, France. +// Copyright (c) 2009-2015 Mateusz Loskot, London, UK. + +// This file was modified by Oracle on 2014, 2015. +// Modifications copyright (c) 2014-2015 Oracle and/or its affiliates. + +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library +// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +//#include <iostream> +#include <sstream> +#include <string> + +#include <boost/algorithm/string.hpp> +#include <boost/concept/requires.hpp> + +#include <boost/test/tools/floating_point_comparison.hpp> +#include <boost/test/included/test_exec_monitor.hpp> + +#include <boost/geometry/geometries/geometries.hpp> + +#include <boost/geometry/io/wkt/wkt.hpp> + +template <typename T> +void test_all(); + + +// Include the single test +#define GEOMETRY_TEST_MULTI +#include "io/wkt/wkt.cpp" + +template <typename T> +void test_order_closure() +{ + using namespace boost::geometry; + typedef bg::model::point<T, 2, bg::cs::cartesian> Pt; + typedef bg::model::polygon<Pt, true, true> PCWC; + typedef bg::model::polygon<Pt, true, false> PCWO; + typedef bg::model::polygon<Pt, false, true> PCCWC; + typedef bg::model::polygon<Pt, false, false> PCCWO; + typedef bg::model::multi_polygon<PCWC> MPCWC; + typedef bg::model::multi_polygon<PCWO> MPCWO; + typedef bg::model::multi_polygon<PCCWC> MPCCWC; + typedef bg::model::multi_polygon<PCCWO> MPCCWO; + + std::string wkt_cwc = "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0)),((0 0,0 -3,-3 -3,-3 0,0 0),(-1 -1,-2 -1,-2 -2,-1 -2,-1 -1)))"; + std::string wkt_cwo = "MULTIPOLYGON(((0 0,0 2,2 2,2 0)),((0 0,0 -3,-3 -3,-3 0),(-1 -1,-2 -1,-2 -2,-1 -2)))"; + std::string wkt_ccwc = "MULTIPOLYGON(((0 0,2 0,2 2,0 2,0 0)),((0 0,-3 0,-3 -3,0 -3,0 0),(-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))"; + std::string wkt_ccwo = "MULTIPOLYGON(((0 0,2 0,2 2,0 2)),((0 0,-3 0,-3 -3,0 -3),(-1 -1,-1 -2,-2 -2,-2 -1)))"; + + test_wkt<MPCWC>(wkt_cwc, wkt_cwc, 15, 0, 12, 24); + test_wkt<MPCWO>(wkt_cwc, wkt_cwc, 12, 0, 12, 24); + test_wkt<MPCWO>(wkt_cwo, wkt_cwc, 12, 0, 12, 24); + test_wkt<MPCCWC>(wkt_ccwc, wkt_ccwc, 15, 0, 12, 24); + test_wkt<MPCCWO>(wkt_ccwc, wkt_ccwc, 12, 0, 12, 24); + test_wkt<MPCCWO>(wkt_ccwo, wkt_ccwc, 12, 0, 12, 24); +} + +template <typename T> +void test_all() +{ + using namespace boost::geometry; + typedef bg::model::point<T, 2, bg::cs::cartesian> P; + + test_wkt<bg::model::multi_point<P> >("multipoint((1 2),(3 4))", 2); + test_wkt<bg::model::multi_linestring<bg::model::linestring<P> > >("multilinestring((1 1,2 2,3 3),(4 4,5 5,6 6))", 6, 4 * sqrt(2.0)); + test_wkt<bg::model::multi_polygon<bg::model::polygon<P> > >("multipolygon(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))", 15, 0, 21, 28); + + // Support for the official alternative syntax for multipoint + // (provided by Aleksey Tulinov): + test_relaxed_wkt<bg::model::multi_point<P> >("multipoint(1 2,3 4)", "multipoint((1 2),(3 4))"); + + test_wrong_wkt<bg::model::multi_polygon<bg::model::polygon<P> > >( + "MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),(0 0,0 4,4 4,4 0,0 0)))", + "expected '('"); + + test_wrong_wkt<bg::model::multi_linestring<bg::model::linestring<P> > >( + "MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10)), (0 0, 1 1)", + "too many tokens at ','"); + + test_wrong_wkt<bg::model::multi_point<P> >( + "MULTIPOINT((8 9), 10 11)", + "expected '(' at '10'"); + test_wrong_wkt<bg::model::multi_point<P> >( + "MULTIPOINT(12 13, (14 15))", + "bad lexical cast: source type value could not be interpreted as target at '(' in 'multipoint(12 13, (14 15))'"); + test_wrong_wkt<bg::model::multi_point<P> >( + "MULTIPOINT((16 17), (18 19)", + "expected ')' in 'multipoint((16 17), (18 19)'"); + test_wrong_wkt<bg::model::multi_point<P> >( + "MULTIPOINT(16 17), (18 19)", + "too many tokens at ',' in 'multipoint(16 17), (18 19)'"); + + test_order_closure<T>(); +} + +/* + +... see comments in "wkt.cpp" + +union select 13,'# mpoint',npoints(geomfromtext('MULTIPOINT((1 2),(3 4))')) +union select 14,'length mpoint',length(geomfromtext('MULTIPOINT((1 2),(3 4))')) +union select 15,'peri mpoint',perimeter(geomfromtext('MULTIPOINT((1 2),(3 4))')) +union select 16,'area mpoint',area(geomfromtext('MULTIPOINT((1 2),(3 4))')) + +union select 17,'# mls',npoints(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))')) +union select 18,'length mls',length(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))')) +union select 19,'peri mls',perimeter(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))')) +union select 20,'area mls',area(geomfromtext('MULTILINESTRING((1 1,2 2,3 3),(4 4,5 5,6 6))')) + +union select 21,'# mpoly',npoints(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))')) +union select 22,'length mpoly',length(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))')) +union select 23,'peri mpoly',perimeter(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))')) +union select 24,'area mpoly',area(geomfromtext('MULTIPOLYGON(((0 0,0 2,2 2,2 0,0 0),(1 1,1 2,2 2,2 1,1 1)),((0 0,0 4,4 4,4 0,0 0)))')) + +*/ |