Back to index

scribus-ng  1.3.4.dfsg+svn20071115
fpoint.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           fpoint.cpp  -  description
00009                              -------------------
00010     begin                : Mit Jul 24 2002
00011     copyright            : (C) 2002 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "fpoint.h"
00025 
00026 #include <qwmatrix.h>
00027 
00028 //Create transformed point
00029 FPoint::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)
00030        : xp(x), yp(y)
00031 {
00032        transform(dx,dy,rot,sx,sy,invert);
00033 }
00034 
00035 bool FPoint::operator==(const FPoint &rhs) const 
00036 {
00037        return QABS(xp-rhs.xp) < 1E-10 && QABS(yp-rhs.yp) < 1E-10;
00038 }
00039 
00040 bool FPoint::operator!=(const FPoint &rhs) const
00041 {
00042        return QABS(xp-rhs.xp) > 1E-10 || QABS(yp-rhs.yp) > 1E-10;
00043 }
00044 
00045 void FPoint::transform(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert)
00046 {
00047        QWMatrix ma;
00048        ma.translate(dx, dy);
00049        ma.scale(sx, sy);
00050        ma.rotate(rot);
00051        if (invert)
00052               ma = ma.invert();
00053        //save new value as old one is used on next line
00054        double newxp = ma.m11() * xp + ma.m21() * yp + ma.dx();
00055        yp = ma.m22() * yp + ma.m12() * xp + ma.dy();
00056        xp = newxp;
00057 }
00058 
00059 FPoint FPoint::transformPoint(const double dx, const double dy, const double rot, const double sx, const double sy, const bool invert)
00060 {
00061        QWMatrix ma;
00062        ma.translate(dx, dy);
00063        ma.scale(sx, sy);
00064        ma.rotate(rot);
00065        if (invert)
00066               ma = ma.invert();
00067        double x = ma.m11() * xp + ma.m21() * yp + ma.dx();
00068        double y = ma.m22() * yp + ma.m12() * xp + ma.dy();
00069        return FPoint(x, y);
00070 }