Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added doc/html/img/algorithms/covered_by.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/html/img/algorithms/crosses.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/html/img/algorithms/disjoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/html/img/algorithms/overlaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/html/img/algorithms/touches_one_geometry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions doc/imports.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
[import src/examples/algorithms/convert.cpp]
[import src/examples/algorithms/convex_hull.cpp]
[import src/examples/algorithms/correct.cpp]
[import src/examples/algorithms/covered_by.cpp]
[import src/examples/algorithms/crosses.cpp]
[import src/examples/algorithms/densify.cpp]
[import src/examples/algorithms/densify_strategy.cpp]
[import src/examples/algorithms/discrete_frechet_distance.cpp]
[import src/examples/algorithms/discrete_frechet_distance_strategy.cpp]
[import src/examples/algorithms/discrete_hausdorff_distance.cpp]
[import src/examples/algorithms/discrete_hausdorff_distance_strategy.cpp]
[import src/examples/algorithms/disjoint.cpp]
[import src/examples/algorithms/distance.cpp]
[import src/examples/algorithms/difference.cpp]
[import src/examples/algorithms/envelope.cpp]
Expand Down Expand Up @@ -66,12 +69,16 @@
[import src/examples/algorithms/num_interior_rings.cpp]
[import src/examples/algorithms/num_points.cpp]
[import src/examples/algorithms/num_segments.cpp]
[import src/examples/algorithms/overlaps.cpp]
[import src/examples/algorithms/perimeter.cpp]
[import src/examples/algorithms/relate.cpp]
[import src/examples/algorithms/relation.cpp]
[import src/examples/algorithms/reverse.cpp]
[import src/examples/algorithms/return_envelope.cpp]
[import src/examples/algorithms/simplify.cpp]
[import src/examples/algorithms/sym_difference.cpp]
[import src/examples/algorithms/touches_one_geometry.cpp]
[import src/examples/algorithms/touches_two_geometries.cpp]
[import src/examples/algorithms/transform.cpp]
[import src/examples/algorithms/transform_with_strategy.cpp]
[import src/examples/algorithms/union.cpp]
Expand Down
70 changes: 70 additions & 0 deletions doc/src/examples/algorithms/covered_by.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[covered_by
//` Checks if the first geometry is inside or on border the second geometry

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Checks if the first geometry is inside or on border the second geometry.
bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
bg::read_wkt("POLYGON((0 2,0 3,2 4,1 2,0 2))", poly1);
bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
bg::read_wkt("POLYGON((0 4,3 4,2 2,0 1,0 4))", poly2);
bool check_covered = bg::covered_by(poly1, poly2);
if (check_covered) {
std::cout << "Covered: Yes" << std::endl;
} else {
std::cout << "Covered: No" << std::endl;
}

bg::model::polygon<bg::model::d2::point_xy<double> > poly3;
bg::read_wkt("POLYGON((-1 -1,-3 -4,-7 -7,-4 -3,-1 -1))", poly3);
check_covered = bg::covered_by(poly1, poly3);
if (check_covered) {
std::cout << "Covered: Yes" << std::endl;
} else {
std::cout << "Covered: No" << std::endl;
}

// This should return true since both polygons are same, so they are lying on each other.
check_covered = bg::covered_by(poly1, poly1);
if (check_covered) {
std::cout << "Covered: Yes" << std::endl;
} else {
std::cout << "Covered: No" << std::endl;
}

return 0;
}

//]


//[covered_by_output
/*`
Output:
[pre
Covered: Yes

[$img/algorithms/covered_by.png]

Covered: No
Covered: Yes
]
*/
//]
62 changes: 62 additions & 0 deletions doc/src/examples/algorithms/crosses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[crosses
//` Checks if two geometries crosses

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Checks if the two geometries (here, a polygon and a linestring) crosses or not.
bg::model::polygon<bg::model::d2::point_xy<double> > poly;
bg::read_wkt("POLYGON((0 0,0 3,3 3,3 0,0 0))", poly);
bg::model::linestring<bg::model::d2::point_xy<double> > line1;
bg::read_wkt("LINESTRING(1 1,2 2,4 4)", line1);
bool check_crosses = bg::crosses(poly, line1);
if (check_crosses) {
std::cout << "Crosses: Yes" << std::endl;
} else {
std::cout << "Crosses: No" << std::endl;
}

// Edge case: linestring just touches the polygon but doesn't crosses it.
bg::model::linestring<bg::model::d2::point_xy<double> > line2;
bg::read_wkt("LINESTRING(1 1,1 2,1 3)", line2);
check_crosses = bg::crosses(poly, line2);
if (check_crosses) {
std::cout << "Crosses: Yes" << std::endl;
} else {
std::cout << "Crosses: No" << std::endl;
}

return 0;
}

