FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geometry/example/c01_custom_point_example.cpp at develop · boostorg/geometry · GitHub
boostorg
geometry
Repository navigation
Code
Issues
146
(146)
Pull requests
15
(15)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
geometry
/
example
/
c01_custom_point_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
160 lines (133 loc) · 4.92 KB
Breadcrumbs
geometry
/
example
/
c01_custom_point_example.cpp
Copy path
File metadata and controls
160 lines (133 loc) · 4.92 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
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 point Example
#
include
<
iostream
>
#
include
<
boost/geometry/algorithms/distance.hpp
>
#
include
<
boost/geometry/algorithms/make.hpp
>
#
include
<
boost/geometry/geometries/register/point.hpp
>
#
include
<
boost/geometry/strategies/strategies.hpp
>
#
include
<
boost/geometry/io/dsv/write.hpp
>
//
Sample point, defining three color values
struct
my_color_point
{
double
red, green, blue;
};
//
Sample point, having an int array defined
struct
my_array_point
{
int
c[
3
];
};
//
Sample point, having x/y
struct
my_2d
{
float
x,y;
};
//
Sample class, protected and construction-time-only x/y,
//
Can (of course) only used in algorithms which take const& points
class
my_class_ro
{
public:
my_class_ro
(
double
x,
double
y) : m_x(x), m_y(y) {}
double
x
()
const
{
return
m_x; }
double
y
()
const
{
return
m_y; }
private:
double
m_x, m_y;
};
//
Sample class using references for read/write
class
my_class_rw
{
public:
const
double
&
x
()
const
{
return
m_x; }
const
double
&
y
()
const
{
return
m_y; }
double
&
x
() {
return
m_x; }
double
&
y
() {
return
m_y; }
private:
double
m_x, m_y;
};
//
Sample class using getters / setters
class
my_class_gs
{
public:
const
double
get_x
()
const
{
return
m_x; }
const
double
get_y
()
const
{
return
m_y; }
void
set_x
(
double
v) { m_x = v; }
void
set_y
(
double
v) { m_y = v; }
private:
double
m_x, m_y;
};
//
Sample point within a namespace
namespace
my
{
struct
my_namespaced_point
{
double
x, y;
};
}
BOOST_GEOMETRY_REGISTER_POINT_3D
(my_color_point,
double
, cs::cartesian, red, green, blue)
BOOST_GEOMETRY_REGISTER_POINT_3D
(my_array_point,
int
, cs::cartesian, c[
0
], c[
1
], c[
2
])
BOOST_GEOMETRY_REGISTER_POINT_2D
(my_2d,
float
, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D_CONST
(my_class_ro,
double
, cs::cartesian, x(), y())
BOOST_GEOMETRY_REGISTER_POINT_2D
(my_class_rw,
double
, cs::cartesian, x(), y())
BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET
(my_class_gs,
double
, cs::cartesian, get_x, get_y, set_x, set_y)
BOOST_GEOMETRY_REGISTER_POINT_2D
(my::my_namespaced_point,
double
, cs::cartesian, x, y)
int
main
()
{
//
Create 2 instances of our custom color point
my_color_point c1 = boost::geometry::make<my_color_point>(
255
,
3
,
233
);
my_color_point c2 = boost::geometry::make<my_color_point>(
0
,
50
,
200
);
//
The distance between them can be calculated using the cartesian method (=pythagoras)
//
provided with the library, configured by the coordinate_system type of the point
std::cout <<
"
color distance
"
<<
boost::geometry::dsv
(c1) <<
"
to
"
<<
boost::geometry::dsv
(c2) <<
"
is
"
<<
boost::geometry::distance
(c1,c2) << std::endl;
my_array_point a1 = {{
0
}};
my_array_point a2 = {{
0
}};
boost::geometry::assign_values
(a1,
1
,
2
,
3
);
boost::geometry::assign_values
(a2,
3
,
2
,
1
);
std::cout <<
"
color distance
"
<<
boost::geometry::dsv
(a1) <<
"
to
"
<<
boost::geometry::dsv
(a2) <<
"
is
"
<<
boost::geometry::distance
(a1,a2) << std::endl;
my_2d p1 = {
1
,
5
};
my_2d p2 = {
3
,
4
};
std::cout <<
"
float distance
"
<<
boost::geometry::dsv
(p1) <<
"
to
"
<<
boost::geometry::dsv
(p2) <<
"
is
"
<<
boost::geometry::distance
(p1,p2) << std::endl;
my_class_ro
cro1
(
1
,
2
);
my_class_ro
cro2
(
3
,
4
);
std::cout <<
"
class ro distance
"
<<
boost::geometry::dsv
(cro1) <<
"
to
"
<<
boost::geometry::dsv
(cro2) <<
"
is
"
<<
boost::geometry::distance
(cro1,cro2) << std::endl;
my_class_rw crw1;
my_class_rw crw2;
boost::geometry::assign_values
(crw1,
1
,
2
);
boost::geometry::assign_values
(crw2,
3
,
4
);
std::cout <<
"
class r/w distance
"
<<
boost::geometry::dsv
(crw1) <<
"
to
"
<<
boost::geometry::dsv
(crw2) <<
"
is
"
<<
boost::geometry::distance
(crw1,crw2) << std::endl;
my_class_gs cgs1;
my_class_gs cgs2;
boost::geometry::assign_values
(cgs1,
1
,
2
);
boost::geometry::assign_values
(cgs2,
3
,
4
);
std::cout <<
"
class g/s distance
"
<<
boost::geometry::dsv
(crw1) <<
"
to
"
<<
boost::geometry::dsv
(crw2) <<
"
is
"
<<
boost::geometry::distance
(cgs1,cgs2) << std::endl;
my::my_namespaced_point nsp1 = boost::geometry::make<my::my_namespaced_point>(
1
,
2
);
my::my_namespaced_point nsp2 = boost::geometry::make<my::my_namespaced_point>(
3
,
4
);
std::cout <<
"
namespaced distance
"
<<
boost::geometry::dsv
(nsp1) <<
"
to
"
<<
boost::geometry::dsv
(nsp2) <<
"
is
"
<<
boost::geometry::distance
(nsp1,nsp2) << std::endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL