Vanetza
Loading...
Searching...
No Matches
areas.hpp
1#ifndef AREAS_HPP_CVK1NIAI
2#define AREAS_HPP_CVK1NIAI
3
4#include <vanetza/geodesy/geodesy.hpp>
5#include <vanetza/units/area.hpp>
6#include <boost/variant.hpp>
7
8namespace vanetza
9{
10namespace geonet
11{
12
13using geodesy::CartesianPosition;
14using geodesy::GeodeticPosition;
15using geodesy::distance;
16using geodesy::local_cartesian;
17
18struct Circle
19{
20 Circle() : r(1.0 * units::si::meters) {}
21 units::Length r; // radius
22};
23
25{
26 Rectangle() : a(1.0 * units::si::meters), b(1.0 * units::si::meters) {}
27 units::Length a; // center to long side
28 units::Length b; // center to short side
29};
30
31struct Ellipse
32{
33 Ellipse() : a(1.0 * units::si::meters), b(1.0 * units::si::meters) {}
34 units::Length a; // long semi-axis
35 units::Length b; // short semi-axis
36};
37
38struct Area
39{
40 boost::variant<Rectangle, Ellipse, Circle> shape;
41 GeodeticPosition position;
42 units::Angle angle;
43};
44
45double geometric_function(const Circle&, const CartesianPosition&);
46double geometric_function(const Rectangle&, const CartesianPosition&);
47double geometric_function(const Ellipse&, const CartesianPosition&);
48double geometric_function(const decltype(Area::shape)&, const CartesianPosition&);
49
50/**
51 * Canonicalize a point in a shape's coordinate system w.r.t. its azimuth angle
52 * \param point Point to canonicalize
53 * \param azimuth Azimuth angle of shape's long side
54 * \return canonical position (suitable for geometric_function)
55 */
56CartesianPosition canonicalize(const CartesianPosition& point, units::Angle azimuth);
57
58/**
59 * Check if positon is within or at border of area
60 * \param area with shape, dimensions, azimuth and center point position
61 * \param position Geodetic position to check against area
62 * \return true if position is inside or at border
63 */
64bool inside_or_at_border(const Area&, const GeodeticPosition&);
65
66/**
67 * Calculate area size in square km.
68 * \param area Area object
69 * \return area size
70 */
71units::Area area_size(const Area&);
72
73template<class SHAPE>
74bool inside_shape(const SHAPE& shape, const CartesianPosition& p)
75{
76 return geometric_function(shape, p) > 0.0;
77}
78
79template<class SHAPE>
80bool outside_shape(const SHAPE& shape, const CartesianPosition& p)
81{
82 return geometric_function(shape, p) < 0.0;
83}
84
85template<class SHAPE>
86bool at_shape_border(const SHAPE& shape, const CartesianPosition& p)
87{
88 return geometric_function(shape, p) == 0.0;
89}
90
91template<class SHAPE>
92bool at_center_point(const SHAPE& shape, const CartesianPosition& p)
93{
94 return geometric_function(shape, p) == 1.0;
95}
96
97} // namespace geonet
98} // namespace vanetza
99
100#endif /* AREAS_HPP_CVK1NIAI */
ChunckPacket is a packet consisting of several memory chunks.
ByteBufferConvertible & operator[](OsiLayer ol)
ChunkPacket & merge(ChunkPacket &packet, OsiLayer from, OsiLayer to)
std::size_t size() const
const ByteBufferConvertible & layer(OsiLayer ol) const
const ByteBufferConvertible & operator[](OsiLayer ol) const
ByteBufferConvertible & layer(OsiLayer ol)
std::size_t size(OsiLayer from, OsiLayer to) const
ChunkPacket extract(OsiLayer from, OsiLayer to)
std::size_t size(OsiLayer from, OsiLayer to) const
buffer_const_range operator[](OsiLayer layer) const
std::size_t size() const
void set_boundary(OsiLayer, unsigned bytes)
const ByteBuffer & buffer() const
CohesivePacket(const ByteBuffer &buffer, OsiLayer layer)
void trim(OsiLayer from, unsigned bytes)
std::size_t size(OsiLayer single_layer) const
value_type operator[](size_type) const
Definition byte_view.cpp:48
byte_view_range(ByteBuffer &&)
Definition byte_view.cpp:37
byte_view_range(const ByteBuffer::const_iterator &, const ByteBuffer::const_iterator &)
Definition byte_view.cpp:27
ByteBuffer::const_pointer data() const
Definition byte_view.cpp:42