//]


//[crosses_output
/*`
Output:
[pre
Crosses: Yes
Crosses: No

[$img/algorithms/crosses.png]

]
*/
//]
61 changes: 61 additions & 0 deletions doc/src/examples/algorithms/disjoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[disjoint
//` Checks if two geometries are disjoint

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Checks if two geometries are disjoint, which means that two geometries have zero intersection.
bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
bg::read_wkt("POLYGON((0 2,-2 0,-4 2,-2 4,0 2))", poly1);
bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
bg::read_wkt("POLYGON((2 2,4 4,6 2,4 0,2 2))", poly2);
bool check_disjoint = bg::disjoint(poly1, poly2);
if (check_disjoint) {
std::cout << "Disjoint: Yes" << std::endl;
} else {
std::cout << "Disjoint: No" << std::endl;
}

bg::model::polygon<bg::model::d2::point_xy<double> > poly3;
bg::read_wkt("POLYGON((0 2,2 4,4 2,2 0,0 2))", poly3);
check_disjoint = bg::disjoint(poly1, poly3);
if (check_disjoint) {
std::cout << "Disjoint: Yes" << std::endl;
} else {
std::cout << "Disjoint: No" << std::endl;
}

return 0;
}

//]


//[disjoint_output
/*`
Output:
[pre
Disjoint: Yes
Disjoint: No

[$img/algorithms/disjoint.png]

]
*/
//]
61 changes: 61 additions & 0 deletions doc/src/examples/algorithms/overlaps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[overlaps
//` Checks if two geometries overlap

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Checks if the two geometries overlaps or not.
bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
bg::read_wkt("POLYGON((0 0,0 4,4 4,4 0,0 0))", poly1);
bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
bg::read_wkt("POLYGON((2 2,2 6,6 7,6 1,2 2))", poly2);
bool check_overlap = bg::overlaps(poly1, poly2);
if (check_overlap) {
std::cout << "Overlaps: Yes" << std::endl;
} else {
std::cout << "Overlaps: No" << std::endl;
}

bg::model::polygon<bg::model::d2::point_xy<double> > poly3;
bg::read_wkt("POLYGON((-1 -1,-3 -4,-7 -7,-4 -3,-1 -1))", poly3);
check_overlap = bg::overlaps(poly1, poly3);
if (check_overlap) {
std::cout << "Overlaps: Yes" << std::endl;
} else {
std::cout << "Overlaps: No" << std::endl;
}

return 0;
}

//]


//[overlaps_output
/*`
Output:
[pre
Overlaps: Yes

[$img/algorithms/overlaps.png]

Overlaps: No
]
*/
//]
42 changes: 42 additions & 0 deletions doc/src/examples/algorithms/perimeter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[perimeter
//` Calculate the perimeter of a polygon

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Calculate the perimeter of a cartesian polygon
bg::model::polygon<bg::model::d2::point_xy<double> > poly;
bg::read_wkt("POLYGON((0 0,3 4,5 -5,-2 -4, 0 0))", poly);
double perimeter = bg::perimeter(poly);
std::cout << "Perimeter: " << perimeter << std::endl;

return 0;
}

//]


//[perimeter_output
/*`
Output:
[pre
Perimeter: 25.7627
]
*/
//]
59 changes: 59 additions & 0 deletions doc/src/examples/algorithms/touches_one_geometry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Digvijay Janartha, Hamirpur, India.

// 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)

//[touches
//` Checks if a geometry has at least one touching point (self-tangency)

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

namespace bg = boost::geometry; /*< Convenient namespace alias >*/

int main()
{
// Checks if the geometry has self-tangency.
bg::model::polygon<bg::model::d2::point_xy<double> > poly1;
bg::read_wkt("POLYGON((0 0,0 3,2 3,2 2,1 2,1 1,2 1,2 2,3 2,3 0,0 0))", poly1);
bool check_touches = bg::touches(poly1);
if (check_touches) {
std::cout << "Touches: Yes" << std::endl;
} else {
std::cout << "Touches: No" << std::endl;
}

bg::model::polygon<bg::model::d2::point_xy<double> > poly2;
bg::read_wkt("POLYGON((0 0,0 4,4 4,4 0,2 3,0 0))", poly2);
check_touches = bg::touches(poly2);
if (check_touches) {
std::cout << "Touches: Yes" << std::endl;
} else {
std::cout << "Touches: No" << std::endl;
}

return 0;
}

//]


//[touches_output
/*`
Output:
[pre
Touches: Yes

[$img/algorithms/touches_one_geometry.png]

Touches: No
]
*/
//]
Loading