1 /******************************************************************* 2 3 Part of the Fritzing project - http://fritzing.org 4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de 5 6 Fritzing is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Fritzing is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>. 18 19 ******************************************************************** 20 21 $Revision: 6904 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-02-26 16:26:03 +0100 (Di, 26. Feb 2013) $ 24 25 ********************************************************************/ 26 27 #ifndef BEZIER_H 28 #define BEZIER_H 29 30 #include <QPointF> 31 #include <QDomElement> 32 #include <QXmlStreamWriter> 33 34 // cubic bezier auxiliary implementation 35 36 class Bezier 37 { 38 public: 39 Bezier(QPointF cp1, QPointF cp2); 40 Bezier(); 41 42 QPointF cp0() const; 43 QPointF cp1() const; 44 QPointF endpoint0() const; 45 QPointF endpoint1() const; 46 void set_cp0(QPointF); 47 void set_cp1(QPointF); 48 void set_endpoints(QPointF, QPointF); 49 bool isEmpty() const; 50 void clear(); 51 void write(QXmlStreamWriter &); 52 bool operator==(const Bezier &) const; 53 bool operator!=(const Bezier &) const; 54 void recalc(QPointF p); 55 void initToEnds(QPointF cp0, QPointF cp1); 56 double xFromT(double t) const; 57 double xFromTPrime(double t) const; 58 double yFromT(double t) const; 59 void split(double t, Bezier & left, Bezier & right) const; 60 void initControlIndex(QPointF fromPoint, double width); 61 double computeCubicCurveLength(double z, int n) const; 62 void copy(const Bezier *); 63 double findSplit(QPointF p, double minDistance) const; 64 void translateToZero(); 65 void translate(QPointF); 66 Bezier join(const Bezier * other) const; 67 bool drag0(); 68 69 protected: 70 double cubicF(double t) const; 71 72 73 public: 74 static Bezier fromElement(QDomElement & element); 75 76 protected: 77 QPointF m_endpoint0; 78 QPointF m_endpoint1; 79 QPointF m_cp0; 80 QPointF m_cp1; 81 bool m_isEmpty; 82 bool m_drag_cp0; 83 }; 84 85 #endif 86