summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Fernando Silva <luizinho_mack@yahoo.com.br>2024-09-11 18:51:38 -0300
committerLuiz Fernando Silva <luizinho_mack@yahoo.com.br>2024-09-12 11:04:57 -0300
commit293cc2126ecb5d3ee5c14adb52fce865ffa5d8fe (patch)
tree351e71e331603bdfe776d7a23ec11d1a3cabcba4
parent2c136e6170a40f58f2dfb89d32eadfca7156ef37 (diff)
downloadredot-engine-293cc2126ecb5d3ee5c14adb52fce865ffa5d8fe.tar.gz
Avoid expensive sqrt operation in hot loop of BitMap.grow_mask
-rw-r--r--scene/resources/bit_map.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp
index 653a4f4949..53f97fefc9 100644
--- a/scene/resources/bit_map.cpp
+++ b/scene/resources/bit_map.cpp
@@ -559,6 +559,7 @@ void BitMap::grow_mask(int p_pixels, const Rect2i &p_rect) {
bool bit_value = p_pixels > 0;
p_pixels = Math::abs(p_pixels);
+ const int pixels2 = p_pixels * p_pixels;
Rect2i r = Rect2i(0, 0, width, height).intersection(p_rect);
@@ -588,8 +589,8 @@ void BitMap::grow_mask(int p_pixels, const Rect2i &p_rect) {
}
}
- float d = Point2(j, i).distance_to(Point2(x, y)) - CMP_EPSILON;
- if (d > p_pixels) {
+ float d = Point2(j, i).distance_squared_to(Point2(x, y)) - CMP_EPSILON2;
+ if (d > pixels2) {
continue;
}