YARP
Yet Another Robot Platform
Vec2D.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_MATH_VEC2D_H
7 #define YARP_MATH_VEC2D_H
8 
9 #include <yarp/math/api.h>
10 
11 #include <yarp/os/Portable.h>
12 
13 #include <yarp/sig/Matrix.h>
14 #include <yarp/sig/Vector.h>
15 
16 #include <type_traits>
17 
18 namespace yarp {
19 namespace math {
20 
21 template <typename T>
23  public yarp::os::Portable
24 {
25  static_assert(std::is_same<size_t, T>::value || std::is_same<int, T>::value || std::is_same<double, T>::value, "Vec2D can be specialized only as size_t, int, double");
26 
27 public:
28  T x;
29  T y;
30 
31  Vec2D<T>();
32  Vec2D<T>(const T& x_value, const T& y_value);
33  Vec2D<T>(const yarp::sig::Vector& v);
34  explicit operator yarp::sig::Vector() const
35  {
36  yarp::sig::Vector v(2);
37  v[0] = double(x);
38  v[1] = double(y);
39  return v;
40  }
41 
46  T norm() const;
47 
52  std::string toString(int precision = -1, int width = -1) const;
53 
55  /*
56  * Read vector from a connection.
57  * return true if a Vec2D was read correctly
58  */
59  bool read(yarp::os::ConnectionReader& connection) override;
60 
65  bool write(yarp::os::ConnectionWriter& connection) const override;
66 
67  yarp::os::Type getType() const override
68  {
69  return yarp::os::Type::byName("yarp/vec2D");
70  }
71 
72  //operators
75  bool operator==(const yarp::math::Vec2D<T>& rhs) const;
76  bool operator!=(const yarp::math::Vec2D<T>& rhs) const;
77 };
78 
79 } // namespace math
80 } // namespace yarp
81 
82 // Forward declarations of specialized methods
89 
90 // Forward declaration of explicit instantiated template classes
91 YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<double>;
92 YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<int>;
93 YARP_math_EXTERN template class /*YARP_math_API*/ yarp::math::Vec2D<size_t>;
94 
95 
96 
97 //operators
98 template <typename T>
100 
101 template <typename T>
103 
104 template <typename T>
106 
107 // Forward declaration of explicit instantiated template functions
114 
115 
116 #endif // YARP_MATH_VEC2D_H
contains the definition of a Matrix type
yarp::math::Vec2D< T > operator*(const yarp::sig::Matrix &lhs, yarp::math::Vec2D< T > rhs)
Definition: Vec2D.cpp:206
yarp::math::Vec2D< T > operator-(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition: Vec2D.cpp:223
yarp::math::Vec2D< T > operator+(yarp::math::Vec2D< T > lhs, const yarp::math::Vec2D< T > &rhs)
Definition: Vec2D.cpp:216
contains the definition of a Vector type
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
yarp::os::Type getType() const override
Definition: Vec2D.h:67
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
static Type byName(const char *name)
Definition: Type.cpp:171
A class for a Matrix.
Definition: Matrix.h:43
std::string toString(const T &value)
convert an arbitrary type to string.
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition: math.cpp:38
Vector & operator-=(Vector &a, const double &s)
Subtraction operator between a vector and a scalar (defined in Math.h).
Definition: math.cpp:98
double norm(const yarp::sig::Vector &v)
Returns the Euclidean norm of the vector (defined in Math.h).
Definition: math.cpp:538
VectorOf< double > Vector
Definition: Vector.h:30
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_math_API
Definition: api.h:17
#define YARP_math_EXTERN
Definition: api.h:18