~vibhavp/ubuntu/saucy/urg/merge-from-debian

« back to all changes in this revision

Viewing changes to include/cpp/Position.h

  • Committer: Bazaar Package Importer
  • Author(s): Albert Huang
  • Date: 2011-05-20 11:33:03 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110520113303-u8niofzwzcea0osk
Tags: 0.8.12-1
* New upstream release (closes: #624987)
* Add debian/watch file
* Bump standards-version to 3.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
  \author Satofumi KAMIMURA
11
11
 
12
 
  $Id: Position.h 1584 2009-12-25 23:25:11Z satofumi $
 
12
  $Id: Position.h 1811 2010-04-30 16:12:05Z satofumi $
13
13
*/
14
14
 
15
15
#include "Angle.h"
18
18
 
19
19
namespace qrk
20
20
{
21
 
  /*!
22
 
    \brief �ʒu
23
 
  */
24
 
  template<class T>
25
 
  class Position
26
 
  {
27
 
  public:
28
 
    T x;                        //!< X �ʒu
29
 
    T y;                        //!< Y �ʒu
30
 
    Angle angle;                //!< �p�x
31
 
 
32
 
 
33
 
    Position(void) : x(0), y(0)
34
 
    {
35
 
    }
36
 
 
37
 
 
38
 
    Position(const Position& rhs) : x(rhs.x), y(rhs.y), angle(rhs.angle)
39
 
    {
40
 
    }
41
 
 
42
 
 
43
 
    Position(T x_, T y_, const Angle& angle_) : x(x_), y(y_), angle(angle_)
44
 
    {
45
 
    }
46
 
 
47
 
 
48
 
    int to_deg(void) const
49
 
    {
50
 
      return angle.to_deg();
51
 
    }
52
 
 
53
 
 
54
 
    double to_rad(void) const
55
 
    {
56
 
      return angle.to_rad();
57
 
    }
58
 
 
59
 
 
60
 
    bool operator == (const Position& rhs) const
61
 
    {
62
 
      if ((this->x == rhs.x) && (this->y == rhs.y) &&
63
 
          (this->angle.to_rad() == rhs.angle.to_rad())) {
64
 
        return true;
65
 
      } else {
66
 
        return false;
67
 
      }
68
 
    }
69
 
 
70
 
 
71
 
    Position& operator = (const Position<T>& rhs)
72
 
    {
73
 
      this->x = rhs.x;
74
 
      this->y = rhs.y;
75
 
      this->angle = rhs.angle;
76
 
 
77
 
      return *this;
78
 
    }
79
 
 
80
 
    Position<T>& operator += (const Position<T>& rhs)
81
 
    {
82
 
      this->x += rhs.x;
83
 
      this->y += rhs.y;
84
 
      this->angle += rhs.angle;
85
 
 
86
 
      return *this;
87
 
    }
88
 
 
89
 
 
90
 
    const Position<T> operator + (const Position<T>& rhs) const
91
 
    {
92
 
      return Position<T>(*this) += rhs;
93
 
    }
94
 
 
95
 
 
96
 
    Position<T>& operator -= (const Position<T>& rhs)
97
 
    {
98
 
      this->x -= rhs.x;
99
 
      this->y -= rhs.y;
100
 
      this->angle -= rhs.angle;
101
 
 
102
 
      return *this;
103
 
    }
104
 
 
105
 
 
106
 
    const Position<T> operator - (const Position<T>& rhs) const
107
 
    {
108
 
      return Position<T>(*this) -= rhs;
109
 
    }
110
 
 
111
 
 
112
 
    Position<T>& operator *= (const T& rhs)
113
 
    {
114
 
      this->x *= rhs;
115
 
      this->y *= rhs;
116
 
      this->angle *= rhs;
117
 
 
118
 
      return *this;
119
 
    }
120
 
 
121
 
 
122
 
    Position<T> operator * (const T& rhs) const
123
 
    {
124
 
      Position<T> ret(*this);
125
 
      return ret *= rhs;
126
 
    }
127
 
 
128
 
 
129
 
    friend const Position<T> operator * (const T& lhs, const Position<T>& rhs)
130
 
    {
131
 
      return Position<T>(rhs) * lhs;
132
 
    }
133
 
 
134
 
 
135
 
    friend std::ostream& operator << (std::ostream& out,
136
 
                                      const Position<T>& rhs)
137
 
    {
138
 
      out << '(' << rhs.x << ", " << rhs.y
139
 
          << ", deg(" << rhs.angle.to_deg() << "))";
140
 
 
141
 
      return out;
142
 
    }
143
 
  };
 
21
    /*!
 
22
      \brief �ʒu
 
23
    */
 
24
    template<class T>
 
25
    class Position
 
26
    {
 
27
    public:
 
28
        T x;                        //!< X �ʒu
 
29
        T y;                        //!< Y �ʒu
 
30
        Angle angle;                //!< �p�x
 
31
 
 
32
 
 
33
        Position(void) : x(0), y(0)
 
34
        {
 
35
        }
 
36
 
 
37
 
 
38
        Position(const Position& rhs) : x(rhs.x), y(rhs.y), angle(rhs.angle)
 
39
        {
 
40
        }
 
41
 
 
42
 
 
43
        Position(T x_, T y_, const Angle& angle_) : x(x_), y(y_), angle(angle_)
 
44
        {
 
45
        }
 
46
 
 
47
 
 
48
        int to_deg(void) const
 
49
        {
 
50
            return angle.to_deg();
 
51
        }
 
52
 
 
53
 
 
54
        double to_rad(void) const
 
55
        {
 
56
            return angle.to_rad();
 
57
        }
 
58
 
 
59
 
 
60
        bool operator == (const Position& rhs) const
 
61
        {
 
62
            if ((this->x == rhs.x) && (this->y == rhs.y) &&
 
63
                (this->angle.to_rad() == rhs.angle.to_rad())) {
 
64
                return true;
 
65
            } else {
 
66
                return false;
 
67
            }
 
68
        }
 
69
 
 
70
 
 
71
        Position& operator = (const Position<T>& rhs)
 
72
        {
 
73
            this->x = rhs.x;
 
74
            this->y = rhs.y;
 
75
            this->angle = rhs.angle;
 
76
 
 
77
            return *this;
 
78
        }
 
79
 
 
80
        Position<T>& operator += (const Position<T>& rhs)
 
81
        {
 
82
            this->x += rhs.x;
 
83
            this->y += rhs.y;
 
84
            this->angle += rhs.angle;
 
85
 
 
86
            return *this;
 
87
        }
 
88
 
 
89
 
 
90
        const Position<T> operator + (const Position<T>& rhs) const
 
91
        {
 
92
            return Position<T>(*this) += rhs;
 
93
        }
 
94
 
 
95
 
 
96
        Position<T>& operator -= (const Position<T>& rhs)
 
97
        {
 
98
            this->x -= rhs.x;
 
99
            this->y -= rhs.y;
 
100
            this->angle -= rhs.angle;
 
101
 
 
102
            return *this;
 
103
        }
 
104
 
 
105
 
 
106
        const Position<T> operator - (const Position<T>& rhs) const
 
107
        {
 
108
            return Position<T>(*this) -= rhs;
 
109
        }
 
110
 
 
111
 
 
112
        Position<T>& operator *= (const T& rhs)
 
113
        {
 
114
            this->x *= rhs;
 
115
            this->y *= rhs;
 
116
            this->angle *= rhs;
 
117
 
 
118
            return *this;
 
119
        }
 
120
 
 
121
 
 
122
        Position<T> operator * (const T& rhs) const
 
123
        {
 
124
            Position<T> ret(*this);
 
125
            return ret *= rhs;
 
126
        }
 
127
 
 
128
 
 
129
        friend const Position<T> operator * (const T& lhs,
 
130
                                             const Position<T>& rhs)
 
131
        {
 
132
            return Position<T>(rhs) * lhs;
 
133
        }
 
134
 
 
135
 
 
136
        friend std::ostream& operator << (std::ostream& out,
 
137
                                          const Position<T>& rhs)
 
138
        {
 
139
            out << '(' << rhs.x << ", " << rhs.y
 
140
                << ", deg(" << rhs.angle.to_deg() << "))";
 
141
 
 
142
            return out;
 
143
        }
 
144
    };
144
145
}
145
146
 
146
147
#endif /* !QRK_POSITION_H */