Scribus
Open source desktop publishing at your fingertips
fpoint.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 /***************************************************************************
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 
27 #include <QTransform>
28 #include <QPoint>
29 #include <QPointF>
30 #include "scribusapi.h"
31 
43 class SCRIBUS_API FPoint
44 {
45 public:
46  FPoint() : xp(0), yp(0) {};
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) {};
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);
52 // ~FPoint() {};
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);
59  bool operator==(const FPoint &rhs) const;
60  bool operator!=(const FPoint &rhs) const;
61  FPoint &operator+=( const FPoint &p );
62  FPoint &operator-=( const FPoint &p );
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 & );
67  friend inline double operator*( const FPoint &a, const FPoint &b );
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
71  FPoint transformPoint(const QTransform& m, const bool invert) const;
72  FPoint transformPoint(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert) const;
74  QPointF toQPointF() const { return QPointF(xp, yp); }
75  friend class FPointArray;
76  bool isNull() const;
77 
78 private:
79  double xp;
80  double yp;
81 };
82 
83 
84 inline const FPoint operator+( const FPoint &p1, const FPoint &p2 ) {
85  return FPoint(p1.xp+p2.xp, p1.yp+p2.yp);
86 }
87 
88 inline const FPoint operator-( const FPoint &p1, const FPoint &p2 ) {
89  return FPoint(p1.xp-p2.xp, p1.yp-p2.yp);
90 }
91 
92 inline const FPoint operator*( const FPoint &p, const double &c ) {
93  return FPoint(p.xp*c, p.yp*c);
94 }
95 
96 inline const FPoint operator*( const double &c, const FPoint &p ) {
97  return FPoint(p.xp*c, p.yp*c);
98 }
99 
100 inline double operator*( const FPoint &a, const FPoint &b ) {
101  return a.xp * b.xp + a.yp * b.yp;
102 }
103 
104 inline FPoint & FPoint::operator=(const FPoint & rhs) {
105  xp = rhs.xp;
106  yp = rhs.yp;
107  return *this;
108 }
109 
110 inline double FPoint::x() const {
111  return xp;
112 }
113 
114 inline double FPoint::y() const {
115  return yp;
116 }
117 
118 inline void FPoint::setX(double x) {
119  xp = x;
120 }
121 
122 inline void FPoint::setY(double y) {
123  yp = y;
124 }
125 
126 inline void FPoint::setXY(double x, double y) {
127  xp = x;
128  yp = y;
129 }
130 
131 inline FPoint & FPoint::operator+=( const FPoint &p ) {
132  xp += p.xp;
133  yp += p.yp;
134  return *this;
135 }
136 
137 inline FPoint & FPoint::operator-=( const FPoint &p ) {
138  xp -= p.xp;
139  yp -= p.yp;
140  return *this;
141 }
142 
143 #endif
A point with floating point precision.
Definition: fpoint.h:43
QPointF toQPointF() const
Returns a copy of the point as a QPointF.
Definition: fpoint.h:74
Definition: fpointarray.h:42