mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 15:14:02 +00:00
[closest_points] Add documentation and examples
This commit is contained in:
parent
90199c1dcc
commit
09c5132e84
@ -24,6 +24,7 @@
|
||||
\defgroup buffer buffer: calculate buffer of a geometry
|
||||
\defgroup centroid centroid: calculate centroid (center of gravity) of a geometry
|
||||
\defgroup clear clear: clear geometries
|
||||
\defgroup closest_points closest points: compute closest points between two geometries
|
||||
\defgroup compare compare: define compare functors for points
|
||||
\defgroup concepts geometry concepts: defines and checks concepts for geometries
|
||||
\defgroup convert convert: convert geometries from one type to another
|
||||
|
BIN
doc/html/img/algorithms/closest_points.png
Normal file
BIN
doc/html/img/algorithms/closest_points.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.8 KiB |
@ -150,7 +150,7 @@
|
||||
</ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: March 26, 2021 at 01:19:59 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: November 18, 2021 at 09:03:30 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
@ -28,6 +28,8 @@
|
||||
[import src/examples/algorithms/azimuth_strategy.cpp]
|
||||
[import src/examples/algorithms/buffer_with_strategies.cpp]
|
||||
[import src/examples/algorithms/clear.cpp]
|
||||
[import src/examples/algorithms/closest_points.cpp]
|
||||
[import src/examples/algorithms/closest_points_strategy.cpp]
|
||||
[import src/examples/algorithms/centroid.cpp]
|
||||
[import src/examples/algorithms/comparable_distance.cpp]
|
||||
[import src/examples/algorithms/convert.cpp]
|
||||
|
@ -96,8 +96,8 @@ def cs_to_quickbook(section):
|
||||
call_doxygen()
|
||||
|
||||
algorithms = ["append", "assign", "make", "clear"
|
||||
, "area", "azimuth", "buffer", "centroid", "convert", "correct", "covered_by"
|
||||
, "convex_hull", "crosses", "densify", "difference"
|
||||
, "area", "azimuth", "buffer", "centroid", "closest_points", "convert"
|
||||
, "correct", "covered_by", "convex_hull", "crosses", "densify", "difference"
|
||||
, "discrete_frechet_distance", "discrete_hausdorff_distance", "disjoint"
|
||||
, "distance", "envelope", "equals", "expand", "for_each", "is_empty"
|
||||
, "is_simple", "is_valid", "intersection", "intersects", "length"
|
||||
|
@ -382,6 +382,10 @@
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="geometry.reference.algorithms.clear">clear</link></member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Closest Points</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="geometry.reference.algorithms.closest_points">closest_points</link></member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Convert</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="geometry.reference.algorithms.convert">convert</link></member>
|
||||
|
@ -93,6 +93,11 @@
|
||||
[endsect]
|
||||
|
||||
[include generated/clear.qbk]
|
||||
|
||||
[section:closest_points closest_points]
|
||||
[include generated/closest_points.qbk]
|
||||
[endsect]
|
||||
|
||||
[include generated/convert.qbk]
|
||||
|
||||
[section:convex_hull convex_hull]
|
||||
|
@ -4,8 +4,8 @@
|
||||
// Copyright (c) 2011-2015 Bruno Lalande, Paris, France.
|
||||
// Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
|
||||
|
||||
// Copyright (c) 2018, Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
|
||||
// Copyright (c) 2018-2021 Oracle and/or its affiliates.
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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
|
||||
@ -27,6 +27,7 @@
|
||||
#include <boost/geometry/algorithms/buffer.hpp>
|
||||
#include <boost/geometry/algorithms/centroid.hpp>
|
||||
#include <boost/geometry/algorithms/clear.hpp>
|
||||
#include <boost/geometry/algorithms/closest_points.hpp>
|
||||
#include <boost/geometry/algorithms/convert.hpp>
|
||||
#include <boost/geometry/algorithms/convex_hull.hpp>
|
||||
#include <boost/geometry/algorithms/correct.hpp>
|
||||
@ -103,6 +104,7 @@ DECLARE_UNARY_ALGORITHM(area)
|
||||
DECLARE_BINARY_ALGORITHM(buffer)
|
||||
DECLARE_UNARY_ALGORITHM(centroid)
|
||||
DECLARE_UNARY_ALGORITHM(clear)
|
||||
DECLARE_BINARY_ALGORITHM(closest_points)
|
||||
DECLARE_BINARY_ALGORITHM(convert)
|
||||
DECLARE_UNARY_ALGORITHM(convex_hull)
|
||||
DECLARE_UNARY_ALGORITHM(correct)
|
||||
@ -244,6 +246,7 @@ void support_status()
|
||||
test_binary_algorithm<buffer, all_types, all_types, OutputFactory>("buffer");
|
||||
test_unary_algorithm<centroid, all_types, OutputFactory>("centroid");
|
||||
test_unary_algorithm<clear, all_types, OutputFactory>("clear");
|
||||
test_binary_algorithm<closest_points, all_types, all_types, OutputFactory>("closest_points");
|
||||
test_binary_algorithm<convert, all_types, all_types, OutputFactory>("convert");
|
||||
test_unary_algorithm<convex_hull, all_types, OutputFactory>("convex_hull");
|
||||
test_unary_algorithm<correct, all_types, OutputFactory>("correct");
|
||||
|
@ -37,6 +37,8 @@ exe assign_points : assign_points.cpp ;
|
||||
exe buffer_with_strategies : buffer_with_strategies.cpp ;
|
||||
exe centroid : centroid.cpp ;
|
||||
exe clear : clear.cpp ;
|
||||
exe closest_points : closest_points.cpp ;
|
||||
exe closest_points_strategy : closest_points_strategy.cpp ;
|
||||
exe comparable_distance : comparable_distance.cpp ;
|
||||
exe convert : convert.cpp ;
|
||||
exe convex_hull : convex_hull.cpp ;
|
||||
|
76
doc/src/examples/algorithms/closest_points_strategy.cpp
Normal file
76
doc/src/examples/algorithms/closest_points_strategy.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
// Boost.Geometry
|
||||
// QuickBook Example
|
||||
|
||||
// Copyright (c) 2021, Oracle and/or its affiliates
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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)
|
||||
|
||||
//[closest_points_strategy
|
||||
//` Shows calculation of the two closest points between two geometries using strategies
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/geometries/linestring.hpp>
|
||||
#include <boost/geometry/geometries/point_xy.hpp>
|
||||
#include <boost/geometry/geometries/polygon.hpp>
|
||||
#include <boost/geometry/geometries/multi_point.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::geometry::model::d2::point_xy
|
||||
<
|
||||
double,
|
||||
boost::geometry::cs::geographic<boost::geometry::degree>
|
||||
> point_type;
|
||||
typedef boost::geometry::model::polygon<point_type> polygon_type;
|
||||
typedef boost::geometry::model::linestring<point_type> linestring_type;
|
||||
typedef boost::geometry::model::multi_point<point_type> multi_point_type;
|
||||
|
||||
point_type p(4.3,1.9);
|
||||
polygon_type poly;
|
||||
linestring_type line;
|
||||
multi_point_type mp;
|
||||
|
||||
boost::geometry::strategies::closest_points::geographic<> strategies
|
||||
(boost::geometry::srs::spheroid<double>(6378137.0, 6356752.3142451793));
|
||||
|
||||
boost::geometry::read_wkt(
|
||||
"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
|
||||
"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);
|
||||
|
||||
line.push_back(point_type(5,0));
|
||||
line.push_back(point_type(2,0));
|
||||
mp.push_back(point_type(2,0.5));
|
||||
mp.push_back(point_type(2,3));
|
||||
|
||||
boost::geometry::model::segment<point_type> sout1,sout2,sout3;
|
||||
|
||||
boost::geometry::closest_points(p, poly, sout1, strategies);
|
||||
std::cout << "Point-Poly: " << boost::geometry::wkt(sout1) << std::endl;
|
||||
|
||||
boost::geometry::closest_points(poly, line, sout2, strategies);
|
||||
std::cout << "Poly-Line: " << boost::geometry::wkt(sout2) << std::endl;
|
||||
|
||||
boost::geometry::closest_points(p, mp, sout3, strategies);
|
||||
std::cout << "Poly-MultiPoint: " << boost::geometry::wkt(sout3) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//]
|
||||
|
||||
|
||||
//[closest_points_strategy_output
|
||||
/*`
|
||||
Output:
|
||||
[pre
|
||||
Point-Poly: LINESTRING(4.3 1.9,4.20096 2.1005)
|
||||
Poly-Line: LINESTRING(2.9 0.7,2.9 0)
|
||||
Poly-MultiPoint: LINESTRING(4.3 1.9,2 3)
|
||||
]
|
||||
*/
|
||||
//]
|
@ -0,0 +1,66 @@
|
||||
// Boost.Geometry
|
||||
// QuickBook Example
|
||||
|
||||
// Copyright (c) 2021, Oracle and/or its affiliates
|
||||
// Contributed and/or modified by Vissarion Fysikopoulos, 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)
|
||||
|
||||
// Code to create SVG for closest_points examples
|
||||
|
||||
#ifndef CREATE_SVG_CLOSEST_POINTS_HPP
|
||||
#define CREATE_SVG_CLOSEST_POINTS_HPP
|
||||
|
||||
#include <fstream>
|
||||
#if defined(HAVE_SVG)
|
||||
# include <boost/geometry/io/svg/svg_mapper.hpp>
|
||||
#endif
|
||||
|
||||
template
|
||||
<
|
||||
typename Point,
|
||||
typename Line,
|
||||
typename Polygon,
|
||||
typename Multipoint,
|
||||
typename Segment
|
||||
>
|
||||
void create_svg_closest_points(Point const& p0,
|
||||
Point const& p,
|
||||
Line const& line,
|
||||
Polygon const& poly,
|
||||
Multipoint const& mp,
|
||||
Segment const& sout1,
|
||||
Segment const& sout2,
|
||||
Segment const& sout3)
|
||||
{
|
||||
// Declare a stream and an SVG mapper
|
||||
std::ofstream svg("closest_points_example.svg");
|
||||
boost::geometry::svg_mapper<Point> mapper(svg, 400, 400);
|
||||
|
||||
// Add geometries such that all these geometries fit on the map
|
||||
|
||||
mapper.add(p0);
|
||||
mapper.add(p);
|
||||
mapper.add(poly);
|
||||
mapper.add(line);
|
||||
mapper.add(mp);
|
||||
mapper.add(sout1);
|
||||
mapper.add(sout2);
|
||||
mapper.add(sout3);
|
||||
|
||||
// Draw the geometries on the SVG map, using a specific SVG style
|
||||
mapper.map(sout1, "opacity:1.0;fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1;stroke-dasharray:1,2");
|
||||
mapper.map(sout2, "opacity:1.0;fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1;stroke-dasharray:1,2");
|
||||
mapper.map(sout3, "opacity:1.0;fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1;stroke-dasharray:1,2");
|
||||
mapper.map(p, "opacity:1.0;fill:rgb(255,0,0);stroke:rgb(255,0,0);stroke-width:1");
|
||||
mapper.map(poly, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
|
||||
mapper.map(line, "opacity:1.0;fill:none;stroke:rgb(0,0,255);stroke-width:2");
|
||||
mapper.map(mp, "opacity:2.0;fill:rgb(0,255,255);stroke:rgb(0,255,255);stroke-width:.5");
|
||||
}
|
||||
|
||||
// NOTE: convert manually from svg to png using Inkscape ctrl-shift-E
|
||||
// and copy png to html/img/...
|
||||
|
||||
#endif // CREATE_SVG_CLOSEST_POINTS_HPP
|
@ -290,8 +290,6 @@ BOOST_AUTO_TEST_CASE( test_all_pointlike_linear )
|
||||
(andoyer(stype(5000000,6000000)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// tests from https://github.com/boostorg/geometry/pull/707#issuecomment-786650747
|
||||
|
||||
template <typename CT>
|
||||
|
Loading…
x
Reference in New Issue
Block a user