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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 184 |
185 bool operator==(const CFX_FloatPoint& that) const { | 185 bool operator==(const CFX_FloatPoint& that) const { |
186 return x == that.x && y == that.y; | 186 return x == that.x && y == that.y; |
187 } | 187 } |
188 bool operator!=(const CFX_FloatPoint& that) const { return !(*this == that); } | 188 bool operator!=(const CFX_FloatPoint& that) const { return !(*this == that); } |
189 | 189 |
190 FX_FLOAT x; | 190 FX_FLOAT x; |
191 FX_FLOAT y; | 191 FX_FLOAT y; |
192 }; | 192 }; |
193 | 193 |
194 class CFX_FloatRect { | |
195 public: | |
196 CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {} | |
197 CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t) | |
198 : left(l), bottom(b), right(r), top(t) {} | |
199 | |
200 explicit CFX_FloatRect(const FX_FLOAT* pArray) | |
201 : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {} | |
202 | |
203 explicit CFX_FloatRect(const FX_RECT& rect); | |
204 | |
205 void Normalize(); | |
206 | |
207 void Reset() { | |
208 left = 0.0f; | |
209 right = 0.0f; | |
210 bottom = 0.0f; | |
211 top = 0.0f; | |
212 } | |
213 | |
214 bool IsEmpty() const { return left >= right || bottom >= top; } | |
215 bool Contains(const CFX_FloatRect& other_rect) const; | |
216 bool Contains(FX_FLOAT x, FX_FLOAT y) const; | |
217 | |
218 void Transform(const CFX_Matrix* pMatrix); | |
219 void Intersect(const CFX_FloatRect& other_rect); | |
220 void Union(const CFX_FloatRect& other_rect); | |
221 | |
222 FX_RECT GetInnerRect() const; | |
223 FX_RECT GetOuterRect() const; | |
224 FX_RECT GetClosestRect() const; | |
225 | |
226 int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); | |
227 | |
228 void InitRect(FX_FLOAT x, FX_FLOAT y) { | |
229 left = x; | |
230 right = x; | |
231 bottom = y; | |
232 top = y; | |
233 } | |
234 void UpdateRect(FX_FLOAT x, FX_FLOAT y); | |
235 | |
236 FX_FLOAT Width() const { return right - left; } | |
237 FX_FLOAT Height() const { return top - bottom; } | |
238 | |
239 void Inflate(FX_FLOAT x, FX_FLOAT y) { | |
240 Normalize(); | |
241 left -= x; | |
242 right += x; | |
243 bottom -= y; | |
244 top += y; | |
245 } | |
246 | |
247 void Inflate(FX_FLOAT other_left, | |
248 FX_FLOAT other_bottom, | |
249 FX_FLOAT other_right, | |
250 FX_FLOAT other_top) { | |
251 Normalize(); | |
252 left -= other_left; | |
253 bottom -= other_bottom; | |
254 right += other_right; | |
255 top += other_top; | |
256 } | |
257 | |
258 void Inflate(const CFX_FloatRect& rt) { | |
259 Inflate(rt.left, rt.bottom, rt.right, rt.top); | |
260 } | |
261 | |
262 void Deflate(FX_FLOAT x, FX_FLOAT y) { | |
263 Normalize(); | |
264 left += x; | |
265 right -= x; | |
266 bottom += y; | |
267 top -= y; | |
268 } | |
269 | |
270 void Deflate(FX_FLOAT other_left, | |
271 FX_FLOAT other_bottom, | |
272 FX_FLOAT other_right, | |
273 FX_FLOAT other_top) { | |
274 Normalize(); | |
275 left += other_left; | |
276 bottom += other_bottom; | |
277 right -= other_right; | |
278 top -= other_top; | |
279 } | |
280 | |
281 void Deflate(const CFX_FloatRect& rt) { | |
282 Deflate(rt.left, rt.bottom, rt.right, rt.top); | |
283 } | |
284 | |
285 void Translate(FX_FLOAT e, FX_FLOAT f) { | |
286 left += e; | |
287 right += e; | |
288 top += f; | |
289 bottom += f; | |
290 } | |
291 | |
292 static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); | |
293 | |
294 FX_RECT ToFxRect() const { | |
295 return FX_RECT(static_cast<int32_t>(left), static_cast<int32_t>(top), | |
296 static_cast<int32_t>(right), static_cast<int32_t>(bottom)); | |
297 } | |
298 | |
299 FX_FLOAT left; | |
300 FX_FLOAT bottom; | |
301 FX_FLOAT right; | |
302 FX_FLOAT top; | |
303 }; | |
304 | |
305 // LTWH rectangles (y-axis runs downwards). | 194 // LTWH rectangles (y-axis runs downwards). |
306 template <class baseType> | 195 template <class baseType> |
307 class CFX_RTemplate { | 196 class CFX_RTemplate { |
308 public: | 197 public: |
309 typedef CFX_PSTemplate<baseType> FXT_POINT; | 198 typedef CFX_PSTemplate<baseType> FXT_POINT; |
310 typedef CFX_PSTemplate<baseType> FXT_SIZE; | 199 typedef CFX_PSTemplate<baseType> FXT_SIZE; |
311 typedef CFX_VTemplate<baseType> FXT_VECTOR; | 200 typedef CFX_VTemplate<baseType> FXT_VECTOR; |
312 typedef CFX_RTemplate<baseType> FXT_RECT; | 201 typedef CFX_RTemplate<baseType> FXT_RECT; |
313 void Set(baseType dst_left, | 202 void Set(baseType dst_left, |
314 baseType dst_top, | 203 baseType dst_top, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 friend bool operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { | 427 friend bool operator!=(const FXT_RECT& rc1, const FXT_RECT& rc2) { |
539 return !(rc1 == rc2); | 428 return !(rc1 == rc2); |
540 } | 429 } |
541 baseType left, top; | 430 baseType left, top; |
542 baseType width, height; | 431 baseType width, height; |
543 }; | 432 }; |
544 typedef CFX_RTemplate<int32_t> CFX_Rect; | 433 typedef CFX_RTemplate<int32_t> CFX_Rect; |
545 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; | 434 typedef CFX_RTemplate<FX_FLOAT> CFX_RectF; |
546 typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; | 435 typedef CFX_ArrayTemplate<CFX_RectF> CFX_RectFArray; |
547 | 436 |
| 437 class CFX_FloatRect { |
| 438 public: |
| 439 CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {} |
| 440 CFX_FloatRect(FX_FLOAT l, FX_FLOAT b, FX_FLOAT r, FX_FLOAT t) |
| 441 : left(l), bottom(b), right(r), top(t) {} |
| 442 |
| 443 explicit CFX_FloatRect(const FX_FLOAT* pArray) |
| 444 : CFX_FloatRect(pArray[0], pArray[1], pArray[2], pArray[3]) {} |
| 445 |
| 446 explicit CFX_FloatRect(const FX_RECT& rect); |
| 447 |
| 448 void Normalize(); |
| 449 |
| 450 void Reset() { |
| 451 left = 0.0f; |
| 452 right = 0.0f; |
| 453 bottom = 0.0f; |
| 454 top = 0.0f; |
| 455 } |
| 456 |
| 457 bool IsEmpty() const { return left >= right || bottom >= top; } |
| 458 bool Contains(const CFX_FloatRect& other_rect) const; |
| 459 bool Contains(FX_FLOAT x, FX_FLOAT y) const; |
| 460 |
| 461 void Transform(const CFX_Matrix* pMatrix); |
| 462 void Intersect(const CFX_FloatRect& other_rect); |
| 463 void Union(const CFX_FloatRect& other_rect); |
| 464 |
| 465 FX_RECT GetInnerRect() const; |
| 466 FX_RECT GetOuterRect() const; |
| 467 FX_RECT GetClosestRect() const; |
| 468 |
| 469 int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects); |
| 470 |
| 471 void InitRect(FX_FLOAT x, FX_FLOAT y) { |
| 472 left = x; |
| 473 right = x; |
| 474 bottom = y; |
| 475 top = y; |
| 476 } |
| 477 void UpdateRect(FX_FLOAT x, FX_FLOAT y); |
| 478 |
| 479 FX_FLOAT Width() const { return right - left; } |
| 480 FX_FLOAT Height() const { return top - bottom; } |
| 481 |
| 482 void Inflate(FX_FLOAT x, FX_FLOAT y) { |
| 483 Normalize(); |
| 484 left -= x; |
| 485 right += x; |
| 486 bottom -= y; |
| 487 top += y; |
| 488 } |
| 489 |
| 490 void Inflate(FX_FLOAT other_left, |
| 491 FX_FLOAT other_bottom, |
| 492 FX_FLOAT other_right, |
| 493 FX_FLOAT other_top) { |
| 494 Normalize(); |
| 495 left -= other_left; |
| 496 bottom -= other_bottom; |
| 497 right += other_right; |
| 498 top += other_top; |
| 499 } |
| 500 |
| 501 void Inflate(const CFX_FloatRect& rt) { |
| 502 Inflate(rt.left, rt.bottom, rt.right, rt.top); |
| 503 } |
| 504 |
| 505 void Deflate(FX_FLOAT x, FX_FLOAT y) { |
| 506 Normalize(); |
| 507 left += x; |
| 508 right -= x; |
| 509 bottom += y; |
| 510 top -= y; |
| 511 } |
| 512 |
| 513 void Deflate(FX_FLOAT other_left, |
| 514 FX_FLOAT other_bottom, |
| 515 FX_FLOAT other_right, |
| 516 FX_FLOAT other_top) { |
| 517 Normalize(); |
| 518 left += other_left; |
| 519 bottom += other_bottom; |
| 520 right -= other_right; |
| 521 top -= other_top; |
| 522 } |
| 523 |
| 524 void Deflate(const CFX_FloatRect& rt) { |
| 525 Deflate(rt.left, rt.bottom, rt.right, rt.top); |
| 526 } |
| 527 |
| 528 void Translate(FX_FLOAT e, FX_FLOAT f) { |
| 529 left += e; |
| 530 right += e; |
| 531 top += f; |
| 532 bottom += f; |
| 533 } |
| 534 |
| 535 static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints); |
| 536 |
| 537 FX_RECT ToFxRect() const { |
| 538 return FX_RECT(static_cast<int32_t>(left), static_cast<int32_t>(top), |
| 539 static_cast<int32_t>(right), static_cast<int32_t>(bottom)); |
| 540 } |
| 541 |
| 542 static CFX_FloatRect FromCFXRectF(const CFX_RectF& rect) { |
| 543 return CFX_FloatRect(rect.left, rect.top, rect.right(), rect.bottom()); |
| 544 } |
| 545 |
| 546 FX_FLOAT left; |
| 547 FX_FLOAT bottom; |
| 548 FX_FLOAT right; |
| 549 FX_FLOAT top; |
| 550 }; |
| 551 |
548 class CFX_Matrix { | 552 class CFX_Matrix { |
549 public: | 553 public: |
550 CFX_Matrix() { SetIdentity(); } | 554 CFX_Matrix() { SetIdentity(); } |
551 | 555 |
552 CFX_Matrix(FX_FLOAT a1, | 556 CFX_Matrix(FX_FLOAT a1, |
553 FX_FLOAT b1, | 557 FX_FLOAT b1, |
554 FX_FLOAT c1, | 558 FX_FLOAT c1, |
555 FX_FLOAT d1, | 559 FX_FLOAT d1, |
556 FX_FLOAT e1, | 560 FX_FLOAT e1, |
557 FX_FLOAT f1) { | 561 FX_FLOAT f1) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 public: | 662 public: |
659 FX_FLOAT a; | 663 FX_FLOAT a; |
660 FX_FLOAT b; | 664 FX_FLOAT b; |
661 FX_FLOAT c; | 665 FX_FLOAT c; |
662 FX_FLOAT d; | 666 FX_FLOAT d; |
663 FX_FLOAT e; | 667 FX_FLOAT e; |
664 FX_FLOAT f; | 668 FX_FLOAT f; |
665 }; | 669 }; |
666 | 670 |
667 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ | 671 #endif // CORE_FXCRT_INCLUDE_FX_COORDINATES_H_ |
OLD | NEW |