LMMS
Loading...
Searching...
No Matches
juce_RelativePointPath.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
34
38{
39 for (int i = 0; i < other.elements.size(); ++i)
40 elements.add (other.elements.getUnchecked(i)->clone());
41}
42
44 : usesNonZeroWinding (path.isUsingNonZeroWinding()),
46{
47 for (Path::Iterator i (path); i.next();)
48 {
49 switch (i.elementType)
50 {
51 case Path::Iterator::startNewSubPath: elements.add (new StartSubPath (RelativePoint (i.x1, i.y1))); break;
52 case Path::Iterator::lineTo: elements.add (new LineTo (RelativePoint (i.x1, i.y1))); break;
53 case Path::Iterator::quadraticTo: elements.add (new QuadraticTo (RelativePoint (i.x1, i.y1), RelativePoint (i.x2, i.y2))); break;
54 case Path::Iterator::cubicTo: elements.add (new CubicTo (RelativePoint (i.x1, i.y1), RelativePoint (i.x2, i.y2), RelativePoint (i.x3, i.y3))); break;
55 case Path::Iterator::closePath: elements.add (new CloseSubPath()); break;
56 default: jassertfalse; break;
57 }
58 }
59}
60
64
65bool RelativePointPath::operator== (const RelativePointPath& other) const noexcept
66{
67 if (elements.size() != other.elements.size()
68 || usesNonZeroWinding != other.usesNonZeroWinding
69 || containsDynamicPoints != other.containsDynamicPoints)
70 return false;
71
72 for (int i = 0; i < elements.size(); ++i)
73 {
74 ElementBase* const e1 = elements.getUnchecked(i);
75 ElementBase* const e2 = other.elements.getUnchecked(i);
76
77 if (e1->type != e2->type)
78 return false;
79
80 int numPoints1, numPoints2;
81 const RelativePoint* const points1 = e1->getControlPoints (numPoints1);
82 const RelativePoint* const points2 = e2->getControlPoints (numPoints2);
83
84 jassert (numPoints1 == numPoints2);
85
86 for (int j = numPoints1; --j >= 0;)
87 if (points1[j] != points2[j])
88 return false;
89 }
90
91 return true;
92}
93
94bool RelativePointPath::operator!= (const RelativePointPath& other) const noexcept
95{
96 return ! operator== (other);
97}
98
100{
101 elements.swapWith (other.elements);
102 std::swap (usesNonZeroWinding, other.usesNonZeroWinding);
103 std::swap (containsDynamicPoints, other.containsDynamicPoints);
104}
105
107{
108 for (int i = 0; i < elements.size(); ++i)
109 elements.getUnchecked(i)->addToPath (path, scope);
110}
111
116
118{
119 if (newElement != nullptr)
120 {
121 elements.add (newElement);
123 }
124}
125
126//==============================================================================
130
132{
133 int numPoints;
134 const RelativePoint* const points = getControlPoints (numPoints);
135
136 for (int i = numPoints; --i >= 0;)
137 if (points[i].isDynamic())
138 return true;
139
140 return false;
141}
142
143//==============================================================================
148
153
155{
156 numPoints = 1;
157 return &startPos;
158}
159
164
165//==============================================================================
170
175
177{
178 numPoints = 0;
179 return nullptr;
180}
181
186
187//==============================================================================
189 : ElementBase (lineToElement), endPoint (endPoint_)
190{
191}
192
194{
195 path.lineTo (endPoint.resolve (scope));
196}
197
199{
200 numPoints = 1;
201 return &endPoint;
202}
203
208
209//==============================================================================
212{
213 controlPoints[0] = controlPoint;
214 controlPoints[1] = endPoint;
215}
216
218{
219 path.quadraticTo (controlPoints[0].resolve (scope),
220 controlPoints[1].resolve (scope));
221}
222
224{
225 numPoints = 2;
226 return controlPoints;
227}
228
233
234
235//==============================================================================
236RelativePointPath::CubicTo::CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint)
238{
239 controlPoints[0] = controlPoint1;
240 controlPoints[1] = controlPoint2;
241 controlPoints[2] = endPoint;
242}
243
245{
246 path.cubicTo (controlPoints[0].resolve (scope),
247 controlPoints[1].resolve (scope),
248 controlPoints[2].resolve (scope));
249}
250
252{
253 numPoints = 3;
254 return controlPoints;
255}
256
261
262} // namespace juce
static Audio_Scope * scope
Definition player.cpp:26
Definition juce_Expression.h:109
Definition juce_Path.h:725
@ quadraticTo
Definition juce_Path.h:745
@ closePath
Definition juce_Path.h:747
@ lineTo
Definition juce_Path.h:744
@ cubicTo
Definition juce_Path.h:746
@ startNewSubPath
Definition juce_Path.h:743
Definition juce_Path.h:65
void startNewSubPath(float startX, float startY)
Definition juce_Path.cpp:216
void quadraticTo(float controlPointX, float controlPointY, float endPointX, float endPointY)
Definition juce_Path.cpp:249
void cubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
Definition juce_Path.cpp:268
void closeSubPath()
Definition juce_Path.cpp:292
void lineTo(float endX, float endY)
Definition juce_Path.cpp:233
Definition juce_RelativePoint.h:38
Definition juce_RelativePointPath.h:114
RelativePoint * getControlPoints(int &numPoints) override
Definition juce_RelativePointPath.cpp:176
ElementBase * clone() const override
Definition juce_RelativePointPath.cpp:182
CloseSubPath()
Definition juce_RelativePointPath.cpp:166
void addToPath(Path &path, Expression::Scope *) const override
Definition juce_RelativePointPath.cpp:171
Definition juce_RelativePointPath.h:161
ElementBase * clone() const override
Definition juce_RelativePointPath.cpp:257
void addToPath(Path &path, Expression::Scope *) const override
Definition juce_RelativePointPath.cpp:244
RelativePoint * getControlPoints(int &numPoints) override
Definition juce_RelativePointPath.cpp:251
RelativePoint controlPoints[3]
Definition juce_RelativePointPath.h:169
CubicTo(const RelativePoint &controlPoint1, const RelativePoint &controlPoint2, const RelativePoint &endPoint)
Definition juce_RelativePointPath.cpp:236
Definition juce_RelativePointPath.h:80
ElementBase(ElementType type)
Definition juce_RelativePointPath.cpp:127
bool isDynamic()
Definition juce_RelativePointPath.cpp:131
virtual RelativePoint * getControlPoints(int &numPoints)=0
const ElementType type
Definition juce_RelativePointPath.h:89
Definition juce_RelativePointPath.h:128
void addToPath(Path &path, Expression::Scope *) const override
Definition juce_RelativePointPath.cpp:193
RelativePoint endPoint
Definition juce_RelativePointPath.h:135
ElementBase * clone() const override
Definition juce_RelativePointPath.cpp:204
RelativePoint * getControlPoints(int &numPoints) override
Definition juce_RelativePointPath.cpp:198
LineTo(const RelativePoint &endPoint)
Definition juce_RelativePointPath.cpp:188
Definition juce_RelativePointPath.h:144
RelativePoint * getControlPoints(int &numPoints) override
Definition juce_RelativePointPath.cpp:223
QuadraticTo(const RelativePoint &controlPoint, const RelativePoint &endPoint)
Definition juce_RelativePointPath.cpp:210
ElementBase * clone() const override
Definition juce_RelativePointPath.cpp:229
void addToPath(Path &path, Expression::Scope *) const override
Definition juce_RelativePointPath.cpp:217
RelativePoint controlPoints[2]
Definition juce_RelativePointPath.h:152
Definition juce_RelativePointPath.h:98
RelativePoint * getControlPoints(int &numPoints) override
Definition juce_RelativePointPath.cpp:154
void addToPath(Path &path, Expression::Scope *) const override
Definition juce_RelativePointPath.cpp:149
StartSubPath(const RelativePoint &pos)
Definition juce_RelativePointPath.cpp:144
ElementBase * clone() const override
Definition juce_RelativePointPath.cpp:160
RelativePoint startPos
Definition juce_RelativePointPath.h:105
bool usesNonZeroWinding
Definition juce_RelativePointPath.h:180
ElementType
Definition juce_RelativePointPath.h:67
@ cubicToElement
Definition juce_RelativePointPath.h:73
@ startSubPathElement
Definition juce_RelativePointPath.h:69
@ quadraticToElement
Definition juce_RelativePointPath.h:72
@ lineToElement
Definition juce_RelativePointPath.h:71
@ closeSubPathElement
Definition juce_RelativePointPath.h:70
RelativePointPath()
Definition juce_RelativePointPath.cpp:29
void createPath(Path &path, Expression::Scope *scope) const
Definition juce_RelativePointPath.cpp:106
void swapWith(RelativePointPath &) noexcept
Definition juce_RelativePointPath.cpp:99
~RelativePointPath()
Definition juce_RelativePointPath.cpp:61
bool containsAnyDynamicPoints() const
Definition juce_RelativePointPath.cpp:112
void addElement(ElementBase *newElement)
Definition juce_RelativePointPath.cpp:117
bool containsDynamicPoints
Definition juce_RelativePointPath.h:185
OwnedArray< ElementBase > elements
Definition juce_RelativePointPath.h:179
register unsigned j
Definition inflate.c:1576
register unsigned i
Definition inflate.c:1575
#define jassert(expression)
#define jassertfalse
Definition carla_juce.cpp:31
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
#define LineTo