Coords.hpp
Go to the documentation of this file.
1 // Copyright (C) 2021 COGIP Robotics association <cogip35@gmail.com>
2 // This file is subject to the terms and conditions of the GNU Lesser
3 // General Public License v2.1. See the file LICENSE in the top level
4 // directory for more details.
5 
11 
12 #pragma once
13 
14 #include "PB_Coords.hpp"
15 
16 namespace cogip {
17 
18 namespace cogip_defs {
19 
21 class Coords {
22 public:
25  double x=0.0,
26  double y=0.0
27  ) : x_(x), y_(y) {};
28 
30  explicit Coords(const PB_Coords &coords) : x_(coords.get_x()), y_(coords.get_y()) {};
31 
33  double x(void) const { return x_; };
34 
36  double y(void) const { return y_; };
37 
39  void set_x(
40  double x
41  ) { x_ = x; };
42 
44  void set_y(
45  double y
46  ) { y_ = y; };
47 
49  double distance(
50  const Coords &dest
51  ) const;
52 
55  bool on_segment(
56  const Coords &a,
57  const Coords &b
58  ) const;
59 
63  const Coords other
64  ) const { return x_ == other.x_ && y_ == other.y_; };
65 
67  void pb_copy(
68  PB_Coords &coords
69  ) const {
70  coords.set_x(x_);
71  coords.set_y(y_);
72  };
73 
74 protected:
75  double x_;
76  double y_;
77 };
78 
79 } // namespace cogip_defs
80 
81 } // namespace cogip
82 
cogip::cogip_defs::Coords::y_
double y_
y-position
Definition: Coords.hpp:76
cogip::cogip_defs::Coords::set_x
void set_x(double x)
Set X coordinate.
Definition: Coords.hpp:39
cogip::cogip_defs::Coords::y
double y(void) const
Return Y coordinate.
Definition: Coords.hpp:36
cogip::cogip_defs::Coords::Coords
Coords(const PB_Coords &coords)
Constructor from Protobuf class.
Definition: Coords.hpp:30
cogip
Differential drive controller.
Definition: Coords.hpp:16
cogip::cogip_defs::Coords::operator==
bool operator==(const Coords other) const
Check if this point is equal to another.
Definition: Coords.hpp:62
cogip::cogip_defs::Coords::distance
double distance(const Coords &dest) const
Compute the distance the destination point.
cogip::cogip_defs::Coords::pb_copy
void pb_copy(PB_Coords &coords) const
Copy data to Protobuf message.
Definition: Coords.hpp:67
cogip::cogip_defs::Coords::x_
double x_
x-position
Definition: Coords.hpp:72
cogip::cogip_defs::Coords::Coords
Coords(double x=0.0, double y=0.0)
Constructor.
Definition: Coords.hpp:24
cogip::cogip_defs::Coords::on_segment
bool on_segment(const Coords &a, const Coords &b) const
Check if this point is placed on a segment defined by two points A,B.
cogip::cogip_defs::Coords
Absolute coordinates along X and Y axis.
Definition: Coords.hpp:21
cogip::cogip_defs::Coords::set_y
void set_y(double y)
Set Y coordinate.
Definition: Coords.hpp:44
cogip::cogip_defs::Coords::x
double x(void) const
Return X coordinate.
Definition: Coords.hpp:33