From 39e145e586385861b4e3ded70f7df0a29b56fa00 Mon Sep 17 00:00:00 2001 From: smatz Date: Fri, 7 Aug 2009 21:11:58 +0000 Subject: (svn r17106) -Codechange: move computation of station's catchment rectagle to separate function --- src/station.cpp | 31 ++++++++++++++++++++++--------- src/station_base.h | 1 + 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/station.cpp b/src/station.cpp index ee000a8e0..14d66cf60 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -239,6 +239,27 @@ uint Station::GetCatchmentRadius() const return ret; } +/** + * Determines catchment rectangle of this station + * @return clamped catchment rectangle + */ +Rect Station::GetCatchmentRect() const +{ + assert(!this->rect.IsEmpty()); + + /* Compute acceptance rectangle */ + int catchment_radius = this->GetCatchmentRadius(); + + Rect ret = { + max(this->rect.left - catchment_radius, 0), + max(this->rect.top - catchment_radius, 0), + min(this->rect.right + catchment_radius, MapMaxX()), + min(this->rect.bottom + catchment_radius, MapMaxY()) + }; + + return ret; +} + /** Rect and pointer to IndustryVector */ struct RectAndIndustryVector { Rect rect; @@ -290,16 +311,8 @@ void Station::RecomputeIndustriesNear() this->industries_near.Clear(); if (this->rect.IsEmpty()) return; - /* Compute acceptance rectangle */ - int catchment_radius = this->GetCatchmentRadius(); - RectAndIndustryVector riv = { - { - max(this->rect.left - catchment_radius, 0), - max(this->rect.top - catchment_radius, 0), - min(this->rect.right + catchment_radius, MapMaxX()), - min(this->rect.bottom + catchment_radius, MapMaxY()) - }, + this->GetCatchmentRect(), &this->industries_near }; diff --git a/src/station_base.h b/src/station_base.h index 7ddb92b39..c1b0640e1 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -101,6 +101,7 @@ public: static void RecomputeIndustriesNearForAll(); uint GetCatchmentRadius() const; + Rect GetCatchmentRect() const; /* virtual */ FORCEINLINE bool TileBelongsToRailStation(TileIndex tile) const { -- cgit v1.2.3-54-g00ecf