From a951717433475fba23f821f78ab8ffac744deb2c Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Sun, 24 Jul 2011 13:22:46 +0200 Subject: [PATCH] [Positioning] Add Stock::in_which_area_is() --- owlps-positioning/src/stock.cc | 21 +++++++++++++++++++++ owlps-positioning/src/stock.hh | 2 ++ 2 files changed, 23 insertions(+) diff --git a/owlps-positioning/src/stock.cc b/owlps-positioning/src/stock.cc index 53cf043..01e4304 100644 --- a/owlps-positioning/src/stock.cc +++ b/owlps-positioning/src/stock.cc @@ -1,6 +1,7 @@ #include "stock.hh" #include "configuration.hh" #include "posexcept.hh" +#include "area.hh" using namespace std ; using std::tr1::unordered_map ; @@ -80,6 +81,26 @@ const Building& Stock::get_building(const string &name) } +/** + * @returns A pointer to the first Area in which \em point was found. + * @returns NULL if \em point does not belong to any Area. + */ +const Area* Stock::in_which_area_is(const Point3D point) +{ + for (unordered_map::const_iterator + b = buildings.begin() ; b != buildings.end() ; ++b) + { + const unordered_map &areas = b->second.get_areas() ; + for (unordered_map::const_iterator + a = areas.begin() ; a != areas.end() ; ++a) + if (a->second->contains_point(point)) + return a->second ; + } + + return NULL ; +} + + /* *** Waypoint operations *** */ diff --git a/owlps-positioning/src/stock.hh b/owlps-positioning/src/stock.hh index fb8a50a..8c4cac7 100644 --- a/owlps-positioning/src/stock.hh +++ b/owlps-positioning/src/stock.hh @@ -50,6 +50,8 @@ public: static const Building& get_building(const std::string &name) ; /// Searches for a Building and creates it if it does not exist static const Building& find_create_building(const std::string &name) ; + /// Searches the Area in which \em point is + static const Area* in_which_area_is(const Point3D point) ; //@} /** @name Waypoint operations */