|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __HUIREALPOINT_H__ |
|
21 #define __HUIREALPOINT_H__ |
|
22 |
|
23 |
|
24 #include <uiacceltk/HuiRealSize.h> |
|
25 |
|
26 |
|
27 /** |
|
28 * Point composed of two floating-point components. |
|
29 */ |
|
30 NONSHARABLE_CLASS(THuiRealPoint) |
|
31 { |
|
32 public: |
|
33 inline THuiRealPoint() |
|
34 : iX(0), iY(0) |
|
35 { |
|
36 } |
|
37 |
|
38 inline THuiRealPoint(TReal32 aX, TReal32 aY) |
|
39 : iX(aX), iY(aY) |
|
40 { |
|
41 } |
|
42 |
|
43 inline THuiRealPoint(const TPoint& aPoint) |
|
44 : iX((TReal32)aPoint.iX), iY((TReal32)aPoint.iY) |
|
45 { |
|
46 } |
|
47 |
|
48 inline THuiRealSize AsSize() const |
|
49 { |
|
50 return THuiRealSize(iX, iY); |
|
51 } |
|
52 |
|
53 inline operator TPoint() const |
|
54 { |
|
55 // Here is a rounding error! |
|
56 return TPoint((TInt)iX, (TInt)iY); |
|
57 } |
|
58 |
|
59 inline TPoint Round() const |
|
60 { |
|
61 TPoint rounded; |
|
62 rounded.iX = HUI_ROUND_FLOAT_TO_INT( iX ); |
|
63 rounded.iY = HUI_ROUND_FLOAT_TO_INT( iY ); |
|
64 return rounded; |
|
65 } |
|
66 |
|
67 inline THuiRealPoint operator + (const THuiRealPoint& aOther) const |
|
68 { |
|
69 return THuiRealPoint(iX + aOther.iX, iY + aOther.iY); |
|
70 } |
|
71 |
|
72 inline THuiRealPoint& operator += (const THuiRealPoint& aOther) |
|
73 { |
|
74 iX += aOther.iX; |
|
75 iY += aOther.iY; |
|
76 return *this; |
|
77 } |
|
78 |
|
79 inline THuiRealPoint& operator -= (const THuiRealPoint& aOther) |
|
80 { |
|
81 iX -= aOther.iX; |
|
82 iY -= aOther.iY; |
|
83 return *this; |
|
84 } |
|
85 |
|
86 inline THuiRealPoint operator - () const |
|
87 { |
|
88 return THuiRealPoint(-iX, -iY); |
|
89 } |
|
90 |
|
91 inline THuiRealPoint operator - (const THuiRealPoint& aOther) const |
|
92 { |
|
93 return THuiRealPoint(iX - aOther.iX, iY - aOther.iY); |
|
94 } |
|
95 |
|
96 inline THuiRealPoint operator * (TReal32 aFactor) const |
|
97 { |
|
98 return THuiRealPoint(iX * aFactor, iY * aFactor); |
|
99 } |
|
100 |
|
101 inline THuiRealPoint Abs() const |
|
102 { |
|
103 return THuiRealPoint(iX<0?-iX:iX, iY<0?-iY:iY); |
|
104 } |
|
105 |
|
106 public: |
|
107 |
|
108 /** X coordinate. */ |
|
109 TReal32 iX; |
|
110 |
|
111 /** Y coordinate. */ |
|
112 TReal32 iY; |
|
113 |
|
114 }; |
|
115 |
|
116 #endif // __HUIREALPOINT_H__ |