|
1 /* |
|
2 * Copyright (c) 2002 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: Graphics Extension Library header file |
|
15 * |
|
16 */ |
|
17 |
|
18 extern "C" { |
|
19 #include "Gfxmath.h" |
|
20 } |
|
21 #ifdef SVG_FLOAT_BUILD |
|
22 // ========================================================================== |
|
23 // Constructor, default to zero |
|
24 // ========================================================================== |
|
25 inline TFloatFixPt::TFloatFixPt() : iValue( 0 ) |
|
26 { |
|
27 } |
|
28 |
|
29 // ========================================================================== |
|
30 // Constructor |
|
31 // ========================================================================== |
|
32 |
|
33 inline TFloatFixPt::TFloatFixPt( TInt aVal ) |
|
34 { |
|
35 iValue = float(aVal); |
|
36 } |
|
37 |
|
38 // ========================================================================== |
|
39 // Constructor |
|
40 // ========================================================================== |
|
41 inline TFloatFixPt::TFloatFixPt( TInt32 aVal ) |
|
42 { |
|
43 iValue = float(aVal); |
|
44 } |
|
45 |
|
46 // ========================================================================== |
|
47 // Constructor |
|
48 // ========================================================================== |
|
49 inline TFloatFixPt::TFloatFixPt( TReal32 aVal ) |
|
50 { |
|
51 iValue = aVal; |
|
52 } |
|
53 |
|
54 // ========================================================================== |
|
55 // Copy constructor |
|
56 // ========================================================================== |
|
57 inline TFloatFixPt::TFloatFixPt( const TFloatFixPt& aFixpt ) |
|
58 { |
|
59 iValue = aFixpt.iValue; |
|
60 } |
|
61 |
|
62 // ========================================================================== |
|
63 // Conversion to TInt32 operator |
|
64 // ========================================================================== |
|
65 inline TFloatFixPt::operator TInt32() const |
|
66 { |
|
67 return ((TInt32)iValue); |
|
68 } |
|
69 |
|
70 // ========================================================================== |
|
71 // Conversion to TInt operator |
|
72 // ========================================================================== |
|
73 inline TFloatFixPt::operator TInt() const |
|
74 { |
|
75 return ((TInt)iValue); |
|
76 } |
|
77 |
|
78 // ========================================================================== |
|
79 // Conversion to TReal32 operator |
|
80 // ========================================================================== |
|
81 inline TFloatFixPt::operator TReal32() const |
|
82 { |
|
83 return iValue; |
|
84 } |
|
85 |
|
86 // ========================================================================== |
|
87 // Assignment operator |
|
88 // ========================================================================== |
|
89 inline TFloatFixPt& TFloatFixPt::operator=( TInt32 aVal ) |
|
90 |
|
91 { |
|
92 iValue = (float)aVal; |
|
93 return *this; |
|
94 } |
|
95 |
|
96 // ========================================================================== |
|
97 // Assignment operator |
|
98 // ========================================================================== |
|
99 inline TFloatFixPt& TFloatFixPt::operator=( TInt aVal ) |
|
100 { |
|
101 iValue = (float)aVal; |
|
102 return *this; |
|
103 } |
|
104 |
|
105 // ========================================================================== |
|
106 // Assignment operator |
|
107 // ========================================================================== |
|
108 inline TFloatFixPt& TFloatFixPt::operator=( TReal32 aVal ) |
|
109 { |
|
110 iValue = aVal; |
|
111 return *this; |
|
112 } |
|
113 |
|
114 // ========================================================================== |
|
115 // Addition Assignment operator |
|
116 // ========================================================================== |
|
117 inline TFloatFixPt& TFloatFixPt::operator+=( const TFloatFixPt& aVal ) |
|
118 { |
|
119 iValue += aVal.iValue; |
|
120 return*this; |
|
121 } |
|
122 |
|
123 // ========================================================================== |
|
124 // Subtraction Assignment operator |
|
125 // ========================================================================== |
|
126 inline TFloatFixPt& TFloatFixPt::operator-=( const TFloatFixPt& aVal ) |
|
127 { |
|
128 iValue -= aVal.iValue; |
|
129 return *this; |
|
130 } |
|
131 |
|
132 |
|
133 // ========================================================================== |
|
134 // Multipication Assignment operator |
|
135 // ========================================================================== |
|
136 inline TFloatFixPt& TFloatFixPt::operator*=( const TFloatFixPt& aVal ) |
|
137 { |
|
138 iValue *= aVal.iValue; |
|
139 return *this; |
|
140 } |
|
141 |
|
142 |
|
143 |
|
144 // ========================================================================== |
|
145 // Division Assignment operator |
|
146 // Note: This may require more optimization... |
|
147 // ========================================================================== |
|
148 inline TFloatFixPt& TFloatFixPt::operator/=( const TFloatFixPt& aVal ) |
|
149 { |
|
150 iValue /= aVal.iValue; |
|
151 return *this; |
|
152 } |
|
153 |
|
154 // =================================================================== |
|
155 // Addition operation |
|
156 // ========================================================================== |
|
157 inline TFloatFixPt TFloatFixPt::operator+( const TFloatFixPt& aVal ) const |
|
158 { |
|
159 return TFloatFixPt( iValue + aVal.iValue ); |
|
160 } |
|
161 |
|
162 // =================================================================== |
|
163 // Addition operation |
|
164 // ========================================================================== |
|
165 inline TFloatFixPt TFloatFixPt::operator+( const double& aVal ) const |
|
166 { |
|
167 return TFloatFixPt( iValue + (float)aVal ); |
|
168 } |
|
169 |
|
170 // =================================================================== |
|
171 // Addition operation |
|
172 // ========================================================================== |
|
173 inline TFloatFixPt TFloatFixPt::operator+( const float& aVal ) const |
|
174 { |
|
175 return TFloatFixPt( iValue + aVal ); |
|
176 } |
|
177 |
|
178 // ========================================================================== |
|
179 // Subtraction operation |
|
180 // ========================================================================== |
|
181 inline TFloatFixPt TFloatFixPt::operator-( const TFloatFixPt& aVal ) const |
|
182 { |
|
183 return TFloatFixPt( iValue - aVal.iValue ); |
|
184 } |
|
185 |
|
186 // ========================================================================== |
|
187 // Subtraction operation |
|
188 // ========================================================================== |
|
189 inline TFloatFixPt TFloatFixPt::operator-( const double aVal ) const |
|
190 { |
|
191 float difference = iValue - aVal; |
|
192 return TFloatFixPt( difference ); |
|
193 } |
|
194 |
|
195 // ========================================================================== |
|
196 // Subtraction operation |
|
197 // ========================================================================== |
|
198 inline TFloatFixPt TFloatFixPt::operator-( const float aVal ) const |
|
199 { |
|
200 return TFloatFixPt( iValue - aVal ); |
|
201 } |
|
202 |
|
203 // ========================================================================== |
|
204 // Multiplication operator |
|
205 // ========================================================================== |
|
206 |
|
207 inline TFloatFixPt TFloatFixPt::operator*( const TFloatFixPt& aVal ) const |
|
208 { |
|
209 TFloatFixPt tmp( iValue ); |
|
210 tmp *= aVal; |
|
211 return tmp; |
|
212 } |
|
213 |
|
214 // ========================================================================== |
|
215 // Multiplication operator |
|
216 // ========================================================================== |
|
217 inline TFloatFixPt TFloatFixPt::operator*( const double aVal ) const |
|
218 { |
|
219 float multans = iValue * aVal; |
|
220 return TFloatFixPt(multans); |
|
221 } |
|
222 |
|
223 // ========================================================================== |
|
224 // Multiplication operator |
|
225 // ========================================================================== |
|
226 inline TFloatFixPt TFloatFixPt::operator*( const float aVal ) const |
|
227 { |
|
228 return TFloatFixPt(iValue * aVal); |
|
229 } |
|
230 |
|
231 // ========================================================================== |
|
232 // Division operator |
|
233 // ========================================================================== |
|
234 inline TFloatFixPt TFloatFixPt::operator/( const TFloatFixPt& aVal ) const |
|
235 { |
|
236 TFloatFixPt tmp( iValue ); |
|
237 tmp /= aVal; |
|
238 return tmp; |
|
239 } |
|
240 |
|
241 // ========================================================================== |
|
242 // Division operator |
|
243 // ========================================================================== |
|
244 inline TFloatFixPt TFloatFixPt::operator/( const double aVal ) const |
|
245 { |
|
246 float divans = iValue / aVal; |
|
247 return TFloatFixPt(divans); |
|
248 } |
|
249 |
|
250 // ========================================================================== |
|
251 // Division operator |
|
252 // ========================================================================== |
|
253 inline TFloatFixPt TFloatFixPt::operator/( const float aVal ) const |
|
254 { |
|
255 return TFloatFixPt(iValue / aVal); |
|
256 } |
|
257 |
|
258 // ========================================================================== |
|
259 // Equals operator |
|
260 // ========================================================================== |
|
261 inline TInt TFloatFixPt::operator==( const TFloatFixPt& aVal ) const |
|
262 { |
|
263 return ( iValue == aVal.iValue ); |
|
264 } |
|
265 |
|
266 // ========================================================================== |
|
267 // Not Equals operator |
|
268 // ========================================================================== |
|
269 inline TInt TFloatFixPt::operator!=( const TFloatFixPt& aVal ) const |
|
270 { |
|
271 return ( iValue != aVal.iValue ); |
|
272 } |
|
273 |
|
274 // ========================================================================== |
|
275 // Greater than or equal to operator |
|
276 // ========================================================================== |
|
277 inline TInt TFloatFixPt::operator>=( const TFloatFixPt& aVal ) const |
|
278 { |
|
279 return ( iValue >= aVal.iValue ); |
|
280 } |
|
281 |
|
282 // ========================================================================== |
|
283 // Less than or equal to operator |
|
284 // ========================================================================== |
|
285 inline TInt TFloatFixPt::operator<=( const TFloatFixPt& aVal ) const |
|
286 { |
|
287 return ( iValue <= aVal.iValue ); |
|
288 } |
|
289 |
|
290 // ========================================================================== |
|
291 // Greater than operator |
|
292 // ========================================================================== |
|
293 inline TInt TFloatFixPt::operator>( const TFloatFixPt& aVal ) const |
|
294 { |
|
295 return ( iValue > aVal.iValue ); |
|
296 } |
|
297 |
|
298 // ========================================================================== |
|
299 // Less than operator |
|
300 // ========================================================================== |
|
301 inline TInt TFloatFixPt::operator<( const TFloatFixPt& aVal ) const |
|
302 { |
|
303 return ( iValue < aVal.iValue ); |
|
304 } |
|
305 |
|
306 // ========================================================================== |
|
307 // Round to the nearest whole number |
|
308 // ========================================================================== |
|
309 inline TInt32 TFloatFixPt::Round() |
|
310 { |
|
311 TInt aInt = (TInt)iValue; |
|
312 return (TInt32)aInt; |
|
313 } |
|
314 |
|
315 // ========================================================================== |
|
316 // Get 32-bit representation |
|
317 // ========================================================================== |
|
318 inline TInt32 TFloatFixPt::RawData() |
|
319 { |
|
320 return ((TInt32)iValue); |
|
321 } |
|
322 |
|
323 |
|
324 #else |
|
325 |
|
326 #define FIXPT_USE_INTS |
|
327 |
|
328 // ========================================================================== |
|
329 // Constructor, default to zero |
|
330 // ========================================================================== |
|
331 inline TFloatFixPt::TFloatFixPt() : iValue( 0 ) |
|
332 { |
|
333 } |
|
334 |
|
335 // ========================================================================== |
|
336 // Constructor |
|
337 // ========================================================================== |
|
338 |
|
339 inline TFloatFixPt::TFloatFixPt( TInt aVal ) |
|
340 { |
|
341 iValue = ( aVal << KFixPtFrac ); |
|
342 } |
|
343 |
|
344 inline TFloatFixPt::TFloatFixPt( TInt aVal, TBool /*a*/ ) |
|
345 { |
|
346 iValue = aVal; |
|
347 } |
|
348 |
|
349 // ========================================================================== |
|
350 // Constructor |
|
351 // ========================================================================== |
|
352 inline TFloatFixPt::TFloatFixPt( TInt32 aVal ) |
|
353 { |
|
354 iValue = ( aVal << KFixPtFrac ); |
|
355 } |
|
356 |
|
357 // ========================================================================== |
|
358 // Constructor |
|
359 // ========================================================================== |
|
360 inline TFloatFixPt::TFloatFixPt( TReal32 aVal ) |
|
361 { |
|
362 iValue = svgScalarFromFloat(aVal);//( TInt32 ) ( aVal * KFixPtFracVal ); |
|
363 } |
|
364 |
|
365 // ========================================================================== |
|
366 // Copy constructor |
|
367 // ========================================================================== |
|
368 inline TFloatFixPt::TFloatFixPt( const TFloatFixPt& aFixpt ) |
|
369 { |
|
370 iValue = aFixpt.iValue; |
|
371 } |
|
372 |
|
373 // ========================================================================== |
|
374 // Return the fractional portion as an integer |
|
375 // ========================================================================== |
|
376 inline TInt32 TFloatFixPt::FracAsInt() |
|
377 { |
|
378 return iValue & 0xFFFF; |
|
379 } |
|
380 |
|
381 // ========================================================================== |
|
382 // Conversion to TInt32 operator |
|
383 // ========================================================================== |
|
384 inline TFloatFixPt::operator TInt32() const |
|
385 { |
|
386 return ( iValue >> KFixPtFrac ); |
|
387 } |
|
388 |
|
389 // ========================================================================== |
|
390 // Conversion to TInt operator |
|
391 // ========================================================================== |
|
392 inline TFloatFixPt::operator TInt() const |
|
393 { |
|
394 return ( iValue >> KFixPtFrac ); |
|
395 } |
|
396 |
|
397 // ========================================================================== |
|
398 // Conversion to TReal32 operator |
|
399 // ========================================================================== |
|
400 inline TFloatFixPt::operator TReal32() const |
|
401 { |
|
402 #ifdef FIXPT_USE_INTS |
|
403 return svgFixedToFloat(iValue); |
|
404 #else |
|
405 return ( ( TReal32 ) iValue ) / KFixPtFracVal; |
|
406 #endif |
|
407 } |
|
408 |
|
409 // ========================================================================== |
|
410 // Assignment operator |
|
411 // ========================================================================== |
|
412 inline TFloatFixPt& TFloatFixPt::operator=( TInt32 aVal ) |
|
413 |
|
414 { |
|
415 iValue = ( aVal << KFixPtFrac ); |
|
416 return *this; |
|
417 } |
|
418 |
|
419 // ========================================================================== |
|
420 // Assignment operator |
|
421 // ========================================================================== |
|
422 inline TFloatFixPt& TFloatFixPt::operator=( TInt aVal ) |
|
423 { |
|
424 iValue = ( aVal << KFixPtFrac ); |
|
425 return *this; |
|
426 } |
|
427 |
|
428 // ========================================================================== |
|
429 // Assignment operator |
|
430 // ========================================================================== |
|
431 inline TFloatFixPt& TFloatFixPt::operator=( TReal32 aVal ) |
|
432 { |
|
433 iValue = svgScalarFromFloat(aVal);//( TInt32 ) ( aVal * KFixPtFracVal ); |
|
434 return *this; |
|
435 } |
|
436 |
|
437 // ========================================================================== |
|
438 // Addition Assignment operator |
|
439 // ========================================================================== |
|
440 inline TFloatFixPt& TFloatFixPt::operator+=( const TFloatFixPt& aVal ) |
|
441 { |
|
442 iValue += aVal.iValue; |
|
443 return*this; |
|
444 } |
|
445 |
|
446 // ========================================================================== |
|
447 // Subtraction Assignment operator |
|
448 // ========================================================================== |
|
449 inline TFloatFixPt& TFloatFixPt::operator-=( const TFloatFixPt& aVal ) |
|
450 { |
|
451 iValue -= aVal.iValue; |
|
452 return *this; |
|
453 } |
|
454 |
|
455 |
|
456 // ========================================================================== |
|
457 // Multipication Assignment operator |
|
458 // ========================================================================== |
|
459 inline TFloatFixPt& TFloatFixPt::operator*=( const TFloatFixPt& aVal ) |
|
460 { |
|
461 #ifdef FIXPT_USE_INTS |
|
462 iValue = svgScalarMul(iValue, aVal.iValue); |
|
463 return *this; |
|
464 #else |
|
465 TInt64 rslt( ( TInt ) iValue ), val( ( TInt ) aVal.iValue ); |
|
466 rslt *= val; |
|
467 iValue = ( I64HIGH(rslt) << KFixPtFrac ) | ( I64LOW ( rslt) >> KFixPtFrac ); |
|
468 |
|
469 return *this; |
|
470 #endif |
|
471 } |
|
472 |
|
473 |
|
474 |
|
475 // ========================================================================== |
|
476 // Division Assignment operator |
|
477 // Note: This may require more optimization... |
|
478 // ========================================================================== |
|
479 inline TFloatFixPt& TFloatFixPt::operator/=( const TFloatFixPt& aVal ) |
|
480 { |
|
481 #ifdef FIXPT_USE_INTS |
|
482 iValue = svgScalarDiv(iValue, aVal.iValue); |
|
483 return *this; |
|
484 #else |
|
485 TInt64 z = MAKE_TINT64( iValue ,0 ) ; |
|
486 TInt64 temp = aVal.iValue ; |
|
487 z /= temp; |
|
488 z >>= KFixPtFrac; |
|
489 iValue = I64INT ( z ); |
|
490 return *this; |
|
491 #endif |
|
492 } |
|
493 |
|
494 // =================================================================== |
|
495 // Addition operation |
|
496 // ========================================================================== |
|
497 inline TFloatFixPt TFloatFixPt::operator+( const TFloatFixPt& aVal ) const |
|
498 { |
|
499 return TFloatFixPt( iValue + aVal.iValue, ETrue ); |
|
500 } |
|
501 // ========================================================================== |
|
502 // Subtraction operation |
|
503 // ========================================================================== |
|
504 inline TFloatFixPt TFloatFixPt::operator-( const TFloatFixPt& aVal ) const |
|
505 { |
|
506 return TFloatFixPt( iValue - aVal.iValue, ETrue ); |
|
507 } |
|
508 |
|
509 // ========================================================================== |
|
510 // Multiplication operator |
|
511 // ========================================================================== |
|
512 |
|
513 inline TFloatFixPt TFloatFixPt::operator*( const TFloatFixPt& aVal ) const |
|
514 { |
|
515 TFloatFixPt tmp( iValue, ETrue ); |
|
516 tmp *= aVal; |
|
517 return tmp; |
|
518 } |
|
519 // ========================================================================== |
|
520 // Division operator |
|
521 // ========================================================================== |
|
522 inline TFloatFixPt TFloatFixPt::operator/( const TFloatFixPt& aVal ) const |
|
523 { |
|
524 TFloatFixPt tmp( iValue, ETrue ); |
|
525 tmp /= aVal; |
|
526 return tmp; |
|
527 } |
|
528 // ========================================================================== |
|
529 // Equals operator |
|
530 // ========================================================================== |
|
531 inline TInt TFloatFixPt::operator==( const TFloatFixPt& aVal ) const |
|
532 { |
|
533 return ( iValue == aVal.iValue ); |
|
534 } |
|
535 |
|
536 // ========================================================================== |
|
537 // Not Equals operator |
|
538 // ========================================================================== |
|
539 inline TInt TFloatFixPt::operator!=( const TFloatFixPt& aVal ) const |
|
540 { |
|
541 return ( iValue != aVal.iValue ); |
|
542 } |
|
543 |
|
544 // ========================================================================== |
|
545 // Greater than or equal to operator |
|
546 // ========================================================================== |
|
547 inline TInt TFloatFixPt::operator>=( const TFloatFixPt& aVal ) const |
|
548 { |
|
549 return ( iValue >= aVal.iValue ); |
|
550 } |
|
551 |
|
552 // ========================================================================== |
|
553 // Less than or equal to operator |
|
554 // ========================================================================== |
|
555 inline TInt TFloatFixPt::operator<=( const TFloatFixPt& aVal ) const |
|
556 { |
|
557 return ( iValue <= aVal.iValue ); |
|
558 } |
|
559 |
|
560 // ========================================================================== |
|
561 // Greater than operator |
|
562 // ========================================================================== |
|
563 inline TInt TFloatFixPt::operator>( const TFloatFixPt& aVal ) const |
|
564 { |
|
565 return ( iValue > aVal.iValue ); |
|
566 } |
|
567 |
|
568 // ========================================================================== |
|
569 // Less than operator |
|
570 // ========================================================================== |
|
571 inline TInt TFloatFixPt::operator<( const TFloatFixPt& aVal ) const |
|
572 { |
|
573 return ( iValue < aVal.iValue ); |
|
574 } |
|
575 // ========================================================================== |
|
576 // Left shift operator |
|
577 // ========================================================================== |
|
578 inline TFloatFixPt TFloatFixPt::operator<<( const TInt aN ) const |
|
579 { |
|
580 TFloatFixPt tmp( iValue<<aN, ETrue ); |
|
581 return tmp; |
|
582 } |
|
583 // ========================================================================== |
|
584 // Right shift operator |
|
585 // ========================================================================== |
|
586 inline TFloatFixPt TFloatFixPt::operator>>( const TInt aN ) const |
|
587 { |
|
588 TFloatFixPt tmp( iValue>>aN, ETrue ); |
|
589 return tmp; |
|
590 } |
|
591 |
|
592 // ========================================================================== |
|
593 // Round to the nearest whole number |
|
594 // ========================================================================== |
|
595 inline TInt32 TFloatFixPt::Round() |
|
596 { |
|
597 if ( 0 != ( iValue & 0x8000 ) ) |
|
598 return ( iValue >> KFixPtFrac ) + 1; |
|
599 else |
|
600 return ( iValue >> KFixPtFrac ); |
|
601 } |
|
602 |
|
603 // ========================================================================== |
|
604 // Get 32-bit representation |
|
605 // ========================================================================== |
|
606 inline TInt32 TFloatFixPt::RawData() |
|
607 { |
|
608 return iValue; |
|
609 } |
|
610 |
|
611 #endif |