bool ribi::Geometry::IsCounterClockwise(const Doubles& angles) const noexcept
{
  const int sz = static_cast<int>(angles.size());
  assert(sz >= 2 && "Need at least two angles to determine if these are counter-clockwise");
  for (int i=0; i!=sz-1; ++i)
  {
    if (!IsCounterClockwise(angles[i],angles[i+1])) return false;
  }

  //Calculate cumulative clockwise distance
  const double tau{boost::math::constants::two_pi<double>()};
  double sum{0.0};
  for (int i=0; i!=sz-1; ++i)
  {
    const double diff{angles[i] - angles[i+1]}; //Order reversed compared to IsClockwise
    if (diff > 0.0)
    {
      sum += diff;
    }
    else
    {
      assert(diff + tau > 0.0);
      sum += (diff + tau);
    }
  }
  return sum < tau;
}
Ejemplo n.º 2
0
// calcule une moyenne à partir d'une liste de réels
// la liste est parcourue pour identifier les différentes valeurs réelles
// puis calcul de la moyenne pondérée
void compute_stats(const Doubles& sequence)
{
    unsigned int n = sequence.size();
    DoubleTable D = get_unique(sequence);
    DoubleTable::iterator it = D.begin();
    double m = 0;

    while (it != D.end()) {
        m += it->first * (it->second / (double)(n));
        ++it;
    }

    std::cout << m << std::endl;
}
Ejemplo n.º 3
0
void Progression::Read_Weights (void)
{
	int group, num_periods;
	double weight;
	String record;
	Strings parts;
	Str_Itr str_itr;

	Doubles weights;
	Dbls_Map_Itr grp_itr;
	Dbls_Map_Stat map_stat;
	Dbl_Itr wt_itr;

	Show_Message (String ("Reading %s -- Record") % weight_file.File_Type ());
	Set_Progress ();

	num_periods = progress_time.Num_Periods ();

	while (weight_file.Read ()) {
		Show_Progress ();

		record = weight_file.Record_String ();
		record.Parse (parts);

		if ((int) parts.size () < 2) continue;

		str_itr = parts.begin ();
		group = str_itr->Integer ();

		weights.clear ();
		weight = 1.0;

		for (++str_itr; str_itr != parts.end (); str_itr++) {
			weight = str_itr->Double ();

			if (weight < 0.01 || weight > 1000.0) {
				Error (String ("Group %d Period Weight %.2lf is Out of Range (0.01..1000.0)") % group % weight);
			}
			weights.push_back (weight);
		}

		//---- check the data ----

		while ((int) weights.size () < num_periods) {
			weights.push_back (weight);
		}

		map_stat = weight_data.insert (Dbls_Map_Data (group, weights));

		if (!map_stat.second) {
			Warning ("Duplicate Weight Group = ") << group;
		}
	}
	End_Progress ();
	weight_file.Close ();

	Print (2, "Number of Group Period Weight Records = ") << Progress_Count ();

	if (Report_Flag (WEIGHT_REPORT)) {

		//---- print the report ----

		Header_Number (WEIGHT_REPORT);

		if (!Break_Check (weight_data.size () + 6)) {
			Print (1);
			Weight_Header ();
		}

		for (grp_itr = weight_data.begin (); grp_itr != weight_data.end (); grp_itr++) {
			Print (1, String ("%5d") % grp_itr->first);

			for (wt_itr = grp_itr->second.begin (); wt_itr != grp_itr->second.end (); wt_itr++) {
				Print (0, String ("  %8.2lf") % *wt_itr);
			}
		}
		Header_Number (0);
	}
}