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_RelativeParallelogram.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
29RelativeParallelogram::RelativeParallelogram()
30{
31}
32
33RelativeParallelogram::RelativeParallelogram (const Rectangle<float>& r)
34 : topLeft (r.getTopLeft()), topRight (r.getTopRight()), bottomLeft (r.getBottomLeft())
35{
36}
37
38RelativeParallelogram::RelativeParallelogram (const RelativePoint& topLeft_, const RelativePoint& topRight_, const RelativePoint& bottomLeft_)
39 : topLeft (topLeft_), topRight (topRight_), bottomLeft (bottomLeft_)
40{
41}
42
43RelativeParallelogram::RelativeParallelogram (const String& topLeft_, const String& topRight_, const String& bottomLeft_)
44 : topLeft (topLeft_), topRight (topRight_), bottomLeft (bottomLeft_)
45{
46}
47
48RelativeParallelogram::~RelativeParallelogram()
49{
50}
51
52void RelativeParallelogram::resolveThreePoints (Point<float>* points, Expression::Scope* const scope) const
53{
54 points[0] = topLeft.resolve (scope);
55 points[1] = topRight.resolve (scope);
56 points[2] = bottomLeft.resolve (scope);
57}
58
59void RelativeParallelogram::resolveFourCorners (Point<float>* points, Expression::Scope* const scope) const
60{
61 resolveThreePoints (points, scope);
62 points[3] = points[1] + (points[2] - points[0]);
63}
64
65const Rectangle<float> RelativeParallelogram::getBounds (Expression::Scope* const scope) const
66{
67 Point<float> points[4];
68 resolveFourCorners (points, scope);
69 return Rectangle<float>::findAreaContainingPoints (points, 4);
70}
71
72void RelativeParallelogram::getPath (Path& path, Expression::Scope* const scope) const
73{
74 Point<float> points[4];
75 resolveFourCorners (points, scope);
76
77 path.startNewSubPath (points[0]);
78 path.lineTo (points[1]);
79 path.lineTo (points[3]);
80 path.lineTo (points[2]);
81 path.closeSubPath();
82}
83
84AffineTransform RelativeParallelogram::resetToPerpendicular (Expression::Scope* const scope)
85{
86 Point<float> corners[3];
87 resolveThreePoints (corners, scope);
88
89 const Line<float> top (corners[0], corners[1]);
90 const Line<float> left (corners[0], corners[2]);
91 const Point<float> newTopRight (corners[0] + Point<float> (top.getLength(), 0.0f));
92 const Point<float> newBottomLeft (corners[0] + Point<float> (0.0f, left.getLength()));
93
94 topRight.moveToAbsolute (newTopRight, scope);
95 bottomLeft.moveToAbsolute (newBottomLeft, scope);
96
97 return AffineTransform::fromTargetPoints (corners[0], corners[0],
98 corners[1], newTopRight,
99 corners[2], newBottomLeft);
100}
101
102bool RelativeParallelogram::isDynamic() const
103{
104 return topLeft.isDynamic() || topRight.isDynamic() || bottomLeft.isDynamic();
105}
106
107bool RelativeParallelogram::operator== (const RelativeParallelogram& other) const noexcept
108{
109 return topLeft == other.topLeft && topRight == other.topRight && bottomLeft == other.bottomLeft;
110}
111
112bool RelativeParallelogram::operator!= (const RelativeParallelogram& other) const noexcept
113{
114 return ! operator== (other);
115}
116
117Point<float> RelativeParallelogram::getInternalCoordForPoint (const Point<float>* const corners, Point<float> target) noexcept
118{
119 const Point<float> tr (corners[1] - corners[0]);
120 const Point<float> bl (corners[2] - corners[0]);
121 target -= corners[0];
122
123 return Point<float> (Line<float> (Point<float>(), tr).getIntersection (Line<float> (target, target - bl)).getDistanceFromOrigin(),
124 Line<float> (Point<float>(), bl).getIntersection (Line<float> (target, target - tr)).getDistanceFromOrigin());
125}
126
127Point<float> RelativeParallelogram::getPointForInternalCoord (const Point<float>* const corners, const Point<float> point) noexcept
128{
129 return corners[0]
130 + Line<float> (Point<float>(), corners[1] - corners[0]).getPointAlongLine (point.x)
131 + Line<float> (Point<float>(), corners[2] - corners[0]).getPointAlongLine (point.y);
132}
133
134Rectangle<float> RelativeParallelogram::getBoundingBox (const Point<float>* const p) noexcept
135{
136 const Point<float> points[] = { p[0], p[1], p[2], p[1] + (p[2] - p[0]) };
137 return Rectangle<float>::findAreaContainingPoints (points, 4);
138}
139
140} // namespace juce
T left(T... args)
JUCE Namespace.