/*
 * 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_MINMAX_HH_
#define _OWLPS_POSITIONING_MINMAX_HH_

#include "trilaterationmethod.hh"

/// Multilaterates using the Lassabe's MinMax algorithm
class MinMax: public TrilaterationMethod
{
private:
  float min ;
  Point3D centre ;
  std::unordered_map<const CapturePoint*, float> const *cp_distances ;

  void iterate(const float x, const float y, const float z) ;

protected:
  const Point3D start ;
  const Point3D stop ;
  float step ;

  static constexpr float MINMAX_DEFAULT_STEP = 0.5 ;
  static constexpr float INFINITE = 1000000 ;

public:
  MinMax(const Point3D &_start,
         const Point3D &_stop,
         const float _step = MINMAX_DEFAULT_STEP):
    min(INFINITE),
    start(_start), stop(_stop), step(_step) {}

  ~MinMax(void) {}

  Point3D trilaterate(
    const std::unordered_map<const CapturePoint*, float> &_cp_distances) ;
  Point3D trilaterate_2d(
    const std::unordered_map<const CapturePoint*, float> &_cp_distances,
    float z) ;
} ;

#endif // _OWLPS_POSITIONING_MINMAX_HH_
