FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geometry/example/c04_b_custom_triangle_example.cpp at develop · boostorg/geometry · GitHub
boostorg
geometry
Repository navigation
Code
Issues
145
(145)
Pull requests
14
(14)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
geometry
/
example
/
c04_b_custom_triangle_example.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (53 loc) · 2.11 KB
Breadcrumbs
geometry
/
example
/
c04_b_custom_triangle_example.cpp
Copy path
File metadata and controls
72 lines (53 loc) · 2.11 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
//
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 triangle template Example
#
include
<
array
>
#
include
<
iostream
>
#
include
<
boost/tuple/tuple.hpp
>
#
include
<
boost/geometry/algorithms/area.hpp
>
#
include
<
boost/geometry/algorithms/centroid.hpp
>
#
include
<
boost/geometry/geometries/adapted/boost_tuple.hpp
>
#
include
<
boost/geometry/geometries/register/ring.hpp
>
#
include
<
boost/geometry/strategies/strategies.hpp
>
#
include
<
boost/geometry/io/dsv/write.hpp
>
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS
(cs::cartesian)
template
<
typename
P>
struct
triangle
:
public
std
::array<P,
3
>
{
};
//
Register triangle<P> as a ring
BOOST_GEOMETRY_REGISTER_RING_TEMPLATED
(triangle)
namespace
boost
{
namespace
geometry
{
namespace
dispatch
{
//
Specializations of area dispatch structure, implement algorithm
template
<
typename
Point>
struct
area
<triangle<Point>, ring_tag>
{
template
<
typename
Strategy>
static
inline
double
apply
(triangle<Point>
const
& t, Strategy
const
&)
{
return
0.5
* ((get<
0
>(t[
1
]) - get<
0
>(t[
0
])) * (get<
1
>(t[
2
]) - get<
1
>(t[
0
]))
- (get<
0
>(t[
2
]) - get<
0
>(t[
0
])) * (get<
1
>(t[
1
]) - get<
1
>(t[
0
])));
}
};
}}}
//
namespace boost::geometry::dispatch
int
main
()
{
//
triangle<boost::geometry::point_xy<double> > t;
triangle<boost::tuple<
double
,
double
> > t;
t[
0
] =
boost::make_tuple
(
0
,
0
);
t[
1
] =
boost::make_tuple
(
5
,
0
);
t[
2
] =
boost::make_tuple
(
2.5
,
2.5
);
std::cout <<
"
Triangle:
"
<<
boost::geometry::dsv
(t) << std::endl;
std::cout <<
"
Area:
"
<<
boost::geometry::area
(t) << std::endl;
//
boost::geometry::point_xy<double> c;
boost::tuple<
double
,
double
> c;
boost::geometry::centroid
(t, c);
std::cout <<
"
Centroid:
"
<<
boost::geometry::dsv
(c) << std::endl;
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL