summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2021-01-08 10:16:18 +0000
committerGitHub <noreply@github.com>2021-01-08 11:16:18 +0100
commit9b800a96ed32720ff60b74e498a0e0a6351004f9 (patch)
tree3f287d339e15c4902ee415556475fd9b2918d33c /src/linkgraph
parentc1fddb9a6ae5c3af6865461a7295788a341011a2 (diff)
downloadopenttd-9b800a96ed32720ff60b74e498a0e0a6351004f9.tar.xz
Codechange: Remove min/max functions in favour of STL variants (#8502)
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/demands.cpp8
-rw-r--r--src/linkgraph/linkgraph.cpp9
-rw-r--r--src/linkgraph/linkgraph.h4
-rw-r--r--src/linkgraph/linkgraph_gui.cpp6
-rw-r--r--src/linkgraph/linkgraphjob.cpp6
-rw-r--r--src/linkgraph/linkgraphjob.h2
-rw-r--r--src/linkgraph/mcf.cpp4
7 files changed, 19 insertions, 20 deletions
diff --git a/src/linkgraph/demands.cpp b/src/linkgraph/demands.cpp
index f1b714820..c31e8896f 100644
--- a/src/linkgraph/demands.cpp
+++ b/src/linkgraph/demands.cpp
@@ -45,7 +45,7 @@ public:
*/
inline void SetDemandPerNode(uint num_demands)
{
- this->demand_per_node = max(this->supply_sum / num_demands, 1U);
+ this->demand_per_node = std::max(this->supply_sum / num_demands, 1U);
}
/**
@@ -57,7 +57,7 @@ public:
*/
inline uint EffectiveSupply(const Node &from, const Node &to)
{
- return max(from.Supply() * max(1U, to.Supply()) * this->mod_size / 100 / this->demand_per_node, 1U);
+ return std::max(from.Supply() * std::max(1U, to.Supply()) * this->mod_size / 100 / this->demand_per_node, 1U);
}
/**
@@ -134,7 +134,7 @@ void SymmetricScaler::SetDemands(LinkGraphJob &job, NodeID from_id, NodeID to_id
uint undelivered = job[to_id].UndeliveredSupply();
if (demand_back > undelivered) {
demand_back = undelivered;
- demand_forw = max(1U, demand_back * 100 / this->mod_size);
+ demand_forw = std::max(1U, demand_back * 100 / this->mod_size);
}
this->Scaler::SetDemands(job, to_id, from_id, demand_back);
}
@@ -230,7 +230,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
demand_forw = 1;
}
- demand_forw = min(demand_forw, job[from_id].UndeliveredSupply());
+ demand_forw = std::min(demand_forw, job[from_id].UndeliveredSupply());
scaler.SetDemands(job, from_id, to_id, demand_forw);
diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp
index 5185d07b7..93af907fc 100644
--- a/src/linkgraph/linkgraph.cpp
+++ b/src/linkgraph/linkgraph.cpp
@@ -71,7 +71,7 @@ void LinkGraph::Compress()
for (NodeID node2 = 0; node2 < this->Size(); ++node2) {
BaseEdge &edge = this->edges[node1][node2];
if (edge.capacity > 0) {
- edge.capacity = max(1U, edge.capacity / 2);
+ edge.capacity = std::max(1U, edge.capacity / 2);
edge.usage /= 2;
}
}
@@ -163,8 +163,7 @@ NodeID LinkGraph::AddNode(const Station *st)
this->nodes.emplace_back();
/* Avoid reducing the height of the matrix as that is expensive and we
* most likely will increase it again later which is again expensive. */
- this->edges.Resize(new_node + 1U,
- max(new_node + 1U, this->edges.Height()));
+ this->edges.Resize(new_node + 1U, std::max(new_node + 1U, this->edges.Height()));
this->nodes[new_node].Init(st->xy, st->index,
HasBit(good.status, GoodsEntry::GES_ACCEPTANCE));
@@ -266,8 +265,8 @@ void LinkGraph::Edge::Update(uint capacity, uint usage, EdgeUpdateMode mode)
this->edge.capacity += capacity;
this->edge.usage += usage;
} else if (mode & EUM_REFRESH) {
- this->edge.capacity = max(this->edge.capacity, capacity);
- this->edge.usage = max(this->edge.usage, usage);
+ this->edge.capacity = std::max(this->edge.capacity, capacity);
+ this->edge.usage = std::max(this->edge.usage, usage);
}
if (mode & EUM_UNRESTRICTED) this->edge.last_unrestricted_update = _date;
if (mode & EUM_RESTRICTED) this->edge.last_restricted_update = _date;
diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h
index 7362b7d56..99348daa1 100644
--- a/src/linkgraph/linkgraph.h
+++ b/src/linkgraph/linkgraph.h
@@ -113,7 +113,7 @@ public:
* Get the date of the last update to any part of the edge's capacity.
* @return Last update.
*/
- Date LastUpdate() const { return max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
+ Date LastUpdate() const { return std::max(this->edge.last_unrestricted_update, this->edge.last_restricted_update); }
};
/**
@@ -453,7 +453,7 @@ public:
*/
inline static uint Scale(uint val, uint target_age, uint orig_age)
{
- return val > 0 ? max(1U, val * target_age / orig_age) : 0;
+ return val > 0 ? std::max(1U, val * target_age / orig_age) : 0;
}
/** Bare constructor, only for save/load. */
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp
index fa4002e2b..efdf425da 100644
--- a/src/linkgraph/linkgraph_gui.cpp
+++ b/src/linkgraph/linkgraph_gui.cpp
@@ -224,7 +224,7 @@ void LinkGraphOverlay::AddLinks(const Station *from, const Station *to)
{
/* multiply the numbers by 32 in order to avoid comparing to 0 too often. */
if (cargo.capacity == 0 ||
- max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < max(new_usg, new_plan) * 32 / (new_cap + 1)) {
+ std::max(cargo.usage, cargo.planned) * 32 / (cargo.capacity + 1) < std::max(new_usg, new_plan) * 32 / (new_cap + 1)) {
cargo.capacity = new_cap;
cargo.usage = new_usg;
cargo.planned = new_plan;
@@ -272,7 +272,7 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
*/
void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
{
- uint usage_or_plan = min(cargo.capacity * 2 + 1, max(cargo.usage, cargo.planned));
+ uint usage_or_plan = std::min(cargo.capacity * 2 + 1, std::max(cargo.usage, cargo.planned));
int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)];
int dash = cargo.shared ? this->scale * 4 : 0;
@@ -302,7 +302,7 @@ void LinkGraphOverlay::DrawStationDots(const DrawPixelInfo *dpi) const
Point pt = this->GetStationMiddle(st);
if (!this->IsPointVisible(pt, dpi, 3 * this->scale)) continue;
- uint r = this->scale * 2 + this->scale * 2 * min(200, i->second) / 200;
+ uint r = this->scale * 2 + this->scale * 2 * std::min(200U, i->second) / 200;
LinkGraphOverlay::DrawVertex(pt.x, pt.y, r,
_colour_gradient[st->owner != OWNER_NONE ?
diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp
index e23c23b47..5e69dbeba 100644
--- a/src/linkgraph/linkgraphjob.cpp
+++ b/src/linkgraph/linkgraphjob.cpp
@@ -223,8 +223,8 @@ void LinkGraphJob::NodeAnnotation::Init(uint supply)
*/
void Path::Fork(Path *base, uint cap, int free_cap, uint dist)
{
- this->capacity = min(base->capacity, cap);
- this->free_capacity = min(base->free_capacity, free_cap);
+ this->capacity = std::min(base->capacity, cap);
+ this->free_capacity = std::min(base->free_capacity, free_cap);
this->distance = base->distance + dist;
assert(this->distance > 0);
if (this->parent != base) {
@@ -250,7 +250,7 @@ uint Path::AddFlow(uint new_flow, LinkGraphJob &job, uint max_saturation)
if (max_saturation != UINT_MAX) {
uint usable_cap = edge.Capacity() * max_saturation / 100;
if (usable_cap > edge.Flow()) {
- new_flow = min(new_flow, usable_cap - edge.Flow());
+ new_flow = std::min(new_flow, usable_cap - edge.Flow());
} else {
return 0;
}
diff --git a/src/linkgraph/linkgraphjob.h b/src/linkgraph/linkgraphjob.h
index 764365921..caeacd19d 100644
--- a/src/linkgraph/linkgraphjob.h
+++ b/src/linkgraph/linkgraphjob.h
@@ -392,7 +392,7 @@ public:
*/
inline static int GetCapacityRatio(int free, uint total)
{
- return Clamp(free, PATH_CAP_MIN_FREE, PATH_CAP_MAX_FREE) * PATH_CAP_MULTIPLIER / max(total, 1U);
+ return Clamp(free, PATH_CAP_MIN_FREE, PATH_CAP_MAX_FREE) * PATH_CAP_MULTIPLIER / std::max(total, 1U);
}
/**
diff --git a/src/linkgraph/mcf.cpp b/src/linkgraph/mcf.cpp
index ea1040941..003412850 100644
--- a/src/linkgraph/mcf.cpp
+++ b/src/linkgraph/mcf.cpp
@@ -235,7 +235,7 @@ bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint cap,
bool CapacityAnnotation::IsBetter(const CapacityAnnotation *base, uint cap,
int free_cap, uint dist) const
{
- int min_cap = Path::GetCapacityRatio(min(base->free_capacity, free_cap), min(base->capacity, cap));
+ int min_cap = Path::GetCapacityRatio(std::min(base->free_capacity, free_cap), std::min(base->capacity, cap));
int this_cap = this->GetCapacityRatio();
if (min_cap == this_cap) {
/* If the capacities are the same and the other path isn't disconnected
@@ -354,7 +354,7 @@ uint MCF1stPass::FindCycleFlow(const PathVector &path, const Path *cycle_begin)
uint flow = UINT_MAX;
const Path *cycle_end = cycle_begin;
do {
- flow = min(flow, cycle_begin->GetFlow());
+ flow = std::min(flow, cycle_begin->GetFlow());
cycle_begin = path[cycle_begin->GetNode()];
} while (cycle_begin != cycle_end);
return flow;