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; |
| 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 l, int t, int r, int b) { Intersect(FX_RECT(l, t, r, b)); } |
| 157 |
| 158 void Union(const FX_RECT& other_rect); |
| 159 void Union(int l, int t, int r, int b) { Union(FX_RECT(l, t, r, b)); } |
| 160 |
| 161 void Offset(int dx, int dy) { |
| 162 left += dx; |
| 163 right += dx; |
| 164 top += dy; |
| 165 bottom += dy; |
| 166 } |
| 167 |
| 168 bool operator==(const FX_RECT& src) const { |
| 169 return left == src.left && right == src.right && top == src.top && |
| 170 bottom == src.bottom; |
| 171 } |
| 172 |
| 173 FX_BOOL Contains(const FX_RECT& other_rect) const { |
| 174 return other_rect.left >= left && other_rect.right <= right && |
| 175 other_rect.top >= top && other_rect.bottom <= bottom; |
| 176 } |
| 177 |
| 178 FX_BOOL Contains(int x, int y) const { |
| 179 return x >= left && x < right && y >= top && y < bottom; |
| 180 } |
| 181 |
| 182 FX_SMALL_RECT ToSmallRect() const { |
| 183 return FX_SMALL_RECT( |
| 184 static_cast<uint16_t>(left), static_cast<uint16_t>(top), |
| 185 static_cast<uint16_t>(right), static_cast<uint16_t>(bottom)); |
| 186 } |
| 187 |
| 188 int left; |
| 189 int top; |
| 190 int right; |
| 191 int bottom; |
| 192 }; |
| 193 |
| 194 // LBRT rectangles (y-axis runs upwards). |
| 195 class CFX_FloatPoint { |
| 196 public: |
| 197 CFX_FloatPoint(FX_FLOAT xx, FX_FLOAT yy) : x(xx), y(yy) {} |
| 198 |
| 199 FX_FLOAT x; |
| 200 FX_FLOAT y; |
| 201 }; |
| 202 |
| 203 class CFX_FloatRect { |
| 204 public: |
| 205 CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {} |
| 206 CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t) |
| 207 : left(l), bottom(b), right(r), top(t) {} |
| 208 |
| 209 explicit CFX_FloatRect(const FX_FLOAT* pArray) |
| 210 : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {} |
| 211 |
| 212 explicit CFX_FloatRect(const FX_RECT& rect); |
| 213 |
| 214 void Normalize(); |
| 215 |
| 216 void Reset() { |
| 217 left = 0.0f; |
| 218 right = 0.0f; |
| 219 bottom = 0.0f; |
| 220 top = 0.0f; |
| 221 } |
| 222 |
| 223 FX_BOOL IsEmpty() const { return left >= right || bottom >= top; } |
| 224 FX_BOOL Contains(const CFX_FloatRect& other_rect) const; |
| 225 FX_BOOL Contains(FX_FLOAT x, FX_FLOAT y) const; |
| 226 |
| 227 void Transform(const CFX_Matrix* pMatrix); |
| 228 void Intersect(const CFX_FloatRect& other_rect); |
| 229 void Union(const CFX_FloatRect& other_rect); |
| 230 |
| 231 FX_RECT GetInnerRect() const; |
| 232 FX_RECT GetOutterRect() const; |
| 233 FX_RECT GetClosestRect() const; |
| 234 |
| 235 int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); |
| 236 |
| 237 void InitRect(FX_FLOAT x, FX_FLOAT y) { |
| 238 left = x; |
| 239 right = x; |
| 240 bottom = y; |
| 241 top = y; |
| 242 } |
| 243 void UpdateRect(FX_FLOAT x, FX_FLOAT y); |
| 244 |
| 245 FX_FLOAT Width() const { return right - left; } |
| 246 FX_FLOAT Height() const { return top - bottom; } |
| 247 |
| 248 void Inflate(FX_FLOAT x, FX_FLOAT y) { |
| 249 Normalize(); |
| 250 left -= x; |
| 251 right += x; |
| 252 bottom -= y; |
| 253 top += y; |
| 254 } |
| 255 |
| 256 void Inflate(FX_FLOAT other_left, |
| 257 FX_FLOAT other_bottom, |
| 258 FX_FLOAT other_right, |
| 259 FX_FLOAT other_top) { |
| 260 Normalize(); |
| 261 left -= other_left; |
| 262 bottom -= other_bottom; |
| 263 right += other_right; |
| 264 top += other_top; |
| 265 } |
| 266 |
| 267 void Inflate(const CFX_FloatRect& rt) { |
| 268 Inflate(rt.left, rt.bottom, rt.right, rt.top); |
| 269 } |
| 270 |
| 271 void Deflate(FX_FLOAT x, FX_FLOAT y) { |
| 272 Normalize(); |
| 273 left += x; |
| 274 right -= x; |
| 275 bottom += y; |
| 276 top -= y; |
| 277 } |
| 278 |
| 279 void Deflate(FX_FLOAT other_left, |
| 280 FX_FLOAT other_bottom, |
| 281 FX_FLOAT other_right, |
| 282 FX_FLOAT other_top) { |
| 283 Normalize(); |
| 284 left += other_left; |
| 285 bottom += other_bottom; |
| 286 right -= other_right; |
| 287 top -= other_top; |
| 288 } |
| 289 |
| 290 void Deflate(const CFX_FloatRect& rt) { |
| 291 Deflate(rt.left, rt.bottom, rt.right, rt.top); |
| 292 } |
| 293 |
| 294 void Translate(FX_FLOAT e, FX_FLOAT f) { |
| 295 left += e; |
| 296 right += e; |
| 297 top += f; |
| 298 bottom += f; |
| 299 } |
| 300 |
| 301 static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); |
| 302 |
| 303 FX_FLOAT left; |
| 304 FX_FLOAT bottom; |
| 305 FX_FLOAT right; |
| 306 FX_FLOAT top; |
| 307 }; |
| 308 |
| 309 // LTWH rectangles (y-axis runs downwards). |
123 template <class baseType> | 310 template <class baseType> |
124 class CFX_RTemplate { | 311 class CFX_RTemplate { |
125 public: | 312 public: |
126 typedef CFX_PSTemplate<baseType> FXT_POINT; | 313 typedef CFX_PSTemplate<baseType> FXT_POINT; |
127 typedef CFX_PSTemplate<baseType> FXT_SIZE; | 314 typedef CFX_PSTemplate<baseType> FXT_SIZE; |
128 typedef CFX_VTemplate<baseType> FXT_VECTOR; | 315 typedef CFX_VTemplate<baseType> FXT_VECTOR; |
129 typedef CFX_RTemplate<baseType> FXT_RECT; | 316 typedef CFX_RTemplate<baseType> FXT_RECT; |
130 void Set(baseType left, baseType top, baseType width, baseType height) { | 317 void Set(baseType left, baseType top, baseType width, baseType height) { |
131 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, | 318 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, |
132 FXT_RECT::height = height; | 319 FXT_RECT::height = height; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 baseType left, top; | 530 baseType left, top; |
344 baseType width, height; | 531 baseType width, height; |
345 }; | 532 }; |
346 typedef CFX_RTemplate<int32_t> CFX_Rect; | 533 typedef CFX_RTemplate<int32_t> CFX_Rect; |
347 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; | 534 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; |
348 typedef CFX_RTemplate<int32_t>* FX_LPRECT; | 535 typedef CFX_RTemplate<int32_t>* FX_LPRECT; |
349 typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF; | 536 typedef CFX_RTemplate<FX_FLOAT>* FX_LPRECTF; |
350 typedef CFX_RTemplate<int32_t> const* FX_LPCRECT; | 537 typedef CFX_RTemplate<int32_t> const* FX_LPCRECT; |
351 typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF; | 538 typedef CFX_RTemplate<FX_FLOAT> const* FX_LPCRECTF; |
352 typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; | 539 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 | 540 |
545 class CFX_Matrix { | 541 class CFX_Matrix { |
546 public: | 542 public: |
547 CFX_Matrix() { SetIdentity(); } | 543 CFX_Matrix() { SetIdentity(); } |
548 | 544 |
549 CFX_Matrix(FX_FLOAT a1, | 545 CFX_Matrix(FX_FLOAT a1, |
550 FX_FLOAT b1, | 546 FX_FLOAT b1, |
551 FX_FLOAT c1, | 547 FX_FLOAT c1, |
552 FX_FLOAT d1, | 548 FX_FLOAT d1, |
553 FX_FLOAT e1, | 549 FX_FLOAT e1, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 public: | 661 public: |
666 FX_FLOAT a; | 662 FX_FLOAT a; |
667 FX_FLOAT b; | 663 FX_FLOAT b; |
668 FX_FLOAT c; | 664 FX_FLOAT c; |
669 FX_FLOAT d; | 665 FX_FLOAT d; |
670 FX_FLOAT e; | 666 FX_FLOAT e; |
671 FX_FLOAT f; | 667 FX_FLOAT f; |
672 }; | 668 }; |
673 | 669 |
674 #endif // CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ | 670 #endif // CORE_INCLUDE_FXCRT_FX_COORDINATES_H_ |
OLD | NEW |