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_Parallelogram.h
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
29//==============================================================================
36template <typename ValueType>
38{
39public:
40 //==============================================================================
43 Parallelogram() = default;
44
46 Parallelogram (const Parallelogram&) = default;
47
55
58 : topLeft (rectangle.getTopLeft()),
59 topRight (rectangle.getTopRight()),
60 bottomLeft (rectangle.getBottomLeft())
61 {
62 }
63
64 Parallelogram& operator= (const Parallelogram&) = default;
65
67 ~Parallelogram() = default;
68
69 //==============================================================================
71 bool isEmpty() const noexcept { return topLeft != topRight || topLeft != bottomLeft; }
72
74 inline bool isFinite() const noexcept { return topLeft.isFinite() && topRight.isFinite() && bottomLeft.isFinite(); }
75
77 inline ValueType getWidth() const noexcept { return Line<ValueType> (topLeft, topRight).getLength(); }
78
80 inline ValueType getHeight() const noexcept { return Line<ValueType> (topLeft, bottomLeft).getLength(); }
81
82 //==============================================================================
84 Point<ValueType> getTopLeft() const noexcept { return topLeft; }
85
87 Point<ValueType> getTopRight() const noexcept { return topRight; }
88
90 Point<ValueType> getBottomLeft() const noexcept { return bottomLeft; }
91
93 Point<ValueType> getBottomRight() const noexcept { return topRight + (bottomLeft - topLeft); }
94
95 //==============================================================================
97 bool operator== (const Parallelogram& other) const noexcept { return topLeft == other.topLeft && topRight == other.topRight && bottomLeft == other.bottomLeft; }
98
100 bool operator!= (const Parallelogram& other) const noexcept { return ! operator== (other); }
101
102 //==============================================================================
105 {
106 auto p = *this;
107 p += deltaPosition;
108 return p;
109 }
110
113 {
114 topLeft += deltaPosition;
115 topRight += deltaPosition;
116 bottomLeft += deltaPosition;
117 return *this;
118 }
119
125
131
133 template <typename PointOrScalarType>
134 Parallelogram operator* (PointOrScalarType scaleFactor) const noexcept
135 {
136 auto p = *this;
137 p *= scaleFactor;
138 return p;
139 }
140
142 template <typename PointOrScalarType>
144 {
145 topLeft *= scaleFactor;
146 topRight *= scaleFactor;
147 bottomLeft *= scaleFactor;
148 return *this;
149 }
150
151 //==============================================================================
158 {
159 return topLeft
160 + (topRight - topLeft) * relativePosition.x
161 + (bottomLeft - topLeft) * relativePosition.y;
162 }
163
165 Parallelogram transformedBy (const AffineTransform& transform) const noexcept
166 {
167 auto p = *this;
168 transform.transformPoints (p.topLeft.x, p.topLeft.y,
169 p.topRight.x, p.topRight.y,
170 p.bottomLeft.x, p.bottomLeft.y);
171
172 return p;
173 }
174
177 {
178 const Point<ValueType> points[] = { topLeft, topRight, bottomLeft, getBottomRight() };
180 }
181
182 Point<ValueType> topLeft, topRight, bottomLeft;
183};
184
185} // namespace juce
Represents a 2D affine-transformation matrix.
Represents a parallelogram that is defined by 3 points.
Parallelogram(Rectangle< ValueType > rectangle) noexcept
Creates a parallelogram from a rectangle.
ValueType getWidth() const noexcept
Returns the width of the parallelogram (i.e.
Parallelogram & operator+=(Point< ValueType > deltaPosition) noexcept
Moves this parallelogram by a given amount.
bool operator!=(const Parallelogram &other) const noexcept
Returns true if the two parallelograms are not identical.
Point< ValueType > getTopRight() const noexcept
Returns the parallelogram's top-right position as a Point.
Parallelogram()=default
Creates a parallelogram with zero size at the origin.
Parallelogram operator+(Point< ValueType > deltaPosition) const noexcept
Returns a parallelogram which is the same as this one moved by a given amount.
Parallelogram & operator-=(Point< ValueType > deltaPosition) noexcept
Moves this parallelogram by a given amount.
Parallelogram transformedBy(const AffineTransform &transform) const noexcept
Returns a transformed version of the parallelogram.
Parallelogram(Point< ValueType > topLeftPosition, Point< ValueType > topRightPosition, Point< ValueType > bottomLeftPosition) noexcept
Creates a parallelogram based on 3 points.
Point< ValueType > getTopLeft() const noexcept
Returns the parallelogram's top-left position as a Point.
Point< ValueType > getBottomLeft() const noexcept
Returns the parallelogram's bottom-left position as a Point.
Point< ValueType > getBottomRight() const noexcept
Returns the parallelogram's bottom-right position as a Point.
Point< ValueType > getRelativePoint(Point< ValueType > relativePosition) const noexcept
Returns a point within this parallelogram, specified as proportional coordinates.
Parallelogram operator*=(PointOrScalarType scaleFactor) noexcept
Scales this parallelogram by the given amount, centred around the origin.
Rectangle< ValueType > getBoundingBox() const noexcept
Returns the smallest rectangle that encloses this parallelogram.
bool isEmpty() const noexcept
Returns true if the parallelogram has a width or height of more than zero.
Parallelogram operator-(Point< ValueType > deltaPosition) const noexcept
Returns a parallelogram which is the same as this one moved by a given amount.
bool operator==(const Parallelogram &other) const noexcept
Returns true if the two parallelograms are identical.
bool isFinite() const noexcept
Returns true if the parallelogram's coordinates are all finite numbers, i.e.
Parallelogram operator*(PointOrScalarType scaleFactor) const noexcept
Returns a parallelogram that has been scaled by the given amount, centred around the origin.
ValueType getHeight() const noexcept
Returns the height of the parallelogram (i.e.
Parallelogram(const Parallelogram &)=default
Creates a copy of another parallelogram.
~Parallelogram()=default
Destructor.
A pair of (x, y) coordinates.
Definition juce_Point.h:42
Manages a rectangle and allows geometric operations to be performed on it.
static Rectangle findAreaContainingPoints(const Point< ValueType > *points, int numPoints) noexcept
Returns the smallest Rectangle that can contain a set of points.
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