mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-10 23:42:12 +00:00
Merge pull request #62 from awulkiew/feature/initializer_list
Feature/initializer list
This commit is contained in:
@@ -91,6 +91,8 @@ ALIASES = qbk{1}="\xmlonly <qbk>\1</qbk> \endxmlonly" \
|
||||
param_z="Third coordinate (usually z-coordinate)" \
|
||||
constructor_default{1}="Default constructor, creating an empty \1" \
|
||||
constructor_begin_end{1}="Constructor with begin and end, filling the \1" \
|
||||
constructor_initializer_list{1}="Constructor taking std::initializer_list, filling the \1" \
|
||||
assignment_initializer_list{1}="Assignment operator taking std::initializer_list, assigning values to the \1" \
|
||||
details_calc{2}="The free function \1 calculates the \2 of a geometry" \
|
||||
details_calc{1}="The free function \1 calculates the \1 of a geometry" \
|
||||
details_calc2{2}="The free function \1 calculates the \2 of two geometries" \
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -25,6 +26,12 @@
|
||||
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -68,6 +75,30 @@ public :
|
||||
inline linestring(Iterator begin, Iterator end)
|
||||
: base_type(begin, end)
|
||||
{}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_initializer_list{linestring}
|
||||
inline linestring(std::initializer_list<Point> l)
|
||||
: base_type(l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it should be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{linestring}
|
||||
// inline linestring & operator=(std::initializer_list<Point> l)
|
||||
// {
|
||||
// base_type::assign(l.begin(), l.end());
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace model
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -22,6 +23,12 @@
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/geometries/concepts/linestring_concept.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -50,6 +57,39 @@ template
|
||||
class multi_linestring : public Container<LineString, Allocator<LineString> >
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concept::Linestring<LineString>) );
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
|
||||
typedef Container<LineString, Allocator<LineString> > base_type;
|
||||
|
||||
public:
|
||||
/// \constructor_default{multi_linestring}
|
||||
multi_linestring()
|
||||
: base_type()
|
||||
{}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_initializer_list{multi_linestring}
|
||||
inline multi_linestring(std::initializer_list<LineString> l)
|
||||
: base_type(l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it shoudl be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{multi_linestring}
|
||||
// inline multi_linestring & operator=(std::initializer_list<LineString> l)
|
||||
// {
|
||||
// base_type::assign(l.begin(), l.end());
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -22,6 +23,12 @@
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -66,6 +73,30 @@ public :
|
||||
inline multi_point(Iterator begin, Iterator end)
|
||||
: base_type(begin, end)
|
||||
{}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_initializer_list{multi_point}
|
||||
inline multi_point(std::initializer_list<Point> l)
|
||||
: base_type(l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it shoudl be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{multi_point}
|
||||
// inline multi_point & operator=(std::initializer_list<Point> l)
|
||||
// {
|
||||
// base_type::assign(l.begin(), l.end());
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace model
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -22,6 +23,13 @@
|
||||
#include <boost/geometry/core/tags.hpp>
|
||||
#include <boost/geometry/geometries/concepts/polygon_concept.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
@@ -48,6 +56,39 @@ template
|
||||
class multi_polygon : public Container<Polygon, Allocator<Polygon> >
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT( (concept::Polygon<Polygon>) );
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
|
||||
typedef Container<Polygon, Allocator<Polygon> > base_type;
|
||||
|
||||
public:
|
||||
/// \constructor_default{multi_polygon}
|
||||
multi_polygon()
|
||||
: base_type()
|
||||
{}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_initializer_list{multi_polygon}
|
||||
inline multi_polygon(std::initializer_list<Polygon> l)
|
||||
: base_type(l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it shoudl be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{multi_polygon}
|
||||
// inline multi_polygon & operator=(std::initializer_list<Polygon> l)
|
||||
// {
|
||||
// base_type::assign(l.begin(), l.end());
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// This file was modified by Oracle on 2014.
|
||||
// Modifications copyright (c) 2014, Oracle and/or its affiliates.
|
||||
@@ -82,7 +83,7 @@ public:
|
||||
{}
|
||||
|
||||
/// @brief Constructor to set one, two or three values
|
||||
explicit inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0)
|
||||
inline point(CoordinateType const& v0, CoordinateType const& v1 = 0, CoordinateType const& v2 = 0)
|
||||
{
|
||||
if (DimensionCount >= 1) m_values[0] = v0;
|
||||
if (DimensionCount >= 2) m_values[1] = v1;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -26,6 +27,13 @@
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
#include <boost/geometry/geometries/ring.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
|
||||
@@ -83,6 +91,46 @@ public:
|
||||
inline ring_type& outer() { return m_outer; }
|
||||
inline inner_container_type & inners() { return m_inners; }
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_default{polygon}
|
||||
inline polygon()
|
||||
: m_outer()
|
||||
, m_inners()
|
||||
{}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
/// \constructor_initializer_list{polygon}
|
||||
inline polygon(std::initializer_list<ring_type> l)
|
||||
: m_outer(l.size() > 0 ? *l.begin() : ring_type())
|
||||
, m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it shoudl be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{polygon}
|
||||
// inline polygon & operator=(std::initializer_list<ring_type> l)
|
||||
// {
|
||||
// if ( l.size() > 0 )
|
||||
// {
|
||||
// m_outer = *l.begin();
|
||||
// m_inners.assign(l.begin() + 1, l.end());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m_outer.clear();
|
||||
// m_inners.clear();
|
||||
// }
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// Utility method, clears outer and inner rings
|
||||
inline void clear()
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// 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.
|
||||
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
|
||||
|
||||
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
||||
// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
||||
@@ -26,6 +27,12 @@
|
||||
|
||||
#include <boost/geometry/geometries/concepts/point_concept.hpp>
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
#include <initializer_list>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost { namespace geometry
|
||||
{
|
||||
@@ -72,6 +79,30 @@ public :
|
||||
inline ring(Iterator begin, Iterator end)
|
||||
: base_type(begin, end)
|
||||
{}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST
|
||||
#ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
|
||||
|
||||
/// \constructor_initializer_list{ring}
|
||||
inline ring(std::initializer_list<Point> l)
|
||||
: base_type(l.begin(), l.end())
|
||||
{}
|
||||
|
||||
// Commented out for now in order to support Boost.Assign
|
||||
// Without this assignment operator first the object should be created
|
||||
// from initializer list, then it shoudl be moved.
|
||||
//// Without this workaround in MSVC the assignment operator is ambiguous
|
||||
//#ifndef BOOST_MSVC
|
||||
// /// \assignment_initializer_list{ring}
|
||||
// inline ring & operator=(std::initializer_list<Point> l)
|
||||
// {
|
||||
// base_type::assign(l.begin(), l.end());
|
||||
// return *this;
|
||||
// }
|
||||
//#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace model
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
# 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.
|
||||
# Copyright (c) 2014 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
|
||||
@@ -24,5 +25,6 @@ test-suite boost-geometry-geometries
|
||||
# custom_linestring_test_fail_clear
|
||||
#]
|
||||
[ run custom_linestring.cpp ]
|
||||
[ run geometries.cpp : : : <define>BOOST_GEOMETRY_EXPERIMENTAL_ENABLE_INITIALIZER_LIST ]
|
||||
[ run segment.cpp ]
|
||||
;
|
||||
|
||||
253
test/geometries/geometries.cpp
Normal file
253
test/geometries/geometries.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
// Boost.Geometry
|
||||
// Unit Test
|
||||
|
||||
// Copyright (c) 2014 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)
|
||||
|
||||
#include <geometry_test_common.hpp>
|
||||
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/range.hpp>
|
||||
|
||||
#include <boost/geometry/geometries/geometries.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
|
||||
#include <boost/geometry/geometries/register/point.hpp>
|
||||
|
||||
#include <boost/geometry/algorithms/num_points.hpp>
|
||||
#include <boost/geometry/multi/algorithms/num_points.hpp>
|
||||
#include <boost/geometry/algorithms/num_geometries.hpp>
|
||||
|
||||
typedef std::pair<float, float> pt_pair_t;
|
||||
BOOST_GEOMETRY_REGISTER_POINT_2D(pt_pair_t, float, bg::cs::cartesian, first, second)
|
||||
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
|
||||
|
||||
template <typename P>
|
||||
void test_default()
|
||||
{
|
||||
typedef bg::model::multi_point<P> mpt;
|
||||
typedef bg::model::linestring<P> ls;
|
||||
typedef bg::model::multi_linestring<ls> mls;
|
||||
typedef bg::model::ring<P> ring;
|
||||
typedef bg::model::polygon<P> poly;
|
||||
typedef bg::model::multi_polygon<poly> mpoly;
|
||||
|
||||
// multi_point()
|
||||
mpt mptd;
|
||||
BOOST_CHECK(bg::num_points(mptd) == 0);
|
||||
// linestring()
|
||||
ls lsd;
|
||||
BOOST_CHECK(bg::num_points(lsd) == 0);
|
||||
// multi_linestring()
|
||||
mls mlsd;
|
||||
BOOST_CHECK(bg::num_points(mlsd) == 0);
|
||||
// ring()
|
||||
ring rd;
|
||||
BOOST_CHECK(bg::num_points(rd) == 0);
|
||||
// polygon()
|
||||
poly pd;
|
||||
BOOST_CHECK(bg::num_points(pd) == 0);
|
||||
// multi_polygon()
|
||||
mpoly mpd;
|
||||
BOOST_CHECK(bg::num_points(mpd) == 0);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_boost_assign_2d()
|
||||
{
|
||||
typedef bg::model::multi_point<P> mpt;
|
||||
typedef bg::model::linestring<P> ls;
|
||||
typedef bg::model::ring<P> ring;
|
||||
|
||||
// using Boost.Assign
|
||||
mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0));
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0));
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
|
||||
// using Boost.Assign
|
||||
ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1));
|
||||
BOOST_CHECK(bg::num_points(ls2) == 3);
|
||||
ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1));
|
||||
BOOST_CHECK(bg::num_points(ls2) == 3);
|
||||
|
||||
// using Boost.Assign
|
||||
ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0));
|
||||
BOOST_CHECK(bg::num_points(r2) == 5);
|
||||
r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0));
|
||||
BOOST_CHECK(bg::num_points(r2) == 5);
|
||||
}
|
||||
|
||||
void test_boost_assign_pair_2d()
|
||||
{
|
||||
typedef std::pair<float, float> pt;
|
||||
|
||||
test_boost_assign_2d<pt>();
|
||||
|
||||
typedef bg::model::multi_point<pt> mpt;
|
||||
|
||||
// using Boost.Assign
|
||||
mpt mpt2 = boost::assign::pair_list_of(0, 0)(1, 0);
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
mpt2 = boost::assign::pair_list_of(0, 0)(1, 0);
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
}
|
||||
|
||||
void test_boost_assign_tuple_2d()
|
||||
{
|
||||
typedef boost::tuple<float, float> pt;
|
||||
|
||||
test_boost_assign_2d<pt>();
|
||||
|
||||
typedef bg::model::multi_point<pt> mpt;
|
||||
|
||||
// using Boost.Assign
|
||||
mpt mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0);
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0);
|
||||
BOOST_CHECK(bg::num_points(mpt2) == 2);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_initializer_list_2d()
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
|
||||
typedef bg::model::multi_point<P> mpt;
|
||||
typedef bg::model::linestring<P> ls;
|
||||
typedef bg::model::multi_linestring<ls> mls;
|
||||
typedef bg::model::ring<P> ring;
|
||||
typedef bg::model::polygon<P> poly;
|
||||
typedef bg::model::multi_polygon<poly> mpoly;
|
||||
|
||||
// multi_point(initializer_list<Point>)
|
||||
mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}};
|
||||
BOOST_CHECK(bg::num_geometries(mpt1) == 3);
|
||||
BOOST_CHECK(bg::num_points(mpt1) == 3);
|
||||
// multi_point::operator=(initializer_list<Point>)
|
||||
mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
|
||||
BOOST_CHECK(bg::num_points(mpt1) == 4);
|
||||
|
||||
// linestring(initializer_list<Point>)
|
||||
ls ls1 = {{0, 0}, {1, 0}, {2, 0}};
|
||||
BOOST_CHECK(bg::num_geometries(ls1) == 1);
|
||||
BOOST_CHECK(bg::num_points(ls1) == 3);
|
||||
// linestring::operator=(initializer_list<Point>)
|
||||
ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
|
||||
BOOST_CHECK(bg::num_points(ls1) == 4);
|
||||
|
||||
// multi_linestring(initializer_list<Linestring>)
|
||||
mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}};
|
||||
BOOST_CHECK(bg::num_geometries(mls1) == 2);
|
||||
BOOST_CHECK(bg::num_points(mls1) == 5);
|
||||
// multi_linestring::operator=(initializer_list<Linestring>)
|
||||
mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}};
|
||||
BOOST_CHECK(bg::num_points(mls1) == 6);
|
||||
|
||||
// ring(initializer_list<Point>)
|
||||
ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
|
||||
BOOST_CHECK(bg::num_geometries(r1) == 1);
|
||||
BOOST_CHECK(bg::num_points(r1) == 5);
|
||||
// ring::operator=(initializer_list<Point>)
|
||||
r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}};
|
||||
BOOST_CHECK(bg::num_points(r1) == 6);
|
||||
|
||||
// polygon(initializer_list<ring_type>)
|
||||
poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}};
|
||||
BOOST_CHECK(bg::num_geometries(p1) == 1);
|
||||
BOOST_CHECK(bg::num_points(p1) == 10);
|
||||
BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1);
|
||||
// polygon::operator=(initializer_list<ring_type>)
|
||||
p1 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}};
|
||||
BOOST_CHECK(bg::num_points(p1) == 11);
|
||||
BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1);
|
||||
p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}};
|
||||
BOOST_CHECK(bg::num_points(p1) == 5);
|
||||
BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0);
|
||||
// polygon(initializer_list<ring_type>)
|
||||
poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}};
|
||||
BOOST_CHECK(bg::num_geometries(p2) == 1);
|
||||
BOOST_CHECK(bg::num_points(p2) == 5);
|
||||
BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0);
|
||||
// polygon::operator=(initializer_list<ring_type>)
|
||||
p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}};
|
||||
BOOST_CHECK(bg::num_points(p2) == 6);
|
||||
|
||||
// multi_polygon(initializer_list<Polygon>)
|
||||
mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}};
|
||||
BOOST_CHECK(bg::num_geometries(mp1) == 2);
|
||||
BOOST_CHECK(bg::num_points(mp1) == 10);
|
||||
// multi_polygon::operator=(initializer_list<Polygon>)
|
||||
mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}};
|
||||
BOOST_CHECK(bg::num_points(mp1) == 11);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_all_2d()
|
||||
{
|
||||
test_default<P>();
|
||||
test_boost_assign_2d<P>();
|
||||
test_initializer_list_2d<P>();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct test_point
|
||||
{
|
||||
test_point(T = T(), T = T()) {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct test_range
|
||||
{
|
||||
test_range() {}
|
||||
template <typename It>
|
||||
test_range(It, It) {}
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
|
||||
test_range(std::initializer_list<T>) {}
|
||||
//test_range & operator=(std::initializer_list<T>) { return *this; }
|
||||
#endif
|
||||
};
|
||||
|
||||
void test_sanity_check()
|
||||
{
|
||||
typedef test_point<float> P;
|
||||
typedef test_range<P> R;
|
||||
typedef std::vector<P> V;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
|
||||
{
|
||||
R r = {{1, 1},{2, 2},{3, 3}};
|
||||
r = {{1, 1},{2, 2},{3, 3}};
|
||||
|
||||
V v = {{1, 1},{2, 2},{3, 3}};
|
||||
v = {{1, 1},{2, 2},{3, 3}};
|
||||
}
|
||||
#endif
|
||||
{
|
||||
R r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
|
||||
r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
|
||||
|
||||
V v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
|
||||
//v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3));
|
||||
v.empty();
|
||||
}
|
||||
}
|
||||
|
||||
int test_main(int, char* [])
|
||||
{
|
||||
test_all_2d< bg::model::point<float, 2, bg::cs::cartesian> >();
|
||||
test_all_2d< bg::model::d2::point_xy<float> >();
|
||||
|
||||
test_boost_assign_pair_2d();
|
||||
test_boost_assign_tuple_2d();
|
||||
|
||||
test_sanity_check();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user