Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
geometry/example/c06_custom_polygon_example.cpp at develop · boostorg/geometry · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
boostorg
geometry
Repository navigation
Code
Issues
146
(146)
Pull requests
16
(16)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
develop
Breadcrumbs
geometry
/
example
/
c06_custom_polygon_example.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
142 lines (109 loc) · 3.7 KB
develop
Breadcrumbs
geometry
/
example
/
c06_custom_polygon_example.cpp
Copy path
Top
File metadata and controls
Code
Blame
142 lines (109 loc) · 3.7 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
Boost.Geometry (aka GGL, Generic Geometry Library)
//
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.
//
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)
//
//
Custom Polygon Example
#
include
<
array
>
#
include
<
iostream
>
#
include
<
boost/geometry/geometry.hpp
>
#
include
<
boost/geometry/geometries/register/point.hpp
>
#
include
<
boost/geometry/geometries/register/ring.hpp
>
struct
my_point
{
my_point
(
double
an_x =
0
,
double
an_y =
0
)
: x(an_x)
, y(an_y)
{}
double
x, y;
};
struct
my_ring
: std::deque<my_point>
{};
//
Define a struct of a polygon, having always two holes
//
(of course this can be implemented differently, usually
//
with a vector or deque, but it is just an exampe)
struct
my_polygon
{
//
required for a polygon: an outer ring...
my_ring boundary;
//
... and a Boost.Range compatible inner ring collection
std::array<my_ring,
2
> holes;
//
just for the sample
std::string name;
my_polygon
(std::string
const
& n =
"
"
) : name(n) {}
};
//
We can conveniently use macro's to register point and ring
BOOST_GEOMETRY_REGISTER_POINT_2D
(my_point,
double
, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_RING
(my_ring)
//
There is currently no registration macro for polygons
//
and besides that a std::array<T,N> in a macro would
//
be very specific, so we show it "by hand":
namespace
boost
{
namespace
geometry
{
namespace
traits
{
template
<>
struct
tag
<my_polygon> {
typedef
polygon_tag type; };
template
<>
struct
ring_const_type
<my_polygon> {
typedef
my_ring
const
& type; };
template
<>
struct
ring_mutable_type
<my_polygon> {
typedef
my_ring& type; };
template
<>
struct
interior_const_type
<my_polygon>
{
typedef
std::array<my_ring,
2
>
const
& type;
};
template
<>
struct
interior_mutable_type
<my_polygon>
{
typedef
std::array<my_ring,
2
>& type;
};
template
<>
struct
exterior_ring
<my_polygon>
{
static
my_ring&
get
(my_polygon& p)
{
return
p.
boundary
;
}
static
my_ring
const
&
get
(my_polygon
const
& p)
{
return
p.
boundary
;
}
};
template
<>
struct
interior_rings
<my_polygon>
{
typedef
std::array<my_ring,
2
> holes_type;
static
holes_type&
get
(my_polygon& p)
{
return
p.
holes
;
}
static
holes_type
const
&
get
(my_polygon
const
& p)
{
return
p.
holes
;
}
};
}}}
//
namespace boost::geometry::traits
int
main
()
{
my_polygon
p1
(
"
my polygon
"
);
//
Fill it the my-way, triangle
p1.
boundary
.
push_back
(
my_point
(
2
,
0
));
p1.
boundary
.
push_back
(
my_point
(
1
,
5
));
p1.
boundary
.
push_back
(
my_point
(
7
,
6
));
p1.
boundary
.
push_back
(
my_point
(
2
,
0
));
//
Triangle
p1.
holes
[
0
].
push_back
(
my_point
(
2
,
1
));
p1.
holes
[
0
].
push_back
(
my_point
(
2.4
,
2
));
p1.
holes
[
0
].
push_back
(
my_point
(
1.9
,
2
));
p1.
holes
[
0
].
push_back
(
my_point
(
2
,
1
));
//
Box
p1.
holes
[
1
].
push_back
(
my_point
(
3
,
3
));
p1.
holes
[
1
].
push_back
(
my_point
(
4
,
3
));
p1.
holes
[
1
].
push_back
(
my_point
(
4
,
4
));
p1.
holes
[
1
].
push_back
(
my_point
(
3
,
4
));
p1.
holes
[
1
].
push_back
(
my_point
(
3
,
3
));
std::cout <<
"
Representation of
"
<< p1.
name
<<
"
:
"
<<
boost::geometry::dsv
(p1) << std::endl;
std::cout <<
"
Area of
"
<< p1.
name
<<
"
:
"
<<
boost::geometry::area
(p1) << std::endl;
std::cout <<
"
Perimeter of
"
<< p1.
name
<<
"
:
"
<<
boost::geometry::perimeter
(p1) << std::endl;
std::cout <<
"
Centroid of
"
<< p1.
name
<<
"
:
"
<<
boost::geometry::dsv
(boost::geometry::return_centroid<my_point>(p1)) << std::endl;
return
0
;
}
You can’t perform that action at this time.