/*
 * This file is part of the Owl Positioning System (OwlPS) project.
 * It is subject to the copyright notice and license terms in the
 * COPYRIGHT.t2t file found in the top-level directory of this
 * distribution and at
 *   https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
 * No part of the OwlPS Project, including this file, may be copied,
 * modified, propagated, or distributed except according to the terms
 * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
 * distributed along with this file, either separately or by replacing
 * this notice by the COPYRIGHT.t2t file's contents.
 */


#ifndef _OWLPS_POSITIONING_TRILATERATIONALGORITHM_HH_
#define _OWLPS_POSITIONING_TRILATERATIONALGORITHM_HH_

#include "positioningalgorithm.hh"
#include "trilaterationmethod.hh"

/// Super-class of trilateration-based positioning algorithms
class TrilaterationAlgorithm: public virtual PositioningAlgorithm
{
protected:
  const Request *request ;

  std::unordered_map<const CapturePoint*, float> cp_distances ;
  TrilaterationMethod *trilateration_method ;

  /** @name Operations */
  //@{
  double make_constant_term(const Measurement &measurement) ;
  void compute_cp_distance_circles(void) ;
  Point3D trilaterate(void) ;
  Point3D trilaterate_2d(const float z) ;
  //@}

public:
  TrilaterationAlgorithm(void) ;

  virtual ~TrilaterationAlgorithm(void) ;

  /** @name Operations */
  //@{
  Result compute(const Request &_request) ;
  virtual float estimate_distance(const Measurement &measurement) = 0 ;
  //@}
} ;



inline Point3D TrilaterationAlgorithm::trilaterate()
{
  return trilateration_method->trilaterate(cp_distances) ;
}


inline Point3D TrilaterationAlgorithm::trilaterate_2d(const float z)
{
  return trilateration_method->trilaterate_2d(cp_distances, z) ;
}



#endif // _OWLPS_POSITIONING_TRILATERATIONALGORITHM_HH_
