Scribus
Open source desktop publishing at your fingertips
util_math.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef _UTIL_MATH_H
8 #define _UTIL_MATH_H
9 
10 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
11 #define _USE_MATH_DEFINES
12 #endif
13 #include <cmath>
14 #include <vector>
15 
16 #include <QByteArray>
17 #include <QPolygon>
18 #include <QList>
19 #include <QPainterPath>
20 #include <QLineF>
21 
22 #include "scribusapi.h"
23 
24 class FPoint;
25 class FPointArray;
26 class QRegion;
27 
31 bool SCRIBUS_API compareDouble(double a, double b);
32 uint SCRIBUS_API getDouble(const QByteArray in, bool raw);
33 FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
34 FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
35 FPoint SCRIBUS_API projectPointOnLine(FPoint p, QPointF lineStart, QPointF lineEnd);
36 bool SCRIBUS_API regionContainsRect(const QRegion& shape, QRect rect);
37 QPolygon SCRIBUS_API FlattenPath(const FPointArray& ina, QList<uint> &Segs);
38 QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
39 QPainterPath SCRIBUS_API RegularPolygonPath(double w, double h, uint c, bool star, double factor, double rota, double factor2 = 0.0, double innerRot = 0.0, double factor3 = 0.0);
40 QPainterPath SCRIBUS_API SpiralPath(double spiralWidth, double spiralHeight, double spiralStartAngle, double spiralEndAngle, double spiralFactor);
41 inline double SCRIBUS_API xy2Deg(double x, double y);
42 inline double SCRIBUS_API sind(double);
43 inline double SCRIBUS_API cosd(double);
44 inline double SCRIBUS_API square(double);
45 inline double SCRIBUS_API distance(double, double);
52 double SCRIBUS_API constrainAngle(double angle, double constrain);
59 double SCRIBUS_API getRotationFromMatrix(QTransform& matrix, double def);
64 double SCRIBUS_API getRotationDFromMatrix(QTransform& matrix);
65 void SCRIBUS_API getScaleFromMatrix(QTransform &matrix, double &scX, double &scY);
66 void SCRIBUS_API getTransformValuesFromMatrix(QTransform &matrix, double &scX, double &scY, double &rot, double &dx, double &dy);
67 
68 
69 // IMPLEMENTATION
70 
71 inline double square(double x)
72 {
73  return x*x;
74 }
75 
76 inline double distance(double x, double y)
77 {
78  return sqrt(x*x + y*y);
79 }
80 
81 inline double xy2Deg(double x, double y)
82 {
83  return atan2(y,x) * (180.0/M_PI);
84 }
85 
86 inline double sind(double alpha)
87 {
88  return sin(alpha / (180.0/M_PI));
89 }
90 
91 inline double cosd(double alpha)
92 {
93  return cos(alpha / (180.0/M_PI));
94 }
95 
96 template <typename T>
97 inline bool isequiv(const T& v1, const T& v2) { return v1 == v2; }
98 
99 template <>
100 inline bool isequiv<double>(const double& v1, const double& v2) { return compareDouble(v1, v2); }
101 
102 #endif
A point with floating point precision.
Definition: fpoint.h:43
Coord distance(Point const &a, Point const &b)
Definition: point.h:205
Definition: fpointarray.h:42