Skip to content

Commit

Permalink
Fixed some minor code styling issues. Removed some minor redundant ca…
Browse files Browse the repository at this point in the history
…lculations for a small performance enhancement with zone detection.
  • Loading branch information
ebbyd3 authored and enricogior committed Sep 26, 2019
1 parent af67f77 commit a8f0d32
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/modules/fancyzones/lib/ZoneSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,31 @@ IFACEMETHODIMP ZoneSet::RemoveZone(winrt::com_ptr<IZone> zone) noexcept
IFACEMETHODIMP_(winrt::com_ptr<IZone>) ZoneSet::ZoneFromPoint(POINT pt) noexcept
{
winrt::com_ptr<IZone> smallestKnownZone = nullptr;
// To reduce redundant calculations, we will store the last known zones area.
int smallestKnownZoneArea = INT32_MAX;
for (auto iter = m_zones.begin(); iter != m_zones.end(); iter++)
{
if (winrt::com_ptr<IZone> zone = iter->try_as<IZone>())
{
RECT* newZoneRect = &zone->GetZoneRect();
if (PtInRect(newZoneRect, pt))
{
if(smallestKnownZone == nullptr)
if (smallestKnownZone == nullptr)
{
smallestKnownZone = zone;

RECT* r = &smallestKnownZone->GetZoneRect();
smallestKnownZoneArea = (r->right-r->left)*(r->bottom-r->top);
}
else
{
RECT* r = &smallestKnownZone->GetZoneRect();
int knownZoneArea = (r->right-r->left)*(r->bottom-r->top);

int newZoneArea = (newZoneRect->right-newZoneRect->left)*(newZoneRect->bottom-newZoneRect->top);

if(newZoneArea<knownZoneArea)
if (newZoneArea<smallestKnownZoneArea)
{
smallestKnownZone = zone;
newZoneArea = smallestKnownZoneArea;
}
}
}
}
Expand Down

0 comments on commit a8f0d32

Please sign in to comment.