• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #ifndef POINT_H
19 #define POINT_H
20 
21 #ifndef STRINGABLE_H
22 #include "stringable.h"
23 #endif
24 #include <stdio.h>
25 
26 //@doc
27 
28 
29 //@class a simple 2-d point class.  This is used for graphics placement, etc.
30 template < class T > class point : public stringable
31 {
32         //@access public data members
33     public:
34         typedef point < T > t_point;
35         //@cmember the x coordinate of the point
36         T x;
37         //@cmember the y coordinate of the point
38         T y;
39         //@access public methods
40     public:
41         //@cmember default constructor
point(void)42         point(void): x(0), y(0)
43         {
44         };
45         //@cmember copy constructor
point(const t_point & rhs)46         point(const t_point & rhs): x(rhs.x), y(rhs.y)
47         {
48         };
49         //@cmember specific constructor
point(const T & new_x,const T & new_y)50         point(const T & new_x, const T & new_y): x(new_x), y(new_y)
51         {
52         };
53         //@cmember equality comparison operator
54         bool operator == (const t_point & rhs) const
55         {
56             return ((x == rhs.x) && (y == rhs.y));
57         };
58         //@cmember inequality comparison operator
59         bool operator != (const t_point & rhs) const
60         {
61             return !((*this) == rhs);
62         };
63         //@cmember adds a point to this point
64         t_point & operator += (const t_point & rhs)
65         {
66             x += rhs.x;
67             y += rhs.y;
68             return (*this);
69         };
70         //@cmember subtracts a point from this point
71         t_point & operator -= (const t_point & rhs)
72         {
73             x -= rhs.x;
74             y -= rhs.y;
75             return (*this);
76         };
77         //@cmember adds two points
78         t_point operator + (const t_point & rhs) const
79         {
80             return t_point(x + rhs.x, y + rhs.y);
81         };
82         //@cmember subtracts two points
83         t_point operator - (const t_point & rhs) const
84         {
85             return t_point(x - rhs.x, y - rhs.y);
86         };
87         //@cmember equals operator
88         t_point & operator = (const t_point & rhs)
89         {
90             x = rhs.x; //should be x;
91             y = rhs.y;
92             return (*this);
93         };
94         //@cmember returns a string representing the point -- note: uses sprintf(); only works correctly for int points
95         //just here to demonstrate to_string
to_string(void)96         virtual std::string to_string(void) const
97         {
98             std::string Result = "(";
99             char temp[100];
100             sprintf(temp, "%d", x);
101             Result.append(temp);
102             Result.append(", ");
103             sprintf(temp, "%d", y);
104             Result.append(temp);
105             Result.append(")");
106             return Result;
107         };
108 };
109 
110 //@type int_point | commonly used element: a <c point> made up of ints
111 typedef point < int >int_point;
112 
113 
114 #endif
115 
116