diff --git a/test/io/Jamfile.v2 b/test/io/Jamfile.v2 index cf1cf59c9..28fbba1a9 100644 --- a/test/io/Jamfile.v2 +++ b/test/io/Jamfile.v2 @@ -4,8 +4,14 @@ # 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 ; \ No newline at end of file +build-project wkt ; +build-project svg ; diff --git a/test/io/svg/Jamfile.v2 b/test/io/svg/Jamfile.v2 new file mode 100644 index 000000000..ed406ffd4 --- /dev/null +++ b/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/test/io/svg/svg.cpp b/test/io/svg/svg.cpp new file mode 100644 index 000000000..e32466f71 --- /dev/null +++ b/test/io/svg/svg.cpp @@ -0,0 +1,146 @@ +// Boost.Geometry +// Unit Test + +// 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) + +#ifdef TEST_WITH_SVG +#include +#endif + +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +template +inline void push_back_square(R & rng, T const& mi, T const& ma) +{ + typedef typename bg::point_type::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 +void test_all() +{ + typedef bg::model::box

box; + typedef bg::model::segment

segment; + typedef bg::model::linestring

linestring; + typedef bg::model::ring

ring; + typedef bg::model::polygon

polygon; + + typedef bg::model::multi_point

multi_point; + typedef bg::model::multi_linestring multi_linestring; + typedef bg::model::multi_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); + + 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 << "" + << "" + << ""; + + 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 << ""; + } + + { +#ifdef TEST_WITH_SVG + std::ofstream os("test2.svg", std::ios::trunc); +#else + std::stringstream os; +#endif + bg::svg_mapper

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.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); + } +} + +int test_main(int, char* []) +{ + test_all< boost::geometry::model::d2::point_xy >(); + test_all< boost::geometry::model::d2::point_xy >(); + +#if defined(HAVE_TTMATH) + test_all< boost::geometry::model::d2::point_xy >(); +#endif + + return 0; +}