From 74980248050431c1b17f33dff09dfe829f822394 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 14 Jul 2020 10:15:56 -0600 Subject: [PATCH] LibGfx: Minor IntRect::shatter and FloatRect::shatter optimization All the shards always intersect unless they're empty. So rather than checking for intersection, just check whether they're empty or not. --- Libraries/LibGfx/FloatRect.cpp | 8 ++++---- Libraries/LibGfx/Rect.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Libraries/LibGfx/FloatRect.cpp b/Libraries/LibGfx/FloatRect.cpp index 6565b3a6c1..0a50961555 100644 --- a/Libraries/LibGfx/FloatRect.cpp +++ b/Libraries/LibGfx/FloatRect.cpp @@ -96,13 +96,13 @@ Vector FloatRect::shatter(const FloatRect& hammer) const right() - hammer.right(), min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y()) }; - if (intersects(top_shard)) + if (!top_shard.is_empty()) pieces.unchecked_append(top_shard); - if (intersects(bottom_shard)) + if (!bottom_shard.is_empty()) pieces.unchecked_append(bottom_shard); - if (intersects(left_shard)) + if (!left_shard.is_empty()) pieces.unchecked_append(left_shard); - if (intersects(right_shard)) + if (!right_shard.is_empty()) pieces.unchecked_append(right_shard); return pieces; diff --git a/Libraries/LibGfx/Rect.cpp b/Libraries/LibGfx/Rect.cpp index f824f2b5ec..c654cb0d25 100644 --- a/Libraries/LibGfx/Rect.cpp +++ b/Libraries/LibGfx/Rect.cpp @@ -97,13 +97,13 @@ Vector IntRect::shatter(const IntRect& hammer) const right() - hammer.right(), min((hammer.y() + hammer.height()), (y() + height())) - max(hammer.y(), y()) }; - if (intersects(top_shard)) + if (!top_shard.is_empty()) pieces.unchecked_append(top_shard); - if (intersects(bottom_shard)) + if (!bottom_shard.is_empty()) pieces.unchecked_append(bottom_shard); - if (intersects(left_shard)) + if (!left_shard.is_empty()) pieces.unchecked_append(left_shard); - if (intersects(right_shard)) + if (!right_shard.is_empty()) pieces.unchecked_append(right_shard); return pieces;