1// Boost.Geometry
2
3// Copyright (c) 2022 Oracle and/or its affiliates.
4// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5
6// Use, modification and distribution is subject to the Boost Software License,
7// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10#include "geometry_test_common.hpp"
11
12#include <boost/geometry/algorithms/buffer.hpp>
13#include <boost/geometry/geometries/geometries.hpp>
14#include <boost/geometry/io/wkt/read.hpp>
15#include <boost/geometry/strategies/strategies.hpp>
16
17using pt_t = bg::model::point<double, 2, bg::cs::cartesian>;
18using ls_t = bg::model::linestring<pt_t>;
19using po_t = bg::model::polygon<pt_t>;
20using mpt_t = bg::model::multi_point<pt_t>;
21using mls_t = bg::model::multi_linestring<ls_t>;
22using mpo_t = bg::model::multi_polygon<po_t>;
23using var_t = boost::variant<pt_t, ls_t, po_t, mpt_t, mls_t, mpo_t>;
24using gc_t = bg::model::geometry_collection<var_t>;
25
26void test_gc()
27{
28 gc_t gc;
29 bg::read_wkt(wkt: "GEOMETRYCOLLECTION("
30 "POLYGON((0 0,0 5,5 5,5 0,0 0)),"
31 "LINESTRING(2 2,9 9),"
32 "POINT(0 9)"
33 ")", geometry&: gc);
34
35 bg::strategy::buffer::distance_symmetric<double> distance(1.0);
36 bg::strategy::buffer::side_straight side;
37 bg::strategy::buffer::join_round join;
38 bg::strategy::buffer::end_round end;
39 bg::strategy::buffer::point_circle circle;
40
41 mpo_t result_mpo;
42 bg::buffer(geometry_in: gc, geometry_out&: result_mpo, distance_strategy: distance, side_strategy: side, join_strategy: join, end_strategy: end, point_strategy: circle);
43
44 BOOST_CHECK(result_mpo.size() == 2);
45 double area = bg::area(geometry: result_mpo);
46 BOOST_CHECK_CLOSE(area, 62.548206613048151, 0.0001);
47
48 gc_t result_gc;
49 bg::buffer(geometry_in: gc, geometry_out&: result_gc, distance_strategy: distance, side_strategy: side, join_strategy: join, end_strategy: end, point_strategy: circle);
50
51 BOOST_CHECK(result_gc.size() == 1);
52 BOOST_CHECK(boost::get<mpo_t>(result_gc[0]).size() == 2);
53 area = bg::area(geometry: boost::get<mpo_t>(operand&: result_gc[0]));
54 BOOST_CHECK_CLOSE(area, 62.548206613048151, 0.0001);
55}
56
57int test_main(int, char* [])
58{
59 test_gc();
60
61 return 0;
62}
63

source code of boost/libs/geometry/test/algorithms/buffer/buffer_gc.cpp