Subversion Repositories Scribus

Rev

Rev 16856 | Rev 19547 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 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
*/
3 paul 7
/***************************************************************************
8
                          fpoint.h  -  description
9
                             -------------------
10
    begin                : Mit Jul 24 2002
11
    copyright            : (C) 2002 by Franz Schmid
12
    email                : Franz.Schmid@altmuehlnet.de
13
 ***************************************************************************/
14
 
15
/***************************************************************************
16
 *                                                                         *
17
 *   This program is free software; you can redistribute it and/or modify  *
18
 *   it under the terms of the GNU General Public License as published by  *
19
 *   the Free Software Foundation; either version 2 of the License, or     *
20
 *   (at your option) any later version.                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23
 
24
#ifndef FPOINT_H
25
#define FPOINT_H
26
 
13951 fschmid 27
#include <QTransform>
10223 cbradney 28
#include <QPoint>
16856 craig 29
#include <QPointF>
2969 craig 30
#include "scribusapi.h"
17966 jghali 31
 
3 paul 32
/**
17966 jghali 33
  * @author Franz Schmid
34
  * @brief A point with floating point precision
35
  *
36
  * One of the advantage of FPoint vs QPointF is that FPoint has consistent precision across platforms :
37
  * the coordinates are systematically stored as double. QPointF uses the qreal typedef which is sometime double,
38
  * sometime float.
39
  *
40
  * FPoint has also some coordinate transformation functionalities not provided by QPointF.
3 paul 41
  */
42
 
2969 craig 43
class SCRIBUS_API FPoint
3 paul 44
{
45
public:
7968 avox 46
        FPoint() : xp(0), yp(0) {};
1955 fschmid 47
        FPoint(double x, double y) : xp(x), yp(y) {};
48
        FPoint(const QPoint & p) : xp(p.x()), yp(p.y()) {};
49
        FPoint(const FPoint & p) : xp(p.xp), yp(p.yp) {};
3235 cbradney 50
        //Creates a transformed point, replaces ScribusView::transformPoint()
51
        FPoint(const double x, const double y, const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert=false);
1884 fschmid 52
//  ~FPoint() {};
3236 avox 53
        FPoint &  operator=(const FPoint & rhs);
54
        double x() const;
55
        double y() const;
56
        void setX(double x);
57
        void setY(double y);
58
        void setXY(double x, double y);
1955 fschmid 59
        bool operator==(const FPoint &rhs) const;
60
        bool operator!=(const FPoint &rhs) const;
3236 avox 61
        FPoint &operator+=( const FPoint &p );
62
        FPoint &operator-=( const FPoint &p );
1525 cbradney 63
        friend inline const FPoint operator+( const FPoint &, const FPoint & );
64
        friend inline const FPoint operator-( const FPoint &, const FPoint & );
65
        friend inline const FPoint operator*( const FPoint &, const double & );
66
        friend inline const FPoint operator*( const double &, const FPoint & );
10509 cbradney 67
        friend inline double  operator*( const FPoint &a, const FPoint &b );
3235 cbradney 68
        //Transform an existing point
69
        void transform(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert);
70
        //Transform an existing point, return a new one
13951 fschmid 71
        FPoint transformPoint(const QTransform& m, const bool invert) const;
10978 avox 72
        FPoint transformPoint(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert) const;
16856 craig 73
        /// Returns a copy of the point as a QPointF.
74
        QPointF toQPointF() const { return QPointF(xp, yp); }
1884 fschmid 75
        friend class FPointArray;
168 Franz 76
 
3 paul 77
private:
80 Franz 78
        double xp;
79
        double yp;
3 paul 80
};
81
 
1525 cbradney 82
 
3236 avox 83
inline const FPoint operator+( const FPoint &p1, const FPoint &p2 ) {
84
        return FPoint(p1.xp+p2.xp, p1.yp+p2.yp);
85
}
1525 cbradney 86
 
3236 avox 87
inline const FPoint operator-( const FPoint &p1, const FPoint &p2 ) {
88
        return FPoint(p1.xp-p2.xp, p1.yp-p2.yp);
89
}
1525 cbradney 90
 
3236 avox 91
inline const FPoint operator*( const FPoint &p, const double &c ) {
92
        return FPoint(p.xp*c, p.yp*c);
93
}
1525 cbradney 94
 
3236 avox 95
inline const FPoint operator*( const double &c, const FPoint &p ) {
96
        return FPoint(p.xp*c, p.yp*c);
97
}
1525 cbradney 98
 
10509 cbradney 99
inline double operator*( const FPoint &a, const FPoint &b ) {
3236 avox 100
        return a.xp * b.xp + a.yp * b.yp;
101
}
102
 
103
inline FPoint &  FPoint::operator=(const FPoint & rhs)  {
104
        xp = rhs.xp;
105
        yp = rhs.yp;
106
        return *this;
107
}
108
 
109
inline double FPoint::x() const {
110
        return xp;
111
}
112
 
113
inline double FPoint::y() const {
114
        return yp;
115
}
116
 
117
inline void FPoint::setX(double x) {
118
        xp = x;
119
}
120
 
121
inline void FPoint::setY(double y) {
122
        yp = y;
123
}
124
 
125
inline void FPoint::setXY(double x, double y) {
126
        xp = x;
127
        yp = y;
128
}
129
 
130
inline FPoint & FPoint::operator+=( const FPoint &p ) {
131
        xp += p.xp;
132
        yp += p.yp;
133
        return *this;
134
}
135
 
136
inline FPoint & FPoint::operator-=( const FPoint &p ) {
137
        xp -= p.xp;
138
        yp -= p.yp;
139
        return *this;
140
}
141
 
3 paul 142
#endif