2 #ifndef FRECHET_VIEW_NUM_ERROR_H 3 #define FRECHET_VIEW_NUM_ERROR_H 10 #include <boost/config.hpp> 11 #include <boost/math/special_functions/next.hpp> 13 #ifdef QUAD_ARITHMETIC 24 # if defined(BOOST_INTEL) || defined(__GNUC__) 25 # include <boost/multiprecision/float128.hpp> 26 typedef boost::multiprecision::float128 float128;
29 # pragma message ("no float128 support. falling back to double precision.") 30 typedef long double float128;
52 static const constexpr
double double_eps = std::numeric_limits<double>::epsilon();
60 template<
typename Number>
61 inline Number
sq(
const Number& x) {
return x*x; }
69 template<
typename Float>
70 inline Float
sqrt(
const Float& x);
82 inline long double sqrt(
const long double& x) { return ::sqrtl(x); }
90 template<
typename Number>
91 inline Number
abs(
const Number& x) {
return (x<0) ? -x : x; }
93 #if defined(BOOST_MP_USE_FLOAT128) || defined(BOOST_MP_USE_QUAD) 98 inline float128
sqrt(
const float128& x) {
return sqrt(x); }
100 inline const float128&
min(
const float128& a,
const float128& b)
113 return boost::math::float_advance(x,ulps);
125 template<
typename Float>
127 const Float& px,
const Float& py,
128 const Float& qx,
const Float& qy)
130 return sq<Float>(px-qx) + sq<Float>(py-qy);
142 template<
typename Float>
144 const Float& px,
const Float& py,
145 const Float& qx,
const Float& qy)
147 return sqrt<Float>(euclidean_distance_sq<Float>(px,py,qx,qy));
157 template<
typename Float>
160 return euclidean_distance<Float>(p.x(),p.y(),q.x(),q.y());
170 template<
typename Float>
173 return euclidean_distance_sq<Float>(p.x(),p.y(),q.x(),q.y());
188 template<
typename Float>
190 const Float& ax,
const Float& ay,
191 const Float& bx,
const Float& by,
192 const Float& px,
const Float& py)
194 Float n = (by-ay)*px - by*ax - (bx-ax)*py + bx*ay;
207 template<
typename Float>
210 return euclidean_segment_distance<Float>(
211 s.p1().x(), s.p1().y(),
212 s.p2().x(), s.p2().y(),
222 inline double min(
double a,
double b)
224 return (std::isnan(a) || (b < a)) ? b:a;
233 inline double max(
double a,
double b)
235 return (std::isnan(a) || (b > a)) ? b:a;
245 if (i==x && i >
min) --i;
256 if (a > b)
return +1;
257 if (a < b)
return -1;
267 double len =
sqrt(
sq(p.x()) +
sq(p.y()) );
268 return Point(p.x()/len, p.y()/len);
280 double det = (p1.x()-p2.x())*(p3.y()-p4.y()) - (p1.y()-p2.y())*(p3.x()-p4.x());
281 double Px = (p1.x()*p2.y()-p1.y()*p2.x())*(p3.x()-p4.x()) - (p1.x()-p2.x())*(p3.x()*p4.y()-p3.y()*p4.x());
282 double Py = (p1.x()*p2.y()-p1.y()*p2.x())*(p3.y()-p4.y()) - (p1.y()-p2.y())*(p3.x()*p4.y()-p3.y()*p4.x());
284 return Point(Px/det,Py/det);
297 Q_ASSERT(w>=0 && w<=1.0);
298 return p*(1-w) + q*w;
308 return euclidean_distance<double> (c[i],c[i+1]);
321 for(
int i=0; i < P.size(); ++i)
323 const Point& p = P[i];
324 for(
int j=0; j < Q.size(); ++j)
326 double dsq = euclidean_distance_sq<double> (p,Q[j]);
337 #endif //FRECHET_VIEW_NUM_ERROR_H double round_up(double x, int ulps=1)
rounding function with 'units in the last place' Roughly speaking, a ulp is the smallest representabl...
Point normalized(Point p)
normalize a vector to unit length
global definitions for all algorithms.
long double sqrt(const long double &x)
sqrt() specialisation for "long double"
int compare(double a, double b)
comparator function
long double accurate_float
int lower_floor(double x, int min=0)
floor function with lower limit
QPointF Point
a point in the plane; with double floating point precision. This type is heavily used throughout all ...
Point intersection(Point p1, Point p2, Point p3, Point p4)
compute the intersection of two lines
Point between(Point p, Point q, double w)
compute a point on a line segment
QPolygonF Curve
a polygonal curve in the plane; with double floating point precision. This type is heavily used throu...
double min(double a, double b)
minimum function with checks for NAN
double segment_length(const Curve &c, int i)
compute the length of a polygon segment
Float euclidean_distance(const Point &p, const Point &q)
euclidean distance function template for arbitrary floating point types
Float euclidean_distance_sq(const Point &p, const Point &q)
euclidean distance function template for arbitrary floating point types
Number sq(const Number &x)
square function template for arbitrary number types
double max_euclidean_distance(const Curve &P, const Curve &Q)
compute the maximum distance between two polygons This value serves as an upper bound for the Frechet...
Number abs(const Number &x)
abs() function template for arbitrary numerical types
static const constexpr double double_eps
smallest double value
Float euclidean_segment_distance(const QLineF &s, const Point &p)
Euclidean Distance between a point and a segment; function template for arbitrary floating point type...
double max(double a, double b)
maximum function with checks for NAN