| 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_FXCRT_INCLUDE_FX_COORDINATES_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| 8 #define CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 // LTWH rectangles (y-axis runs downwards). | 314 // LTWH rectangles (y-axis runs downwards). |
| 315 template <class baseType> | 315 template <class baseType> |
| 316 class CFX_RTemplate { | 316 class CFX_RTemplate { |
| 317 public: | 317 public: |
| 318 typedef CFX_PSTemplate<baseType> FXT_POINT; | 318 typedef CFX_PSTemplate<baseType> FXT_POINT; |
| 319 typedef CFX_PSTemplate<baseType> FXT_SIZE; | 319 typedef CFX_PSTemplate<baseType> FXT_SIZE; |
| 320 typedef CFX_VTemplate<baseType> FXT_VECTOR; | 320 typedef CFX_VTemplate<baseType> FXT_VECTOR; |
| 321 typedef CFX_RTemplate<baseType> FXT_RECT; | 321 typedef CFX_RTemplate<baseType> FXT_RECT; |
| 322 void Set(baseType left, baseType top, baseType width, baseType height) { | 322 void Set(baseType dst_left, |
| 323 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::width = width, | 323 baseType dst_top, |
| 324 FXT_RECT::height = height; | 324 baseType dst_width, |
| 325 baseType dst_height) { |
| 326 left = dst_left; |
| 327 top = dst_top; |
| 328 width = dst_width; |
| 329 height = dst_height; |
| 325 } | 330 } |
| 326 void Set(baseType left, baseType top, const FXT_SIZE& size) { | 331 void Set(baseType dst_left, baseType dst_top, const FXT_SIZE& dst_size) { |
| 327 FXT_RECT::left = left, FXT_RECT::top = top, FXT_RECT::Size(size); | 332 left = dst_left; |
| 333 top = dst_top; |
| 334 Size(dst_size); |
| 328 } | 335 } |
| 329 void Set(const FXT_POINT& p, baseType width, baseType height) { | 336 void Set(const FXT_POINT& p, baseType dst_width, baseType dst_height) { |
| 330 TopLeft(p), FXT_RECT::width = width, FXT_RECT::height = height; | 337 TopLeft(p); |
| 338 width = dst_width; |
| 339 height = dst_height; |
| 331 } | 340 } |
| 332 void Set(const FXT_POINT& p1, const FXT_POINT& p2) { | 341 void Set(const FXT_POINT& p1, const FXT_POINT& p2) { |
| 333 TopLeft(p1), FXT_RECT::width = p2.x - p1.x, FXT_RECT::height = p2.y - p1.y, | 342 TopLeft(p1); |
| 334 FXT_RECT::Normalize(); | 343 width = p2.x - p1.x; |
| 344 height = p2.y - p1.y; |
| 345 Normalize(); |
| 335 } | 346 } |
| 336 void Set(const FXT_POINT& p, const FXT_VECTOR& v) { | 347 void Set(const FXT_POINT& p, const FXT_VECTOR& v) { |
| 337 TopLeft(p), FXT_RECT::width = v.x, FXT_RECT::height = v.y, | 348 TopLeft(p); |
| 338 FXT_RECT::Normalize(); | 349 width = v.x; |
| 350 height = v.y; |
| 351 Normalize(); |
| 339 } | 352 } |
| 340 void Reset() { | 353 void Reset() { |
| 341 FXT_RECT::left = FXT_RECT::top = FXT_RECT::width = FXT_RECT::height = 0; | 354 left = 0; |
| 355 top = 0; |
| 356 width = 0; |
| 357 height = 0; |
| 342 } | 358 } |
| 343 FXT_RECT& operator+=(const FXT_POINT& p) { | 359 FXT_RECT& operator+=(const FXT_POINT& p) { |
| 344 left += p.x, top += p.y; | 360 left += p.x; |
| 361 top += p.y; |
| 345 return *this; | 362 return *this; |
| 346 } | 363 } |
| 347 FXT_RECT& operator-=(const FXT_POINT& p) { | 364 FXT_RECT& operator-=(const FXT_POINT& p) { |
| 348 left -= p.x, top -= p.y; | 365 left -= p.x; |
| 366 top -= p.y; |
| 349 return *this; | 367 return *this; |
| 350 } | 368 } |
| 351 baseType right() const { return left + width; } | 369 baseType right() const { return left + width; } |
| 352 baseType bottom() const { return top + height; } | 370 baseType bottom() const { return top + height; } |
| 353 void Normalize() { | 371 void Normalize() { |
| 354 if (width < 0) { | 372 if (width < 0) { |
| 355 left += width; | 373 left += width; |
| 356 width = -width; | 374 width = -width; |
| 357 } | 375 } |
| 358 if (height < 0) { | 376 if (height < 0) { |
| 359 top += height; | 377 top += height; |
| 360 height = -height; | 378 height = -height; |
| 361 } | 379 } |
| 362 } | 380 } |
| 363 void Offset(baseType dx, baseType dy) { | 381 void Offset(baseType dx, baseType dy) { |
| 364 left += dx; | 382 left += dx; |
| 365 top += dy; | 383 top += dy; |
| 366 } | 384 } |
| 367 void Inflate(baseType x, baseType y) { | 385 void Inflate(baseType x, baseType y) { |
| 368 left -= x; | 386 left -= x; |
| 369 width += x * 2; | 387 width += x * 2; |
| 370 top -= y; | 388 top -= y; |
| 371 height += y * 2; | 389 height += y * 2; |
| 372 } | 390 } |
| 373 void Inflate(const FXT_POINT& p) { Inflate(p.x, p.y); } | 391 void Inflate(const FXT_POINT& p) { Inflate(p.x, p.y); } |
| 374 void Inflate(baseType left, baseType top, baseType right, baseType bottom) { | 392 void Inflate(baseType off_left, |
| 375 FXT_RECT::left -= left; | 393 baseType off_top, |
| 376 FXT_RECT::top -= top; | 394 baseType off_right, |
| 377 FXT_RECT::width += left + right; | 395 baseType off_bottom) { |
| 378 FXT_RECT::height += top + bottom; | 396 left -= off_left; |
| 397 top -= off_top; |
| 398 width += off_left + off_right; |
| 399 height += off_top + off_bottom; |
| 379 } | 400 } |
| 380 void Inflate(const FXT_RECT& rt) { | 401 void Inflate(const FXT_RECT& rt) { |
| 381 Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); | 402 Inflate(rt.left, rt.top, rt.left + rt.width, rt.top + rt.height); |
| 382 } | 403 } |
| 383 void Deflate(baseType x, baseType y) { | 404 void Deflate(baseType x, baseType y) { |
| 384 left += x; | 405 left += x; |
| 385 width -= x * 2; | 406 width -= x * 2; |
| 386 top += y; | 407 top += y; |
| 387 height -= y * 2; | 408 height -= y * 2; |
| 388 } | 409 } |
| 389 void Deflate(const FXT_POINT& p) { Deflate(p.x, p.y); } | 410 void Deflate(const FXT_POINT& p) { Deflate(p.x, p.y); } |
| 390 void Deflate(baseType left, baseType top, baseType right, baseType bottom) { | 411 void Deflate(baseType off_left, |
| 391 FXT_RECT::left += left; | 412 baseType off_top, |
| 392 FXT_RECT::top += top; | 413 baseType off_right, |
| 393 FXT_RECT::width -= left + right; | 414 baseType off_bottom) { |
| 394 FXT_RECT::height -= top + bottom; | 415 left += off_left; |
| 416 top += off_top; |
| 417 width -= off_left + off_right; |
| 418 height -= off_top + off_bottom; |
| 395 } | 419 } |
| 396 void Deflate(const FXT_RECT& rt) { | 420 void Deflate(const FXT_RECT& rt) { |
| 397 Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); | 421 Deflate(rt.left, rt.top, rt.top + rt.width, rt.top + rt.height); |
| 398 } | 422 } |
| 399 FX_BOOL IsEmpty() const { return width <= 0 || height <= 0; } | 423 FX_BOOL IsEmpty() const { return width <= 0 || height <= 0; } |
| 400 FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const { | 424 FX_BOOL IsEmpty(FX_FLOAT fEpsilon) const { |
| 401 return width <= fEpsilon || height <= fEpsilon; | 425 return width <= fEpsilon || height <= fEpsilon; |
| 402 } | 426 } |
| 403 void Empty() { width = height = 0; } | 427 void Empty() { width = height = 0; } |
| 404 FX_BOOL Contains(baseType x, baseType y) const { | 428 FX_BOOL Contains(baseType x, baseType y) const { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 width = br.x - left; | 481 width = br.x - left; |
| 458 height = br.y - top; | 482 height = br.y - top; |
| 459 } | 483 } |
| 460 FXT_POINT Center() const { | 484 FXT_POINT Center() const { |
| 461 FXT_POINT p; | 485 FXT_POINT p; |
| 462 p.x = left + width / 2; | 486 p.x = left + width / 2; |
| 463 p.y = top + height / 2; | 487 p.y = top + height / 2; |
| 464 return p; | 488 return p; |
| 465 } | 489 } |
| 466 void Union(baseType x, baseType y) { | 490 void Union(baseType x, baseType y) { |
| 467 baseType r = right(), b = bottom(); | 491 baseType r = right(); |
| 468 if (left > x) { | 492 baseType b = bottom(); |
| 493 if (left > x) |
| 469 left = x; | 494 left = x; |
| 470 } | 495 if (r < x) |
| 471 if (r < x) { | |
| 472 r = x; | 496 r = x; |
| 473 } | 497 if (top > y) |
| 474 if (top > y) { | |
| 475 top = y; | 498 top = y; |
| 476 } | 499 if (b < y) |
| 477 if (b < y) { | |
| 478 b = y; | 500 b = y; |
| 479 } | |
| 480 width = r - left; | 501 width = r - left; |
| 481 height = b - top; | 502 height = b - top; |
| 482 } | 503 } |
| 483 void Union(const FXT_POINT& p) { Union(p.x, p.y); } | 504 void Union(const FXT_POINT& p) { Union(p.x, p.y); } |
| 484 void Union(const FXT_RECT& rt) { | 505 void Union(const FXT_RECT& rt) { |
| 485 baseType r = right(), b = bottom(); | 506 baseType r = right(); |
| 486 if (left > rt.left) { | 507 baseType b = bottom(); |
| 508 if (left > rt.left) |
| 487 left = rt.left; | 509 left = rt.left; |
| 488 } | 510 if (r < rt.right()) |
| 489 if (r < rt.right()) { | |
| 490 r = rt.right(); | 511 r = rt.right(); |
| 491 } | 512 if (top > rt.top) |
| 492 if (top > rt.top) { | |
| 493 top = rt.top; | 513 top = rt.top; |
| 494 } | 514 if (b < rt.bottom()) |
| 495 if (b < rt.bottom()) { | |
| 496 b = rt.bottom(); | 515 b = rt.bottom(); |
| 497 } | |
| 498 width = r - left; | 516 width = r - left; |
| 499 height = b - top; | 517 height = b - top; |
| 500 } | 518 } |
| 501 void Intersect(const FXT_RECT& rt) { | 519 void Intersect(const FXT_RECT& rt) { |
| 502 baseType r = right(), b = bottom(); | 520 baseType r = right(); |
| 503 if (left < rt.left) { | 521 baseType b = bottom(); |
| 522 if (left < rt.left) |
| 504 left = rt.left; | 523 left = rt.left; |
| 505 } | 524 if (r > rt.right()) |
| 506 if (r > rt.right()) { | |
| 507 r = rt.right(); | 525 r = rt.right(); |
| 508 } | 526 if (top < rt.top) |
| 509 if (top < rt.top) { | |
| 510 top = rt.top; | 527 top = rt.top; |
| 511 } | 528 if (b > rt.bottom()) |
| 512 if (b > rt.bottom()) { | |
| 513 b = rt.bottom(); | 529 b = rt.bottom(); |
| 514 } | |
| 515 width = r - left; | 530 width = r - left; |
| 516 height = b - top; | 531 height = b - top; |
| 517 } | 532 } |
| 518 FX_BOOL IntersectWith(const FXT_RECT& rt) const { | 533 FX_BOOL IntersectWith(const FXT_RECT& rt) const { |
| 519 FXT_RECT rect = rt; | 534 FXT_RECT rect = rt; |
| 520 rect.Intersect(*this); | 535 rect.Intersect(*this); |
| 521 return !rect.IsEmpty(); | 536 return !rect.IsEmpty(); |
| 522 } | 537 } |
| 523 FX_BOOL IntersectWith(const FXT_RECT& rt, FX_FLOAT fEpsilon) const { | 538 FX_BOOL IntersectWith(const FXT_RECT& rt, FX_FLOAT fEpsilon) const { |
| 524 FXT_RECT rect = rt; | 539 FXT_RECT rect = rt; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 public: | 677 public: |
| 663 FX_FLOAT a; | 678 FX_FLOAT a; |
| 664 FX_FLOAT b; | 679 FX_FLOAT b; |
| 665 FX_FLOAT c; | 680 FX_FLOAT c; |
| 666 FX_FLOAT d; | 681 FX_FLOAT d; |
| 667 FX_FLOAT e; | 682 FX_FLOAT e; |
| 668 FX_FLOAT f; | 683 FX_FLOAT f; |
| 669 }; | 684 }; |
| 670 | 685 |
| 671 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 686 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
| OLD | NEW |