-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfloatpoint.cpp
More file actions
67 lines (51 loc) · 1.41 KB
/
Copy pathfloatpoint.cpp
File metadata and controls
67 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "floatpoint.h"
#include "transformationmatrix.h"
#include "common.h"
/*#include "config.h"
#include "FloatPoint.h"
#include "TransformationMatrix.h"
#include "FloatConversion.h"
#include "IntPoint.h"*/
#include <cmath>
FloatPoint::FloatPoint(const IntPoint& p) : m_x(p.x()), m_y(p.y())
{
}
void FloatPoint::normalize()
{
float tempLength = length();
if (tempLength) {
m_x /= tempLength;
m_y /= tempLength;
}
}
float FloatPoint::length() const
{
return sqrtf(lengthSquared());
}
FloatPoint FloatPoint::matrixTransform(const AffineTransform& transform) const
{
double newX, newY;
transform.map(static_cast<double>(m_x), static_cast<double>(m_y), newX, newY);
return narrowPrecision(newX, newY);
}
FloatPoint FloatPoint::matrixTransform(const TransformationMatrix& transform) const
{
double newX, newY;
transform.map(static_cast<double>(m_x), static_cast<double>(m_y), newX, newY);
return narrowPrecision(newX, newY);
}
FloatPoint FloatPoint::narrowPrecision(double x, double y)
{
return FloatPoint(narrowPrecisionToFloat(x), narrowPrecisionToFloat(y));
}
//////////////////
// https://github.com/rkudiyarov/ClutterWebkit/blob/05d919e0598691bcd34f57d27f44872919e39e92/WebCore/platform/graphics/qt/FloatPointQt.cpp
FloatPoint::FloatPoint(const QPointF& p)
: m_x(p.x())
, m_y(p.y())
{
}
FloatPoint::operator QPointF() const
{
return QPointF(m_x, m_y);
}