|
1 /* |
|
2 * Copyright (c) 2003 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: SVG Engine header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "SVGFourPointRect.h" |
|
20 |
|
21 // --------------------------------------------------------------------------- |
|
22 // Constructor |
|
23 // --------------------------------------------------------------------------- |
|
24 TSvgFourPointRect::TSvgFourPointRect( ) |
|
25 { |
|
26 iPoint1.iX = 0; |
|
27 iPoint1.iY = 0; |
|
28 |
|
29 iPoint2.iX = 0; |
|
30 iPoint2.iY = 0; |
|
31 |
|
32 iPoint3.iX = 0; |
|
33 iPoint3.iY = 0; |
|
34 |
|
35 iPoint4.iX = 0; |
|
36 iPoint4.iY = 0; |
|
37 } |
|
38 |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // TSvgFourPointRect::TSvgFourPointRect( TGfxRectangle2D aRect ) |
|
42 // --------------------------------------------------------------------------- |
|
43 TSvgFourPointRect::TSvgFourPointRect( TGfxRectangle2D aRect ) |
|
44 { |
|
45 iPoint1.iX = aRect.iX; |
|
46 iPoint1.iY = aRect.iY; |
|
47 |
|
48 iPoint2.iX = aRect.iX + aRect.iWidth; |
|
49 iPoint2.iY = aRect.iY; |
|
50 |
|
51 iPoint3.iX = aRect.iX; |
|
52 iPoint3.iY = aRect.iY + aRect.iHeight; |
|
53 |
|
54 iPoint4.iX = aRect.iX + aRect.iWidth; |
|
55 iPoint4.iY = aRect.iY + aRect.iHeight; |
|
56 |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------- |
|
60 // void TSvgFourPointRect::SetRectPoints( TGfxRectangle2D aRect ) |
|
61 // --------------------------------------------------------------------------- |
|
62 void TSvgFourPointRect::SetRectPoints( TGfxRectangle2D aRect ) |
|
63 { |
|
64 iPoint1.iX = aRect.iX; |
|
65 iPoint1.iY = aRect.iY; |
|
66 |
|
67 iPoint2.iX = aRect.iX + aRect.iWidth; |
|
68 iPoint2.iY = aRect.iY; |
|
69 |
|
70 iPoint3.iX = aRect.iX; |
|
71 iPoint3.iY = aRect.iY + aRect.iHeight; |
|
72 |
|
73 iPoint4.iX = aRect.iX + aRect.iWidth; |
|
74 iPoint4.iY = aRect.iY + aRect.iHeight; |
|
75 |
|
76 } |
|
77 |
|
78 // -------------------------------------------------------------------------- |
|
79 // TSvgFourPointRect::TSvgFourPointRect( TFloatFixPt aX, TFloatFixPt aY, TFloatFixPt aWidth, TFloatFixPt aHeight ) |
|
80 // --------------------------------------------------------------------------- |
|
81 TSvgFourPointRect::TSvgFourPointRect( TFloatFixPt aX, TFloatFixPt aY, TFloatFixPt aWidth, TFloatFixPt aHeight ) |
|
82 { |
|
83 iPoint1.iX = aX; |
|
84 iPoint1.iY = aY; |
|
85 |
|
86 iPoint2.iX = aX + aWidth; |
|
87 iPoint2.iY = aY; |
|
88 |
|
89 iPoint3.iX = aX; |
|
90 iPoint3.iY = aY + aHeight; |
|
91 |
|
92 iPoint4.iX = aX + aWidth; |
|
93 iPoint4.iY = aY + aHeight; |
|
94 } |
|
95 |
|
96 // -------------------------------------------------------------------------- |
|
97 // void TSvgFourPointRect::SetRectPoints( TFloatFixPt aX, TFloatFixPt aY, TFloatFixPt aWidth, TFloatFixPt aHeight ) |
|
98 // --------------------------------------------------------------------------- |
|
99 void TSvgFourPointRect::SetRectPoints( TFloatFixPt aX, TFloatFixPt aY, TFloatFixPt aWidth, TFloatFixPt aHeight ) |
|
100 { |
|
101 iPoint1.iX = aX; |
|
102 iPoint1.iY = aY; |
|
103 |
|
104 iPoint2.iX = aX + aWidth; |
|
105 iPoint2.iY = aY; |
|
106 |
|
107 iPoint3.iX = aX; |
|
108 iPoint3.iY = aY + aHeight; |
|
109 |
|
110 iPoint4.iX = aX + aWidth; |
|
111 iPoint4.iY = aY + aHeight; |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 // -------------------------------------------------------------------------- |
|
118 // TSvgFourPointRect::TSvgFourPointRect(TGfxPoint2D aPoint1, TGfxPoint2D aPoint2, TGfxPoint2D aPoint3, TGfxPoint2D aPoint4) |
|
119 // --------------------------------------------------------------------------- |
|
120 TSvgFourPointRect::TSvgFourPointRect(TGfxPoint2D aPoint1, TGfxPoint2D aPoint2, TGfxPoint2D aPoint3, TGfxPoint2D aPoint4) |
|
121 { |
|
122 iPoint1 = aPoint1; |
|
123 iPoint2 = aPoint2; |
|
124 iPoint3 = aPoint3; |
|
125 iPoint4 = aPoint4; |
|
126 } |
|
127 |
|
128 |
|
129 // -------------------------------------------------------------------------- |
|
130 // void TSvgFourPointRect::SetRectPoints(TGfxPoint2D aPoint1, TGfxPoint2D aPoint2, TGfxPoint2D aPoint3, TGfxPoint2D aPoint4) |
|
131 // --------------------------------------------------------------------------- |
|
132 void TSvgFourPointRect::SetRectPoints(TGfxPoint2D aPoint1, TGfxPoint2D aPoint2, TGfxPoint2D aPoint3, TGfxPoint2D aPoint4) |
|
133 { |
|
134 iPoint1 = aPoint1; |
|
135 iPoint2 = aPoint2; |
|
136 iPoint3 = aPoint3; |
|
137 iPoint4 = aPoint4; |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // TSvgFourPointRect::TSvgFourPointRect(TPoint aPoint1, TPoint aPoint2, TPoint aPoint3, TPoint aPoint4) |
|
142 // --------------------------------------------------------------------------- |
|
143 TSvgFourPointRect::TSvgFourPointRect(TPoint aPoint1, TPoint aPoint2, TPoint aPoint3, TPoint aPoint4) |
|
144 { |
|
145 iPoint1.iX = TFloatFixPt(aPoint1.iX); |
|
146 iPoint2.iX = TFloatFixPt(aPoint2.iX); |
|
147 iPoint3.iX = TFloatFixPt(aPoint3.iX); |
|
148 iPoint4.iX = TFloatFixPt(aPoint4.iX); |
|
149 iPoint1.iY = TFloatFixPt(aPoint1.iY); |
|
150 iPoint2.iY = TFloatFixPt(aPoint2.iY); |
|
151 iPoint3.iY = TFloatFixPt(aPoint3.iY); |
|
152 iPoint4.iY = TFloatFixPt(aPoint4.iY); |
|
153 |
|
154 } |
|
155 |
|
156 // -------------------------------------------------------------------------- |
|
157 // void TSvgFourPointRect::SetRectPoints(TPoint aPoint1, TPoint aPoint2, TPoint aPoint3, TPoint aPoint4) |
|
158 // --------------------------------------------------------------------------- |
|
159 void TSvgFourPointRect::SetRectPoints(TPoint aPoint1, TPoint aPoint2, TPoint aPoint3, TPoint aPoint4) |
|
160 { |
|
161 iPoint1.iX = TFloatFixPt(aPoint1.iX); |
|
162 iPoint2.iX = TFloatFixPt(aPoint2.iX); |
|
163 iPoint3.iX = TFloatFixPt(aPoint3.iX); |
|
164 iPoint4.iX = TFloatFixPt(aPoint4.iX); |
|
165 iPoint1.iY = TFloatFixPt(aPoint1.iY); |
|
166 iPoint2.iY = TFloatFixPt(aPoint2.iY); |
|
167 iPoint3.iY = TFloatFixPt(aPoint3.iY); |
|
168 iPoint4.iY = TFloatFixPt(aPoint4.iY); |
|
169 |
|
170 } |
|
171 |
|
172 |
|
173 // -------------------------------------------------------------------------- |
|
174 // void TSvgFourPointRect::GetPoints(TPoint& aPoint1, TPoint& aPoint2, TPoint& aPoint3, TPoint& aPoint4) const |
|
175 // --------------------------------------------------------------------------- |
|
176 void TSvgFourPointRect::GetPoints(TPoint& aPoint1, TPoint& aPoint2, TPoint& aPoint3, TPoint& aPoint4) const |
|
177 { |
|
178 aPoint1.iX = (TInt)iPoint1.iX; |
|
179 aPoint1.iY = (TInt)iPoint1.iY; |
|
180 |
|
181 aPoint2.iX = (TInt)iPoint2.iX; |
|
182 aPoint2.iY = (TInt)iPoint2.iY; |
|
183 |
|
184 aPoint3.iX = (TInt)iPoint3.iX; |
|
185 aPoint3.iY = (TInt)iPoint3.iY; |
|
186 |
|
187 aPoint4.iX = (TInt)iPoint4.iX; |
|
188 aPoint4.iY = (TInt)iPoint4.iY; |
|
189 } |
|
190 |
|
191 // -------------------------------------------------------------------------- |
|
192 // void TSvgFourPointRect::GetPoints(TGfxPoint2D& aPoint1, TGfxPoint2D& aPoint2, TGfxPoint2D& aPoint3, TGfxPoint2D& aPoint4) |
|
193 // --------------------------------------------------------------------------- |
|
194 void TSvgFourPointRect::GetPoints(TGfxPoint2D& aPoint1, TGfxPoint2D& aPoint2, TGfxPoint2D& aPoint3, TGfxPoint2D& aPoint4) |
|
195 { |
|
196 aPoint1 = iPoint1; |
|
197 aPoint2 = iPoint2; |
|
198 aPoint3 = iPoint3; |
|
199 aPoint4 = iPoint4; |
|
200 } |
|
201 |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // void TSvgFourPointRect::GetTRect(TRect& aRect) |
|
205 // --------------------------------------------------------------------------- |
|
206 void TSvgFourPointRect::GetTRect(TRect& aRect) |
|
207 { |
|
208 |
|
209 TFloatFixPt lMaxX = iPoint1.iX; |
|
210 |
|
211 if (iPoint2.iX > lMaxX) |
|
212 { |
|
213 lMaxX = iPoint2.iX; |
|
214 } |
|
215 if (iPoint3.iX > lMaxX) |
|
216 { |
|
217 lMaxX = iPoint3.iX; |
|
218 } |
|
219 if (iPoint4.iX > lMaxX) |
|
220 { |
|
221 lMaxX = iPoint4.iX; |
|
222 } |
|
223 |
|
224 TFloatFixPt lMaxY = iPoint1.iY; |
|
225 |
|
226 if (iPoint2.iY > lMaxY) |
|
227 { |
|
228 lMaxY = iPoint2.iY; |
|
229 } |
|
230 if (iPoint3.iY > lMaxY) |
|
231 { |
|
232 lMaxY = iPoint3.iY; |
|
233 } |
|
234 if (iPoint4.iY > lMaxY) |
|
235 { |
|
236 lMaxY = iPoint4.iY; |
|
237 } |
|
238 |
|
239 TFloatFixPt lMinX = iPoint1.iX; |
|
240 |
|
241 if (iPoint2.iX < lMinX) |
|
242 { |
|
243 lMinX = iPoint2.iX; |
|
244 } |
|
245 if (iPoint3.iX < lMinX) |
|
246 { |
|
247 lMinX = iPoint3.iX; |
|
248 } |
|
249 if (iPoint4.iX < lMinX) |
|
250 { |
|
251 lMinX = iPoint4.iX; |
|
252 } |
|
253 |
|
254 TFloatFixPt lMinY = iPoint1.iY; |
|
255 |
|
256 if (iPoint2.iY < lMinY) |
|
257 { |
|
258 lMinY = iPoint2.iY; |
|
259 } |
|
260 if (iPoint3.iY < lMinY) |
|
261 { |
|
262 lMinY = iPoint3.iY; |
|
263 } |
|
264 if (iPoint4.iY < lMinY) |
|
265 { |
|
266 lMinY = iPoint4.iY; |
|
267 } |
|
268 |
|
269 aRect.iBr.iX = lMaxX; |
|
270 aRect.iBr.iY = lMaxY; |
|
271 aRect.iTl.iX = lMinX; |
|
272 aRect.iTl.iY = lMinY; |
|
273 |
|
274 } |
|
275 |
|
276 |
|
277 // -------------------------------------------------------------------------- |
|
278 // void TSvgFourPointRect::GetTRect(TGfxRectangle2D& aRect) |
|
279 // --------------------------------------------------------------------------- |
|
280 void TSvgFourPointRect::GetTRect(TGfxRectangle2D& aRect) |
|
281 { |
|
282 |
|
283 TFloatFixPt lMaxX = iPoint1.iX; |
|
284 |
|
285 if (iPoint2.iX > lMaxX) |
|
286 { |
|
287 lMaxX = iPoint2.iX; |
|
288 } |
|
289 if (iPoint3.iX > lMaxX) |
|
290 { |
|
291 lMaxX = iPoint3.iX; |
|
292 } |
|
293 if (iPoint4.iX > lMaxX) |
|
294 { |
|
295 lMaxX = iPoint4.iX; |
|
296 } |
|
297 |
|
298 TFloatFixPt lMaxY = iPoint1.iY; |
|
299 |
|
300 if (iPoint2.iY > lMaxY) |
|
301 { |
|
302 lMaxY = iPoint2.iY; |
|
303 } |
|
304 if (iPoint3.iY > lMaxY) |
|
305 { |
|
306 lMaxY = iPoint3.iY; |
|
307 } |
|
308 if (iPoint4.iY > lMaxY) |
|
309 { |
|
310 lMaxY = iPoint4.iY; |
|
311 } |
|
312 |
|
313 TFloatFixPt lMinX = iPoint1.iX; |
|
314 |
|
315 if (iPoint2.iX < lMinX) |
|
316 { |
|
317 lMinX = iPoint2.iX; |
|
318 } |
|
319 if (iPoint3.iX < lMinX) |
|
320 { |
|
321 lMinX = iPoint3.iX; |
|
322 } |
|
323 if (iPoint4.iX < lMinX) |
|
324 { |
|
325 lMinX = iPoint4.iX; |
|
326 } |
|
327 |
|
328 TFloatFixPt lMinY = iPoint1.iY; |
|
329 |
|
330 if (iPoint2.iY < lMinY) |
|
331 { |
|
332 lMinY = iPoint2.iY; |
|
333 } |
|
334 if (iPoint3.iY < lMinY) |
|
335 { |
|
336 lMinY = iPoint3.iY; |
|
337 } |
|
338 if (iPoint4.iY < lMinY) |
|
339 { |
|
340 lMinY = iPoint4.iY; |
|
341 } |
|
342 |
|
343 aRect.iX = lMinX; |
|
344 aRect.iY = lMinY; |
|
345 aRect.iWidth = lMaxX - lMinX; |
|
346 aRect.iHeight = lMaxY - lMinY; |
|
347 |
|
348 } |
|
349 |
|
350 // -------------------------------------------------------------------------- |
|
351 // void TSvgFourPointRect::Center(TPoint& aCenter) |
|
352 // --------------------------------------------------------------------------- |
|
353 void TSvgFourPointRect::Center(TPoint& aCenter) |
|
354 { |
|
355 TFloatFixPt lMaxX = iPoint1.iX; |
|
356 |
|
357 if (iPoint2.iX > lMaxX) |
|
358 { |
|
359 lMaxX = iPoint2.iX; |
|
360 } |
|
361 if (iPoint3.iX > lMaxX) |
|
362 { |
|
363 lMaxX = iPoint3.iX; |
|
364 } |
|
365 if (iPoint4.iX > lMaxX) |
|
366 { |
|
367 lMaxX = iPoint4.iX; |
|
368 } |
|
369 |
|
370 TFloatFixPt lMaxY = iPoint1.iY; |
|
371 |
|
372 if (iPoint2.iY > lMaxY) |
|
373 { |
|
374 lMaxY = iPoint2.iY; |
|
375 } |
|
376 if (iPoint3.iY > lMaxY) |
|
377 { |
|
378 lMaxY = iPoint3.iY; |
|
379 } |
|
380 if (iPoint4.iY > lMaxY) |
|
381 { |
|
382 lMaxY = iPoint4.iY; |
|
383 } |
|
384 |
|
385 TFloatFixPt lMinX = iPoint1.iX; |
|
386 |
|
387 if (iPoint2.iX < lMinX) |
|
388 { |
|
389 lMinX = iPoint2.iX; |
|
390 } |
|
391 if (iPoint3.iX < lMinX) |
|
392 { |
|
393 lMinX = iPoint3.iX; |
|
394 } |
|
395 if (iPoint4.iX < lMinX) |
|
396 { |
|
397 lMinX = iPoint4.iX; |
|
398 } |
|
399 |
|
400 TFloatFixPt lMinY = iPoint1.iY; |
|
401 |
|
402 if (iPoint2.iY < lMinY) |
|
403 { |
|
404 lMinY = iPoint2.iY; |
|
405 } |
|
406 if (iPoint3.iY < lMinY) |
|
407 { |
|
408 lMinY = iPoint3.iY; |
|
409 } |
|
410 if (iPoint4.iY < lMinY) |
|
411 { |
|
412 lMinY = iPoint4.iY; |
|
413 } |
|
414 |
|
415 aCenter.iX = (( lMaxX - lMinX ) / TFloatFixPt(2) ) + lMinX; |
|
416 aCenter.iY = (( lMaxY - lMinY ) / TFloatFixPt(2) ) + lMinY; |
|
417 } |
|
418 |
|
419 // -------------------------------------------------------------------------- |
|
420 // TBool TSvgFourPointRect::Intersects(const MRect& aFourPointRect) |
|
421 // --------------------------------------------------------------------------- |
|
422 TBool TSvgFourPointRect::Intersects(const MRect& aFourPointRect) |
|
423 { |
|
424 TGfxRectangle2D rect; |
|
425 TGfxRectangle2D thisRect; |
|
426 |
|
427 GetTRect(thisRect); |
|
428 ((TSvgFourPointRect&)aFourPointRect).GetTRect(rect); |
|
429 |
|
430 return ( thisRect.Intersects(rect) ); |
|
431 } |