Skip to content

Commit f2ce94f

Browse files
committedSep 13, 2024
Merge pull request #96885 from LuizZak/grow_mask_sqrt_fix
Avoid expensive sqrt operation in hot loop of `BitMap.grow_mask`
2 parents 0f86f30 + 293cc21 commit f2ce94f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed
 

‎scene/resources/bit_map.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ void BitMap::grow_mask(int p_pixels, const Rect2i &p_rect) {
559559

560560
bool bit_value = p_pixels > 0;
561561
p_pixels = Math::abs(p_pixels);
562+
const int pixels2 = p_pixels * p_pixels;
562563

563564
Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect);
564565

@@ -588,8 +589,8 @@ void BitMap::grow_mask(int p_pixels, const Rect2i &p_rect) {
588589
}
589590
}
590591

591-
float d = Point2(j, i).distance_to(Point2(x, y)) - CMP_EPSILON;
592-
if (d > p_pixels) {
592+
float d = Point2(j, i).distance_squared_to(Point2(x, y)) - CMP_EPSILON2;
593+
if (d > pixels2) {
593594
continue;
594595
}
595596

0 commit comments

Comments
 (0)
Please sign in to comment.