[Positioning] Stock::closest_calibration_request()
Add CalibrationRequest Stock::closest_calibration_request(Request).
This commit is contained in:
parent
920e4491ef
commit
a39e06cf19
|
@ -256,8 +256,9 @@ const ReferencePoint& Stock::
|
|||
closest_reference_point(const Request &request)
|
||||
{
|
||||
if (reference_points.empty())
|
||||
throw element_not_found("Cannot search for the closest reference \
|
||||
point: reference point list is empty!") ;
|
||||
throw element_not_found(
|
||||
"Cannot search for the closest reference point: reference points'"
|
||||
" list is empty!") ;
|
||||
|
||||
unordered_set<ReferencePoint>::const_iterator i =
|
||||
reference_points.begin() ;
|
||||
|
@ -289,3 +290,30 @@ find_create_calibration_request(const CalibrationRequest &request)
|
|||
calibration_requests.insert(request) ;
|
||||
return *ret.first ;
|
||||
}
|
||||
|
||||
|
||||
const CalibrationRequest& Stock::
|
||||
closest_calibration_request(const Request &request)
|
||||
{
|
||||
if (calibration_requests.empty())
|
||||
throw element_not_found(
|
||||
"Cannot search for the closest calibration request: calibration"
|
||||
" requests' list is empty!") ;
|
||||
|
||||
unordered_set<CalibrationRequest>::const_iterator i =
|
||||
calibration_requests.begin() ;
|
||||
float distance = i->ss_square_distance(request) ;
|
||||
unordered_set<CalibrationRequest>::const_iterator closest = i ;
|
||||
|
||||
for (++i ; i != calibration_requests.end() ; ++i)
|
||||
{
|
||||
float tmp_distance = i->ss_square_distance(request) ;
|
||||
if (tmp_distance < distance)
|
||||
{
|
||||
distance = tmp_distance ;
|
||||
closest = i ;
|
||||
}
|
||||
}
|
||||
|
||||
return *closest ;
|
||||
}
|
||||
|
|
|
@ -101,6 +101,10 @@ public:
|
|||
/// Search for a CalibrationRequest and add it if it does not exist
|
||||
static const CalibrationRequest&
|
||||
find_create_calibration_request(const CalibrationRequest &request) ;
|
||||
/// \brief Search for the closest CalibrationRequest (in the signal
|
||||
/// strength space) to a given Request
|
||||
static const CalibrationRequest&
|
||||
closest_calibration_request(const Request &request) ;
|
||||
//@}
|
||||
|
||||
/// Deletes all elements in all attributes
|
||||
|
|
Loading…
Reference in New Issue