OLD | NEW |
---|---|
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ | 7 #ifndef CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ |
8 #define CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ | 8 #define CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ |
9 | 9 |
10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 void Rotate(FX_FLOAT fRadian) { | 113 void Rotate(FX_FLOAT fRadian) { |
114 FX_FLOAT cosValue = FXSYS_cos(fRadian); | 114 FX_FLOAT cosValue = FXSYS_cos(fRadian); |
115 FX_FLOAT sinValue = FXSYS_sin(fRadian); | 115 FX_FLOAT sinValue = FXSYS_sin(fRadian); |
116 x = x * cosValue - y * sinValue; | 116 x = x * cosValue - y * sinValue; |
117 y = x * sinValue + y * cosValue; | 117 y = x * sinValue + y * cosValue; |
118 } | 118 } |
119 }; | 119 }; |
120 typedef CFX_VTemplate<int32_t> CFX_Vector; | 120 typedef CFX_VTemplate<int32_t> CFX_Vector; |
121 typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; | 121 typedef CFX_VTemplate<FX_FLOAT> CFX_VectorF; |
122 | 122 |
123 // Rectangles. | |
124 // TODO(tsepez): Consolidate all these different rectangle classes. | |
125 | |
126 // LTRB rectangles (y-axis runs downwards). | |
127 struct FX_SMALL_RECT { | |
128 FX_SMALL_RECT() : FX_SMALL_RECT(kInvalid, kInvalid, kInvalid, kInvalid) {} | |
129 | |
130 FX_SMALL_RECT(int16_t l, int16_t t, int16_t r, int16_t b) | |
131 : Left(l), Top(t), Right(r), Bottom(b) {} | |
132 | |
133 static const int16_t kInvalid = -1; | |
134 | |
135 int16_t Left; | |
dsinclair
2016/02/27 03:11:44
Why does this one use upper case (Left) and the on
Tom Sepez
2016/02/29 18:42:08
Because they're inconsistent with public members.
| |
136 int16_t Top; | |
137 int16_t Right; | |
138 int16_t Bottom; | |
139 }; | |
140 | |
141 struct FX_RECT { | |
142 FX_RECT() : left(0), top(0), right(0), bottom(0) {} | |
143 | |
144 FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {} | |
145 | |
146 explicit FX_RECT(const FX_SMALL_RECT& small) | |
147 : FX_RECT(small.Left, small.Top, small.Right, small.Bottom) {} | |
148 | |
149 int Width() const { return right - left; } | |
150 int Height() const { return bottom - top; } | |
151 bool IsEmpty() const { return right <= left || bottom <= top; } | |
152 | |
153 void Normalize(); | |
154 | |
155 void Intersect(const FX_RECT& src); | |
156 void Intersect(int left1, int top1, int right1, int bottom1) { | |
dsinclair
2016/02/27 03:11:44
nit: Why the 1's in the names?
Tom Sepez
2016/02/29 18:42:07
They conflict with instance variables in the class
| |
157 Intersect(FX_RECT(left1, top1, right1, bottom1)); | |
158 } | |
159 | |
160 void Union(const FX_RECT& other_rect); | |
161 void Union(int left1, int top1, int right1, int bottom1) { | |
162 Union(FX_RECT(left1, top1, right1, bottom1)); | |
163 } | |
164 | |
165 void Offset(int dx, int dy) { | |
166 left += dx; | |
167 right += dx; | |
168 top += dy; | |
169 bottom += dy; | |
170 } | |
171 | |
172 bool operator==(const FX_RECT& src) const { | |
173 return left == src.left && right == src.right && top == src.top && | |
174 bottom == src.bottom; | |
175 } | |
176 | |
177 FX_BOOL Contains(const FX_RECT& other_rect) const { | |
178 return other_rect.left >= left && other_rect.right <= right && | |
179 other_rect.top >= top && other_rect.bottom <= bottom; | |
180 } | |
181 | |
182 FX_BOOL Contains(int x, int y) const { | |
183 return x >= left && x < right && y >= top && y < bottom; | |
dsinclair
2016/02/27 03:11:44
Why >= for left and top but < for right and bottom
Tom Sepez
2016/02/29 18:42:08
Beats me. I'd expect a lot of 1px diffs if we cha
| |
184 } | |
185 | |
186 FX_SMALL_RECT ToSmallRect() const { | |
187 return FX_SMALL_RECT( | |
188 static_cast<uint16_t>(left), static_cast<uint16_t>(top), | |
189 static_cast<uint16_t>(right), static_cast<uint16_t>(bottom)); | |
190 } | |
191 | |
192 int left; | |
193 int top; | |
194 int right; | |
195 int bottom; | |
196 }; | |
197 | |
198 // LBRT rectangles (y-axis runs upwards). | |
199 class CFX_FloatPoint { | |
200 public: | |
201 CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} | |
202 | |
203 FX_FLOAT x; | |
204 FX_FLOAT y; | |
205 }; | |
206 | |
207 class CFX_FloatRect { | |
208 public: | |
209 CFX_FloatRect() { left = right = bottom = top = 0; } | |
dsinclair
2016/02/27 03:11:44
CFX_FloatRect() : left(0), right(0), bottom(0), to
Tom Sepez
2016/02/29 18:42:07
Done.
| |
210 | |
211 CFX_FloatRect(FX_FLOAT left1, | |
212 FX_FLOAT bottom1, | |
213 FX_FLOAT right1, | |
214 FX_FLOAT top1) { | |
215 left = left1; | |
216 bottom = bottom1; | |
217 right = right1; | |
218 top = top1; | |
219 } | |
220 | |
221 CFX_FloatRect(const FX_FLOAT* pArray) { | |
dsinclair
2016/02/27 03:11:44
nit: explicit
Tom Sepez
2016/02/29 18:42:08
Yep. Good catch. Done.
| |
222 left = pArray[0]; | |
223 bottom = pArray[1]; | |
224 right = pArray[2]; | |
225 top = pArray[3]; | |
226 } | |
227 | |
228 CFX_FloatRect(const FX_RECT& rect); | |
dsinclair
2016/02/27 03:11:44
nit: explicit
Tom Sepez
2016/02/29 18:42:08
Done.
| |
229 | |
230 FX_BOOL IsEmpty() const { return left >= right || bottom >= top; } | |
231 | |
232 void Normalize(); | |
233 | |
234 void Reset() { left = right = bottom = top = 0; } | |
235 | |
236 FX_BOOL Contains(const CFX_FloatRect& other_rect) const; | |
237 | |
238 FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const; | |
239 | |
240 void Transform(const CFX_Matrix* pMatrix); | |
241 | |
242 void Intersect(const CFX_FloatRect& other_rect); | |
243 | |
244 void Union(const CFX_FloatRect& other_rect); | |
245 | |
246 FX_RECT GetInnerRect() const; | |
247 | |
dsinclair
2016/02/27 03:11:44
nit: Can a bunch of these spaces be removed?
Tom Sepez
2016/02/29 18:42:08
Done.
| |
248 FX_RECT GetOutterRect() const; | |
249 | |
250 FX_RECT GetClosestRect() const; | |
251 | |
252 int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); | |
253 | |
254 void InitRect(FX_FLOAT x, FX_FLOAT y) { | |
dsinclair
2016/02/27 03:11:44
This seems like a very weird init method? We initi
Tom Sepez
2016/02/29 18:42:08
yes. looking at usage, its always followed by a bu
| |
255 left = right = x; | |
256 bottom = top = y; | |
257 } | |
258 | |
259 void UpdateRect(FX_FLOAT x, FX_FLOAT y); | |
260 | |
261 FX_FLOAT Width() const { return right - left; } | |
262 | |
263 FX_FLOAT Height() const { return top - bottom; } | |
264 | |
265 void Inflate(FX_FLOAT x, FX_FLOAT y) { | |
dsinclair
2016/02/27 03:11:44
Maybe add a comment that this inflates by 2x and 2
Tom Sepez
2016/02/29 18:42:08
Maybe.
| |
266 Normalize(); | |
267 left -= x; | |
268 right += x; | |
269 bottom -= y; | |
270 top += y; | |
271 } | |
272 | |
273 void Inflate(FX_FLOAT other_left, | |
274 FX_FLOAT other_bottom, | |
275 FX_FLOAT other_right, | |
276 FX_FLOAT other_top) { | |
277 Normalize(); | |
278 left -= other_left; | |
279 bottom -= other_bottom; | |
280 right += other_right; | |
281 top += other_top; | |
282 } | |
283 | |
284 void Inflate(const CFX_FloatRect& rt) { | |
285 Inflate(rt.left, rt.bottom, rt.right, rt.top); | |
286 } | |
287 | |
288 void Deflate(FX_FLOAT x, FX_FLOAT y) { | |
dsinclair
2016/02/27 03:11:44
ditto: deflates by 2x, 2y
| |
289 Normalize(); | |
290 left += x; | |
291 right -= x; | |
292 bottom += y; | |
293 top -= y; | |
294 } | |
295 | |
296 void Deflate(FX_FLOAT other_left, | |
297 FX_FLOAT other_bottom, | |
298 FX_FLOAT other_right, | |
299 FX_FLOAT other_top) { | |
300 Normalize(); | |
301 left += other_left; | |
302 bottom += other_bottom; | |
303 right -= other_right; | |
304 top -= other_top; | |
305 } | |
306 | |
307 void Deflate(const CFX_FloatRect& rt) { | |
308 Deflate(rt.left, rt.bottom, rt.right, rt.top); | |
309 } | |
310 | |
311 void Translate(FX_FLOAT e, FX_FLOAT f) { | |
312 left += e; | |
313 right += e; | |
314 top += f; | |
315 bottom += f; | |
316 } | |
317 | |
318 static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); | |
319 | |
320 FX_FLOAT left; | |
321 FX_FLOAT right; | |
322 FX_FLOAT bottom; | |
323 FX_FLOAT top; | |
324 }; | |
325 | |
326 // LTWH rectangles (y-axis runs downwards). | |
dsinclair
2016/02/27 03:11:44
What does LTWH stand for?
Tom Sepez
2016/02/29 18:42:07
Left, Top, Width, Height -- as in we store a point
| |
123 template <class baseType> | 327 template <class baseType> |
124 class CFX_RTemplate { | 328 class CFX_RTemplate { |
125 public: | 329 public: |
126 typedef CFX_PSTemplate<baseType> FXT_POINT; | 330 typedef CFX_PSTemplate<baseType> FXT_POINT; |
127 typedef CFX_PSTemplate<baseType> FXT_SIZE; | 331 typedef CFX_PSTemplate<baseType> FXT_SIZE; |
128 typedef CFX_VTemplate<baseType> FXT_VECTOR; | 332 typedef CFX_VTemplate<baseType> FXT_VECTOR; |
129 typedef CFX_RTemplate<baseType> FXT_RECT; | 333 typedef CFX_RTemplate<baseType> FXT_RECT; |
130 void Set(baseType left, baseType top, baseType width, baseType height) { | 334 void Set(baseType left, baseType top, baseType width, baseType height) { |
131 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, | 335 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, |
132 FXT_RECT::height = height; | 336 FXT_RECT::height = height; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 baseType left, top; | 547 baseType left, top; |
344 baseType width, height; | 548 baseType width, height; |
345 }; | 549 }; |
346 typedef CFX_RTemplate<int32_t> CFX_Rect; | 550 typedef CFX_RTemplate<int32_t> CFX_Rect; |
347 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; | 551 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; |
348 typedef CFX_RTemplate<int32_t>* FX_LPRECT; | 552 typedef CFX_RTemplate<int32_t>* FX_LPRECT; |
349 typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF; | 553 typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF; |
350 typedef CFX_RTemplate<int32_t> const* FX_LPCRECT; | 554 typedef CFX_RTemplate<int32_t> const* FX_LPCRECT; |
351 typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF; | 555 typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF; |
352 typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; | 556 typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; |
353 struct FX_RECT { | |
354 int left; | |
355 | |
356 int top; | |
357 | |
358 int right; | |
359 | |
360 int bottom; | |
361 | |
362 FX_RECT() : left(0), top(0), right(0), bottom(0) {} | |
363 | |
364 FX_RECT(int left1, int top1, int right1, int bottom1) { | |
365 left = left1; | |
366 top = top1; | |
367 right = right1; | |
368 bottom = bottom1; | |
369 } | |
370 | |
371 int Width() const { return right - left; } | |
372 | |
373 int Height() const { return bottom - top; } | |
374 | |
375 FX_BOOL IsEmpty() const { return right <= left || bottom <= top; } | |
376 | |
377 void Normalize(); | |
378 | |
379 void Intersect(const FX_RECT& src); | |
380 | |
381 void Intersect(int left1, int top1, int right1, int bottom1) { | |
382 Intersect(FX_RECT(left1, top1, right1, bottom1)); | |
383 } | |
384 | |
385 void Union(const FX_RECT& other_rect); | |
386 | |
387 bool operator==(const FX_RECT& src) const { | |
388 return left == src.left && right == src.right && top == src.top && | |
389 bottom == src.bottom; | |
390 } | |
391 | |
392 void Offset(int dx, int dy) { | |
393 left += dx; | |
394 right += dx; | |
395 top += dy; | |
396 bottom += dy; | |
397 } | |
398 | |
399 FX_BOOL Contains(const FX_RECT& other_rect) const { | |
400 return other_rect.left >= left && other_rect.right <= right && | |
401 other_rect.top >= top && other_rect.bottom <= bottom; | |
402 } | |
403 | |
404 FX_BOOL Contains(int x, int y) const { | |
405 return x >= left && x < right && y >= top && y < bottom; | |
406 } | |
407 }; | |
408 struct FX_SMALL_RECT { | |
409 int16_t Left; | |
410 | |
411 int16_t Top; | |
412 | |
413 int16_t Right; | |
414 | |
415 int16_t Bottom; | |
416 }; | |
417 | |
418 class CFX_FloatPoint { | |
419 public: | |
420 CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} | |
421 | |
422 FX_FLOAT x; | |
423 FX_FLOAT y; | |
424 }; | |
425 | |
426 class CFX_FloatRect { | |
427 public: | |
428 CFX_FloatRect() { left = right = bottom = top = 0; } | |
429 | |
430 CFX_FloatRect(FX_FLOAT left1, | |
431 FX_FLOAT bottom1, | |
432 FX_FLOAT right1, | |
433 FX_FLOAT top1) { | |
434 left = left1; | |
435 bottom = bottom1; | |
436 right = right1; | |
437 top = top1; | |
438 } | |
439 | |
440 CFX_FloatRect(const FX_FLOAT* pArray) { | |
441 left = pArray[0]; | |
442 bottom = pArray[1]; | |
443 right = pArray[2]; | |
444 top = pArray[3]; | |
445 } | |
446 | |
447 CFX_FloatRect(const FX_RECT& rect); | |
448 | |
449 FX_BOOL IsEmpty() const { return left >= right || bottom >= top; } | |
450 | |
451 void Normalize(); | |
452 | |
453 void Reset() { left = right = bottom = top = 0; } | |
454 | |
455 FX_BOOL Contains(const CFX_FloatRect& other_rect) const; | |
456 | |
457 FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const; | |
458 | |
459 void Transform(const CFX_Matrix* pMatrix); | |
460 | |
461 void Intersect(const CFX_FloatRect& other_rect); | |
462 | |
463 void Union(const CFX_FloatRect& other_rect); | |
464 | |
465 FX_RECT GetInnerRect() const; | |
466 | |
467 FX_RECT GetOutterRect() const; | |
468 | |
469 FX_RECT GetClosestRect() const; | |
470 | |
471 int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); | |
472 | |
473 void InitRect(FX_FLOAT x, FX_FLOAT y) { | |
474 left = right = x; | |
475 bottom = top = y; | |
476 } | |
477 | |
478 void UpdateRect(FX_FLOAT x, FX_FLOAT y); | |
479 | |
480 FX_FLOAT Width() const { return right - left; } | |
481 | |
482 FX_FLOAT Height() const { return top - bottom; } | |
483 | |
484 void Inflate(FX_FLOAT x, FX_FLOAT y) { | |
485 Normalize(); | |
486 left -= x; | |
487 right += x; | |
488 bottom -= y; | |
489 top += y; | |
490 } | |
491 | |
492 void Inflate(FX_FLOAT other_left, | |
493 FX_FLOAT other_bottom, | |
494 FX_FLOAT other_right, | |
495 FX_FLOAT other_top) { | |
496 Normalize(); | |
497 left -= other_left; | |
498 bottom -= other_bottom; | |
499 right += other_right; | |
500 top += other_top; | |
501 } | |
502 | |
503 void Inflate(const CFX_FloatRect& rt) { | |
504 Inflate(rt.left, rt.bottom, rt.right, rt.top); | |
505 } | |
506 | |
507 void Deflate(FX_FLOAT x, FX_FLOAT y) { | |
508 Normalize(); | |
509 left += x; | |
510 right -= x; | |
511 bottom += y; | |
512 top -= y; | |
513 } | |
514 | |
515 void Deflate(FX_FLOAT other_left, | |
516 FX_FLOAT other_bottom, | |
517 FX_FLOAT other_right, | |
518 FX_FLOAT other_top) { | |
519 Normalize(); | |
520 left += other_left; | |
521 bottom += other_bottom; | |
522 right -= other_right; | |
523 top -= other_top; | |
524 } | |
525 | |
526 void Deflate(const CFX_FloatRect& rt) { | |
527 Deflate(rt.left, rt.bottom, rt.right, rt.top); | |
528 } | |
529 | |
530 void Translate(FX_FLOAT e, FX_FLOAT f) { | |
531 left += e; | |
532 right += e; | |
533 top += f; | |
534 bottom += f; | |
535 } | |
536 | |
537 static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); | |
538 | |
539 FX_FLOAT left; | |
540 FX_FLOAT right; | |
541 FX_FLOAT bottom; | |
542 FX_FLOAT top; | |
543 }; | |
544 | 557 |
545 class CFX_Matrix { | 558 class CFX_Matrix { |
546 public: | 559 public: |
547 CFX_Matrix() { SetIdentity(); } | 560 CFX_Matrix() { SetIdentity(); } |
548 | 561 |
549 CFX_Matrix(FX_FLOAT a1, | 562 CFX_Matrix(FX_FLOAT a1, |
550 FX_FLOAT b1, | 563 FX_FLOAT b1, |
551 FX_FLOAT c1, | 564 FX_FLOAT c1, |
552 FX_FLOAT d1, | 565 FX_FLOAT d1, |
553 FX_FLOAT e1, | 566 FX_FLOAT e1, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 public: | 678 public: |
666 FX_FLOAT a; | 679 FX_FLOAT a; |
667 FX_FLOAT b; | 680 FX_FLOAT b; |
668 FX_FLOAT c; | 681 FX_FLOAT c; |
669 FX_FLOAT d; | 682 FX_FLOAT d; |
670 FX_FLOAT e; | 683 FX_FLOAT e; |
671 FX_FLOAT f; | 684 FX_FLOAT f; |
672 }; | 685 }; |
673 | 686 |
674 #endif // CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ | 687 #endif // CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ |
OLD | NEW |