Skip to content
Permalink
Browse files

Use early return

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
  • Loading branch information...
lauft committed Apr 11, 2019
1 parent 6f43909 commit b3799ede037c905a464d381967fcd869b8777f57
Showing with 34 additions and 37 deletions.
  1. +34 −37 src/Chart.cpp
@@ -184,55 +184,52 @@ std::pair<int, int> Chart::determineHourRange (
const Interval &filter,
const std::vector<Interval> &tracked)
{
// Default to the full day.
auto first_hour = 0;
auto last_hour = 23;
// If there is no data, show the whole day.
if (tracked.empty ())
{
return std::make_pair (0, 23);
}

// If there is no data,
// show the whole day.
if (!tracked.empty ())
// Get the extreme time range for the filtered data.
auto first_hour = 23;
auto last_hour = 0;

for (Datetime day = filter.start; day < filter.end; day++)
{
// Get the extreme time range for the filtered data.
first_hour = 23;
last_hour = 0;
auto day_range = getFullDay (day);

for (Datetime day = filter.start; day < filter.end; day++)
for (auto &track : tracked)
{
auto day_range = getFullDay (day);

for (auto &track : tracked)
if (day_range.overlaps (track))
{
if (day_range.overlaps (track))
Interval clipped = clip (track, day_range);
if (track.is_open ())
{
Interval clipped = clip (track, day_range);
if (track.is_open ())
{
clipped.end = reference_datetime;
}
clipped.end = reference_datetime;
}

if (clipped.start.hour () < first_hour)
{
first_hour = clipped.start.hour ();
}
if (clipped.start.hour () < first_hour)
{
first_hour = clipped.start.hour ();
}

if (!clipped.is_open () && clipped.end.hour () > last_hour)
{
last_hour = clipped.end.hour ();
}
if (!clipped.is_open () && clipped.end.hour () > last_hour)
{
last_hour = clipped.end.hour ();
}
}
}
}

if (first_hour == 23 && last_hour == 0)
{
first_hour = reference_datetime.hour ();
last_hour = std::min (first_hour + 1, 23);
}
else
{
first_hour = std::max (first_hour - 1, 0);
last_hour = std::min (last_hour + 1, 23);
}
if (first_hour == 23 && last_hour == 0)
{
first_hour = reference_datetime.hour ();
last_hour = std::min (first_hour + 1, 23);
}
else
{
first_hour = std::max (first_hour - 1, 0);
last_hour = std::min (last_hour + 1, 23);
}

return std::make_pair (first_hour, last_hour);

0 comments on commit b3799ed

Please sign in to comment.
You can’t perform that action at this time.