Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • graphics
  • vector
beziercurve.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5
6This program is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public License
8as published by the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15*/
16#ifndef BEZIERCURVE_H
17#define BEZIERCURVE_H
18
19#include <QPainter>
20
21class Object;
22class Status;
23class QXmlStreamWriter;
24class QDomElement;
25
26struct Intersection
27{
28 QPointF point;
29 qreal t1 = 0.0;
30 qreal t2 = 0.0;
31};
32
33class BezierCurve
34{
35public:
36 explicit BezierCurve();
37 explicit BezierCurve(const QList<QPointF>& pointList, bool smooth=true);
38 explicit BezierCurve(const QList<QPointF>& pointList, const QList<qreal>& pressureList, double tol, bool smooth=true);
39
40 Status createDomElement(QXmlStreamWriter &xmlStream);
41 void loadDomElement(const QDomElement& element);
42
43 qreal getWidth() const { return width; }
44 qreal getFeather() const { return feather; }
45 bool getVariableWidth() const { return variableWidth; }
46 int getColorNumber() const { return colorNumber; }
47 void decreaseColorNumber() { colorNumber--; }
48 int getVertexSize() const { return vertex.size(); }
49 QPointF getOrigin() const { return origin; }
50 QPointF getVertex(int i) const { if (i==-1) { return origin; } else { return vertex.at(i);} }
51 QPointF getC1(int i) const { return c1.at(i); }
52 QPointF getC2(int i) const { return c2.at(i); }
53 qreal getPressure(int i) const { return pressure.at(i); }
54 bool isSelected(int vertex) const { return selected.at(vertex+1); }
55 bool isSelected() const { bool result=true; for(int i=0; i<selected.size(); i++) result = result && selected[i]; return result; }
56 bool isPartlySelected() const { bool result=false; for(int i=0; i<selected.size(); i++) result = result || selected[i]; return result; }
57 bool isInvisible() const { return invisible; }
58 bool intersects(QPointF point, qreal distance);
59 bool intersects(QRectF rectangle);
60 bool isFilled() const { return mFilled; }
61
62 void setOrigin(const QPointF& point);
63 void setOrigin(const QPointF& point, const qreal& pressureValue, const bool& trueOrFalse);
64 void setC1(int i, const QPointF& point);
65 void setC2(int i, const QPointF& point);
66 void setVertex(int i, const QPointF& point);
67 void setLastVertex(const QPointF& point);
68 void setWidth(qreal desiredWidth);
69 void setFeather(qreal desiredFeather);
70 void setVariableWidth(bool YesOrNo);
71 void setInvisibility(bool YesOrNo);
72 void setColorNumber(int colorNumber) { this->colorNumber = colorNumber; }
73 void setSelected(bool YesOrNo) { for(int i=0; i<selected.size(); i++) { selected[i] = YesOrNo; } }
74 void setSelected(int i, bool YesOrNo);
75 void setFilled(bool yesOrNo);
76
77 BezierCurve transformed(QTransform transformation) const;
78 void transform(QTransform transformation);
79
80 void appendCubic(const QPointF& c1Point, const QPointF& c2Point, const QPointF& vertexPoint, qreal pressureValue);
81 void addPoint(int position, const QPointF point);
82 void addPoint(int position, const qreal fraction);
83 QPointF getPointOnCubic(int i, qreal t);
84 void removeVertex(int i);
85 QPainterPath getStraightPath();
86 QPainterPath getSimplePath();
87 QPainterPath getStrokedPath();
88 QPainterPath getStrokedPath(qreal width);
89 QPainterPath getStrokedPath(qreal width, bool pressure);
90 QRectF getBoundingRect();
91
92 void drawPath(QPainter& painter, const Object& object, QTransform transformation, bool simplified, bool showThinLines );
93 void createCurve(const QList<QPointF>& pointList, const QList<qreal>& pressureList , bool smooth);
94 void smoothCurve();
95
96 static void simplify(double tol, const QList<QPointF>& inputList, int j, int k, QList<bool>& markList);
97
98 // general useful functions -> to be placed elsewhere?
99 static qreal eLength(const QPointF point); // returns the Euclidean length of a point (seen as a vector)
100 static qreal mLength(const QPointF point); // returns the Manhattan length of a point (seen as a vector)
101 static void normalise(QPointF& point); // normalises a point (seen as a vector);
102 static qreal findDistance(BezierCurve curve, int i, QPointF P, QPointF& nearestPoint, qreal& t); //finds the distance between a cubic section and a point
103 static bool findIntersection(BezierCurve curve1, int i1, BezierCurve curve2, int i2, QList<Intersection>& intersections); //finds the intersection between two cubic sections
104
105private:
106 QPointF origin;
107 QList<QPointF> c1;
108 QList<QPointF> c2;
109 QList<QPointF> vertex;
110 QList<float> pressure; // this list has one more element than the other list (the first element is for the origin)
111 int colorNumber = 0;
112 float width = 0.f;
113 float feather = 0.f;
114 bool variableWidth = 0.f;
115 bool invisible = false;
116 bool mFilled = false;
117 QList<bool> selected; // this list has one more element than the other list (the first element is for the origin)
118};
119
120#endif
BezierCurve
Definition: beziercurve.h:34
BezierCurve::setFilled
void setFilled(bool yesOrNo)
BezierCurve::setFilled.
Definition: beziercurve.cpp:277
Object
Definition: object.h:42
Status
Definition: pencilerror.h:40
QDomElement
QList
QList::at
const T & at(int i) const const
QList::size
int size() const const
QPainter
QPainterPath
QPointF
QRectF
QTransform
QXmlStreamWriter
Intersection
Definition: beziercurve.h:27
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39