owlps/owlps-positioning/src/result.cc

85 lines
1.4 KiB
C++

#include "result.hh"
#include "request.hh"
#include <sstream>
using namespace std ;
/* *** Constructors *** */
Result::Result(const Point3D &_position, const std::string &_algorithm,
const Point3D &real_position):
position(_position), algorithm(_algorithm)
{
compute_error(real_position) ;
}
/* *** Write accessors *** */
void Result::compute_error(const Point3D &real_position)
{
error = position.distance(real_position) ;
}
/* *** Operators *** */
const Result& Result::operator=(const Result &source)
{
if (this == &source)
return *this ;
algorithm = source.algorithm ;
position = source.position ;
return *this ;
}
bool Result::operator==(const Result &source) const
{
return
algorithm == source.algorithm &&
position == source.position ;
}
/**
* @return the result as a CSV string, \em without trailing '\n'.
*/
const string Result::to_csv() const
{
ostringstream csv_line ;
csv_line
<< algorithm
<< ';' << position.get_x()
<< ';' << position.get_y()
<< ';' << position.get_z()
<< ';' << "Error"
<< ';' << error ;
return csv_line.str() ;
}
std::ostream& operator<<(ostream &os, const Result &r)
{
os
<< "The result of the algorithm " << r.algorithm
<< " is: " << r.position ;
if (r.error >= 0)
os << ", error = " << r.error << " m" ;
return os ;
}