11#ifndef COMMON_PERSISTENCE_REPRESENTATIONS_H_
12#define COMMON_PERSISTENCE_REPRESENTATIONS_H_
17#include <boost/math/constants/constants.hpp>
22namespace Persistence_representations {
25static constexpr double pi = boost::math::constants::pi<double>();
31using Persistence_diagram = std::vector<std::pair<double, double> >;
34double epsi = 0.000005;
41inline bool almost_equal(
double a,
double b) {
42 if (std::fabs(a - b) < epsi)
return true;
50double minus_length(std::pair<double, double> a) {
return a.first - a.second; }
51double birth_plus_deaths(std::pair<double, double> a) {
return a.first + a.second; }
57std::pair<double, double> compute_parameters_of_a_line(std::pair<double, double> p1, std::pair<double, double> p2) {
58 double a = (p2.second - p1.second) / (p2.first - p1.first);
59 double b = p1.second - a * p1.first;
60 return std::make_pair(a, b);
67double find_zero_of_a_line_segment_between_those_two_points(std::pair<double, double> p1,
68 std::pair<double, double> p2) {
69 if (p1.first == p2.first)
return p1.first;
70 if (p1.second * p2.second > 0) {
71 std::ostringstream errMessage;
72 errMessage <<
"In function find_zero_of_a_line_segment_between_those_two_points the arguments are: (" << p1.first
73 <<
"," << p1.second <<
") and (" << p2.first <<
"," << p2.second
74 <<
"). There is no zero in line between those two points. Program terminated.";
75 std::string errMessageStr = errMessage.str();
76 const char* err = errMessageStr.c_str();
81 double a = (p2.second - p1.second) / (p2.first - p1.first);
82 double b = p1.second - a * p1.first;
91bool compare_points_sorting(std::pair<double, double> f, std::pair<double, double> s) {
92 if (f.first < s.first) {
95 if (f.first > s.first) {
98 if (f.second > s.second) {
112double function_value(std::pair<double, double> p1, std::pair<double, double> p2,
double x) {
115 double a = (p2.second - p1.second) / (p2.first - p1.first);
116 double b = p1.second - a * p1.first;