| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #include "SkRTree.h" | 8 #include "SkRTree.h" |
| 10 #include "SkTSort.h" | 9 #include "SkTSort.h" |
| 11 | 10 |
| 12 static inline uint32_t get_area(const SkIRect& rect); | 11 static inline uint32_t get_area(const SkIRect& rect); |
| 13 static inline uint32_t get_overlap(const SkIRect& rect1, const SkIRect& rect2); | 12 static inline uint32_t get_overlap(const SkIRect& rect1, const SkIRect& rect2); |
| 14 static inline uint32_t get_margin(const SkIRect& rect); | 13 static inline uint32_t get_margin(const SkIRect& rect); |
| 15 static inline uint32_t get_overlap_increase(const SkIRect& rect1, const SkIRect&
rect2, | |
| 16 SkIRect expandBy); | |
| 17 static inline uint32_t get_area_increase(const SkIRect& rect1, SkIRect rect2); | 14 static inline uint32_t get_area_increase(const SkIRect& rect1, SkIRect rect2); |
| 18 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out); | 15 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out); |
| 19 | 16 |
| 20 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 17 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 21 | 18 |
| 22 SK_DEFINE_INST_COUNT(SkRTree) | 19 SK_DEFINE_INST_COUNT(SkRTree) |
| 23 | 20 |
| 24 SkRTree* SkRTree::Create(int minChildren, int maxChildren, SkScalar aspectRatio, | 21 SkRTree* SkRTree::Create(int minChildren, int maxChildren, SkScalar aspectRatio, |
| 25 bool sortWhenBulkLoading) { | 22 bool sortWhenBulkLoading) { |
| 26 if (minChildren < maxChildren && (maxChildren + 1) / 2 >= minChildren && | 23 if (minChildren < maxChildren && (maxChildren + 1) / 2 >= minChildren && |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // I suspect there's a more efficient way of computing this... | 461 // I suspect there's a more efficient way of computing this... |
| 465 return SkMax32(0, SkMin32(rect1.fRight, rect2.fRight) - SkMax32(rect1.fLeft,
rect2.fLeft)) * | 462 return SkMax32(0, SkMin32(rect1.fRight, rect2.fRight) - SkMax32(rect1.fLeft,
rect2.fLeft)) * |
| 466 SkMax32(0, SkMin32(rect1.fBottom, rect2.fBottom) - SkMax32(rect1.fTop
, rect2.fTop)); | 463 SkMax32(0, SkMin32(rect1.fBottom, rect2.fBottom) - SkMax32(rect1.fTop
, rect2.fTop)); |
| 467 } | 464 } |
| 468 | 465 |
| 469 // Get the margin (aka perimeter) | 466 // Get the margin (aka perimeter) |
| 470 static inline uint32_t get_margin(const SkIRect& rect) { | 467 static inline uint32_t get_margin(const SkIRect& rect) { |
| 471 return 2 * (rect.width() + rect.height()); | 468 return 2 * (rect.width() + rect.height()); |
| 472 } | 469 } |
| 473 | 470 |
| 474 static inline uint32_t get_overlap_increase(const SkIRect& rect1, const SkIRect&
rect2, | |
| 475 SkIRect expandBy) { | |
| 476 join_no_empty_check(rect1, &expandBy); | |
| 477 return get_overlap(expandBy, rect2) - get_overlap(rect1, rect2); | |
| 478 } | |
| 479 | |
| 480 static inline uint32_t get_area_increase(const SkIRect& rect1, SkIRect rect2) { | 471 static inline uint32_t get_area_increase(const SkIRect& rect1, SkIRect rect2) { |
| 481 join_no_empty_check(rect1, &rect2); | 472 join_no_empty_check(rect1, &rect2); |
| 482 return get_area(rect2) - get_area(rect1); | 473 return get_area(rect2) - get_area(rect1); |
| 483 } | 474 } |
| 484 | 475 |
| 485 // Expand 'out' to include 'joinWith' | 476 // Expand 'out' to include 'joinWith' |
| 486 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { | 477 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { |
| 487 // since we check for empty bounds on insert, we know we'll never have empty
rects | 478 // since we check for empty bounds on insert, we know we'll never have empty
rects |
| 488 // and we can save the empty check that SkIRect::join requires | 479 // and we can save the empty check that SkIRect::join requires |
| 489 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } | 480 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } |
| 490 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } | 481 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } |
| 491 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } | 482 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } |
| 492 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } | 483 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } |
| 493 } | 484 } |
| OLD | NEW |