From 5fd1ac47adc11be2ec24fdd03fd75b1f50b95726 Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 13 Apr 2014 10:52:19 +0000 Subject: [PATCH] (svn r26461) [1.4] -Backport from trunk: - Fix: Avoid division by 0 when scaling flow values [FS#5970] (r26448) - Feature: Draw links to match _settings_game.vehicle.road_side [FS#5961] (r26445) - Change: Use pkg-config for libpng as well (r26435, r26433, r26432) - Feature: Load button for heightmap list [FS#5953] (r26428) --- src/linkgraph/flowmapper.cpp | 6 ++++-- src/linkgraph/linkgraph_gui.cpp | 5 +++-- src/station_cmd.cpp | 2 ++ src/widgets/story_widget.h | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/linkgraph/flowmapper.cpp b/src/linkgraph/flowmapper.cpp index 79e0f09f3f..3daab44142 100644 --- a/src/linkgraph/flowmapper.cpp +++ b/src/linkgraph/flowmapper.cpp @@ -49,8 +49,10 @@ void FlowMapper::Run(LinkGraphJob &job) const FlowStatMap &flows = node.Flows(); flows.FinalizeLocalConsumption(node.Station()); if (this->scale) { - /* Scale by time the graph has been running without being compressed. */ - uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression(); + /* Scale by time the graph has been running without being compressed. Add 1 to avoid + * division by 0 if spawn date == last compression date. This matches + * LinkGraph::Monthly(). */ + uint runtime = job.JoinDate() - job.Settings().recalc_time - job.LastCompression() + 1; for (FlowStatMap::iterator i = flows.begin(); i != flows.end(); ++i) { i->second.ScaleToMonthly(runtime); } diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 9889ad87ae..093d7ab4d1 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -220,11 +220,12 @@ void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &c /* Move line a bit 90° against its dominant direction to prevent it from * being hidden below the grey line. */ + int side = _settings_game.vehicle.road_side ? 1 : -1; if (abs(pta.x - ptb.x) < abs(pta.y - ptb.y)) { - int offset_x = (pta.y > ptb.y ? 1 : -1) * this->scale; + int offset_x = (pta.y > ptb.y ? 1 : -1) * side * this->scale; GfxDrawLine(pta.x + offset_x, pta.y, ptb.x + offset_x, ptb.y, colour, this->scale, dash); } else { - int offset_y = (pta.x < ptb.x ? 1 : -1) * this->scale; + int offset_y = (pta.x < ptb.x ? 1 : -1) * side * this->scale; GfxDrawLine(pta.x, pta.y + offset_y, ptb.x, ptb.y + offset_y, colour, this->scale, dash); } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 55b6fae14d..d637d83c38 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -4314,9 +4314,11 @@ void FlowStat::ReleaseShare(StationID st) /** * Scale all shares from link graph's runtime to monthly values. * @param runtime Time the link graph has been running without compression. + * @pre runtime must be greater than 0 as we don't want infinite flow values. */ void FlowStat::ScaleToMonthly(uint runtime) { + assert(runtime > 0); SharesMap new_shares; uint share = 0; for (SharesMap::iterator i = this->shares.begin(); i != this->shares.end(); ++i) { diff --git a/src/widgets/story_widget.h b/src/widgets/story_widget.h index c3f279444d..139b6d2d6b 100644 --- a/src/widgets/story_widget.h +++ b/src/widgets/story_widget.h @@ -23,4 +23,4 @@ enum StoryBookWidgets { WID_SB_NEXT_PAGE, ///< Next button. }; -#endif /* WIDGETS_STORY_WIDGET_H */ \ No newline at end of file +#endif /* WIDGETS_STORY_WIDGET_H */