JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
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
29RelativePointPath::RelativePointPath()
30 : usesNonZeroWinding (true),
31 containsDynamicPoints (false)
32{
33}
34
35RelativePointPath::RelativePointPath (const RelativePointPath& other)
36 : usesNonZeroWinding (true),
37 containsDynamicPoints (false)
38{
39 for (int i = 0; i < other.elements.size(); ++i)
40 elements.add (other.elements.getUnchecked (i)->clone());
41}
42
43RelativePointPath::RelativePointPath (const Path& path)
44 : usesNonZeroWinding (path.isUsingNonZeroWinding()),
45 containsDynamicPoints (false)
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
61RelativePointPath::~RelativePointPath()
62{
63}
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
99void RelativePointPath::swapWith (RelativePointPath& other) noexcept
100{
101 elements.swapWith (other.elements);
102 std::swap (usesNonZeroWinding, other.usesNonZeroWinding);
103 std::swap (containsDynamicPoints, other.containsDynamicPoints);
104}
105
106void RelativePointPath::createPath (Path& path, Expression::Scope* scope) const
107{
108 for (int i = 0; i < elements.size(); ++i)
109 elements.getUnchecked (i)->addToPath (path, scope);
110}
111
112bool RelativePointPath::containsAnyDynamicPoints() const
113{
114 return containsDynamicPoints;
115}
116
117void RelativePointPath::addElement (ElementBase* newElement)
118{
119 if (newElement != nullptr)
120 {
121 elements.add (newElement);
122 containsDynamicPoints = containsDynamicPoints || newElement->isDynamic();
123 }
124}
125
126//==============================================================================
127RelativePointPath::ElementBase::ElementBase (const ElementType type_) : type (type_)
128{
129}
130
131bool RelativePointPath::ElementBase::isDynamic()
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//==============================================================================
144RelativePointPath::StartSubPath::StartSubPath (const RelativePoint& pos)
145 : ElementBase (startSubPathElement), startPos (pos)
146{
147}
148
149void RelativePointPath::StartSubPath::addToPath (Path& path, Expression::Scope* scope) const
150{
151 path.startNewSubPath (startPos.resolve (scope));
152}
153
154RelativePoint* RelativePointPath::StartSubPath::getControlPoints (int& numPoints)
155{
156 numPoints = 1;
157 return &startPos;
158}
159
160RelativePointPath::ElementBase* RelativePointPath::StartSubPath::clone() const
161{
162 return new StartSubPath (startPos);
163}
164
165//==============================================================================
166RelativePointPath::CloseSubPath::CloseSubPath()
167 : ElementBase (closeSubPathElement)
168{
169}
170
171void RelativePointPath::CloseSubPath::addToPath (Path& path, Expression::Scope*) const
172{
173 path.closeSubPath();
174}
175
176RelativePoint* RelativePointPath::CloseSubPath::getControlPoints (int& numPoints)
177{
178 numPoints = 0;
179 return nullptr;
180}
181
182RelativePointPath::ElementBase* RelativePointPath::CloseSubPath::clone() const
183{
184 return new CloseSubPath();
185}
186
187//==============================================================================
188RelativePointPath::LineTo::LineTo (const RelativePoint& endPoint_)
189 : ElementBase (lineToElement), endPoint (endPoint_)
190{
191}
192
193void RelativePointPath::LineTo::addToPath (Path& path, Expression::Scope* scope) const
194{
195 path.lineTo (endPoint.resolve (scope));
196}
197
198RelativePoint* RelativePointPath::LineTo::getControlPoints (int& numPoints)
199{
200 numPoints = 1;
201 return &endPoint;
202}
203
204RelativePointPath::ElementBase* RelativePointPath::LineTo::clone() const
205{
206 return new LineTo (endPoint);
207}
208
209//==============================================================================
210RelativePointPath::QuadraticTo::QuadraticTo (const RelativePoint& controlPoint, const RelativePoint& endPoint)
211 : ElementBase (quadraticToElement)
212{
213 controlPoints[0] = controlPoint;
214 controlPoints[1] = endPoint;
215}
216
217void RelativePointPath::QuadraticTo::addToPath (Path& path, Expression::Scope* scope) const
218{
219 path.quadraticTo (controlPoints[0].resolve (scope),
220 controlPoints[1].resolve (scope));
221}
222
223RelativePoint* RelativePointPath::QuadraticTo::getControlPoints (int& numPoints)
224{
225 numPoints = 2;
226 return controlPoints;
227}
228
229RelativePointPath::ElementBase* RelativePointPath::QuadraticTo::clone() const
230{
231 return new QuadraticTo (controlPoints[0], controlPoints[1]);
232}
233
234
235//==============================================================================
236RelativePointPath::CubicTo::CubicTo (const RelativePoint& controlPoint1, const RelativePoint& controlPoint2, const RelativePoint& endPoint)
237 : ElementBase (cubicToElement)
238{
239 controlPoints[0] = controlPoint1;
240 controlPoints[1] = controlPoint2;
241 controlPoints[2] = endPoint;
242}
243
244void RelativePointPath::CubicTo::addToPath (Path& path, Expression::Scope* scope) const
245{
246 path.cubicTo (controlPoints[0].resolve (scope),
247 controlPoints[1].resolve (scope),
248 controlPoints[2].resolve (scope));
249}
250
251RelativePoint* RelativePointPath::CubicTo::getControlPoints (int& numPoints)
252{
253 numPoints = 3;
254 return controlPoints;
255}
256
257RelativePointPath::ElementBase* RelativePointPath::CubicTo::clone() const
258{
259 return new CubicTo (controlPoints[0], controlPoints[1], controlPoints[2]);
260}
261
262} // namespace juce
When evaluating an Expression object, this class is used to resolve symbols and perform functions tha...
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
A path object that consists of RelativePoint coordinates rather than the normal fixed ones.
Point< float > resolve(const Expression::Scope *evaluationContext) const
Calculates the absolute position of this point.
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
T swap(T... args)