25 #ifndef JUCE_RECTANGLE_H_INCLUDED 26 #define JUCE_RECTANGLE_H_INCLUDED 35 template <
typename ValueType>
50 :
pos (other.pos),
w (other.w),
h (other.h)
57 :
pos (initialX, initialY),
70 :
pos (
jmin (corner1.x, corner2.x),
71 jmin (corner1.y, corner2.y)),
72 w (corner1.x - corner2.x),
73 h (corner1.y - corner2.y)
75 if (
w < ValueType())
w = -
w;
76 if (
h < ValueType())
h = -
h;
84 ValueType right, ValueType bottom)
noexcept 86 return Rectangle (left, top, right - left, bottom - top);
92 w = other.w;
h = other.h;
132 pos.y +
h / (ValueType) 2); }
168 void setSize (ValueType newWidth, ValueType newHeight)
noexcept {
w = newWidth;
h = newHeight; }
172 ValueType newWidth, ValueType newHeight)
noexcept {
pos.x = newX;
pos.y = newY;
w = newWidth;
h = newHeight; }
187 inline void setCentre (ValueType newCentreX, ValueType newCentreY)
noexcept {
pos.x = newCentreX -
w / (ValueType) 2;
188 pos.y = newCentreY -
h / (ValueType) 2; }
216 newCentre.y -
h / (ValueType) 2,
w,
h); }
229 pos.y + (
h - newHeight) / (ValueType) 2, newWidth, newHeight); }
316 pos += deltaPosition;
329 pos -= deltaPosition;
338 template <
typename FloatType>
351 template <
typename FloatType>
366 template <
typename FloatType>
370 pos.y * scaleFactor.y,
377 template <
typename FloatType>
386 template <
typename FloatType>
397 template <
typename FloatType>
401 pos.y / scaleFactor.y,
415 const ValueType nw =
jmax (ValueType(),
w + deltaX * 2);
416 const ValueType nh =
jmax (ValueType(),
h + deltaY * 2);
428 const ValueType nw =
jmax (ValueType(),
w + deltaX * 2);
429 const ValueType nh =
jmax (ValueType(),
h + deltaY * 2);
451 expand (-deltaX, -deltaY);
518 amountToRemove =
jmin (amountToRemove,
w);
535 amountToRemove =
jmin (amountToRemove,
h);
551 return xCoord >=
pos.x && yCoord >=
pos.y && xCoord <
pos.x +
w && yCoord <
pos.y +
h;
557 return point.x >=
pos.x && point.y >=
pos.y && point.x <
pos.x +
w && point.y <
pos.y +
h;
564 &&
pos.x +
w >= other.pos.x + other.w &&
pos.y +
h >= other.pos.y + other.h;
582 pos.y + static_cast <ValueType> (
h * relativeY));
588 return pos.x +
w > other.pos.x
589 &&
pos.y +
h > other.pos.y
590 &&
pos.x < other.
pos.x + other.
w 591 &&
pos.y < other.
pos.y + other.
h 592 &&
w > ValueType() &&
h > ValueType()
593 && other.w > ValueType() && other.h > ValueType();
611 const ValueType nx =
jmax (
pos.x, other.
pos.x);
612 const ValueType ny =
jmax (
pos.y, other.
pos.y);
613 const ValueType nw =
jmin (
pos.x +
w, other.pos.x + other.w) - nx;
614 const ValueType nh =
jmin (
pos.y +
h, other.pos.y + other.h) - ny;
616 if (nw >= ValueType() && nh >= ValueType())
628 const ValueType maxX (
jmax (otherX,
pos.x));
629 otherW =
jmin (otherX + otherW,
pos.x +
w) - maxX;
631 if (otherW > ValueType())
633 const ValueType maxY (
jmax (otherY,
pos.y));
634 otherH =
jmin (otherY + otherH,
pos.y +
h) - maxY;
636 if (otherH > ValueType())
638 otherX = maxX; otherY = maxY;
652 rectangleToClip.w, rectangleToClip.h);
662 if (other.isEmpty())
return *
this;
665 const ValueType newX =
jmin (
pos.x, other.
pos.x);
666 const ValueType newY =
jmin (
pos.y, other.
pos.y);
669 jmax (
pos.x +
w, other.pos.x + other.w) - newX,
670 jmax (
pos.y +
h, other.pos.y + other.h) - newY);
684 const ValueType newY =
jmin (
pos.y, other.
pos.y);
693 const ValueType newX =
jmin (
pos.x, other.
pos.x);
711 const ValueType otherR (other.getRight());
712 if (
pos.x >= other.
pos.x &&
pos.x < otherR) inside = 1;
713 const ValueType otherB (other.getBottom());
714 if (
pos.y >= other.
pos.y &&
pos.y < otherB) inside |= 2;
715 const ValueType r (
pos.x +
w);
716 if (r >= other.pos.x && r < otherR) inside |= 4;
717 const ValueType
b (
pos.y +
h);
718 if (b >= other.pos.y && b < otherB) inside |= 8;
722 case 1 + 2 + 8:
w = r - otherR;
pos.x = otherR;
return true;
723 case 1 + 2 + 4:
h = b - otherB;
pos.y = otherB;
return true;
724 case 2 + 4 + 8:
w = other.pos.x -
pos.x;
return true;
725 case 1 + 4 + 8:
h = other.pos.y -
pos.y;
return true;
740 const ValueType newW (
jmin (
w, areaToFitWithin.getWidth()));
741 const ValueType newH (
jmin (
h, areaToFitWithin.getHeight()));
743 return Rectangle (
jlimit (areaToFitWithin.getX(), areaToFitWithin.getRight() - newW,
pos.x),
744 jlimit (areaToFitWithin.getY(), areaToFitWithin.getBottom() - newH,
pos.y),
757 FloatType x1 =
static_cast<FloatType
> (
pos.x), y1 = static_cast<FloatType> (
pos.y);
758 FloatType x2 =
static_cast<FloatType
> (
pos.x +
w), y2 = static_cast<FloatType> (
pos.y);
759 FloatType x3 =
static_cast<FloatType
> (
pos.x), y3 = static_cast<FloatType> (
pos.y +
h);
760 FloatType x4 =
static_cast<FloatType
> (x2), y4 = static_cast<FloatType> (y3);
762 transform.transformPoints (x1, y1, x2, y2);
763 transform.transformPoints (x3, y3, x4, y4);
765 const FloatType rx1 =
jmin (x1, x2, x3, x4);
766 const FloatType rx2 =
jmax (x1, x2, x3, x4);
767 const FloatType ry1 =
jmin (y1, y2, y3, y4);
768 const FloatType ry2 =
jmax (y1, y2, y3, y4);
795 static_cast<float> (
w), static_cast<float> (
h));
804 static_cast<double> (
w), static_cast<double> (
h));
811 template <
typename TargetType>
825 ValueType minX (points[0].x);
826 ValueType maxX (minX);
827 ValueType minY (points[0].y);
828 ValueType maxY (minY);
830 for (
int i = 1; i < numPoints; ++i)
832 minX =
jmin (minX, points[i].x);
833 maxX =
jmax (maxX, points[i].x);
834 minY =
jmin (minY, points[i].y);
835 maxY =
jmax (maxY, points[i].y);
838 return Rectangle (minX, minY, maxX - minX, maxY - minY);
847 const ValueType x2,
const ValueType y2,
const ValueType w2,
const ValueType h2)
noexcept 849 const ValueType x (
jmax (x1, x2));
850 w1 =
jmin (x1 + w1, x2 + w2) - x;
852 if (w1 > ValueType())
854 const ValueType y (
jmax (y1, y2));
855 h1 =
jmin (y1 + h1, y2 + h2) - y;
857 if (h1 > ValueType())
881 s <<
pos.x <<
' ' <<
pos.y <<
' ' <<
w <<
' ' <<
h;
898 toks.
addTokens (stringVersion.
text.findEndOfWhitespace(),
",; \t\r\n",
"");
912 template <typename OtherType>
friend class Rectangle;
918 {
return s.text.findEndOfWhitespace().getIntValue32(); }
925 static int floorAsInt (
float n) noexcept {
return (
int) std::floor (n); }
926 static int floorAsInt (
double n) noexcept {
return (
int) std::floor (n); }
928 static int ceilAsInt (
float n) noexcept {
return (
int) std::ceil (n); }
929 static int ceilAsInt (
double n) noexcept {
return (
int) std::ceil (n); }
933 #endif // JUCE_RECTANGLE_H_INCLUDED Rectangle(Point< ValueType > corner1, Point< ValueType > corner2) noexcept
Definition: juce_Rectangle.h:69
bool contains(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:561
Rectangle withBottom(ValueType newBottom) const noexcept
Definition: juce_Rectangle.h:277
Rectangle withLeft(ValueType newLeft) const noexcept
Definition: juce_Rectangle.h:241
void setCentre(Point< ValueType > newCentre) noexcept
Definition: juce_Rectangle.h:191
Rectangle withPosition(Point< ValueType > newPos) const noexcept
Definition: juce_Rectangle.h:209
ValueType w
Definition: juce_Rectangle.h:915
Rectangle(ValueType width, ValueType height) noexcept
Definition: juce_Rectangle.h:63
ValueType getWidth() const noexcept
Definition: juce_Rectangle.h:113
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Definition: juce_StringArray.cpp:345
Rectangle withPosition(ValueType newX, ValueType newY) const noexcept
Definition: juce_Rectangle.h:206
bool operator!=(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:546
void setCentre(ValueType newCentreX, ValueType newCentreY) noexcept
Definition: juce_Rectangle.h:187
Rectangle translated(ValueType deltaX, ValueType deltaY) const noexcept
Definition: juce_Rectangle.h:301
static int ceilAsInt(int n) noexcept
Definition: juce_Rectangle.h:927
Rectangle withSize(ValueType newWidth, ValueType newHeight) const noexcept
Definition: juce_Rectangle.h:225
String::CharPointerType text
Definition: juce_StringRef.h:119
Rectangle removeFromRight(ValueType amountToRemove) noexcept
Definition: juce_Rectangle.h:516
void setTop(ValueType newTop) noexcept
Definition: juce_Rectangle.h:247
ValueType getRight() const noexcept
Definition: juce_Rectangle.h:119
void setHeight(ValueType newHeight) noexcept
Definition: juce_Rectangle.h:184
Point< ValueType > getCentre() const noexcept
Definition: juce_Rectangle.h:131
ValueType getAspectRatio(bool widthOverHeight=true) const noexcept
Definition: juce_Rectangle.h:137
Rectangle withCentre(Point< ValueType > newCentre) const noexcept
Definition: juce_Rectangle.h:215
void expand(ValueType deltaX, ValueType deltaY) noexcept
Definition: juce_Rectangle.h:412
Definition: juce_Line.h:44
#define noexcept
Definition: juce_CompilerSupport.h:141
void copyWithRounding(Rectangle< float > &result) const noexcept
Definition: juce_Rectangle.h:921
bool reduceIfPartlyContainedIn(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:708
ValueType getCentreX() const noexcept
Definition: juce_Rectangle.h:125
Rectangle getUnion(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:660
ValueType getX() const noexcept
Definition: juce_Rectangle.h:107
Point< ValueType > getBottomLeft() const noexcept
Definition: juce_Rectangle.h:156
static int floorAsInt(double n) noexcept
Definition: juce_Rectangle.h:926
Rectangle withY(ValueType newY) const noexcept
Definition: juce_Rectangle.h:203
Rectangle withZeroOrigin() const noexcept
Definition: juce_Rectangle.h:212
ValueType getHeight() const noexcept
Definition: juce_Rectangle.h:116
Type jmin(const Type a, const Type b)
Definition: juce_core.h:113
Rectangle withRight(ValueType newRight) const noexcept
Definition: juce_Rectangle.h:265
Definition: juce_Range.h:44
Rectangle transformedBy(const AffineTransform &transform) const noexcept
Definition: juce_Rectangle.h:753
void setHorizontalRange(Range< ValueType > range) noexcept
Definition: juce_Rectangle.h:194
Rectangle expanded(ValueType deltaX, ValueType deltaY) const noexcept
Definition: juce_Rectangle.h:425
bool intersects(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:586
Rectangle withTrimmedLeft(ValueType amountToRemove) const noexcept
Definition: juce_Rectangle.h:280
Rectangle withTrimmedTop(ValueType amountToRemove) const noexcept
Definition: juce_Rectangle.h:286
Range< ValueType > getVerticalRange() const noexcept
Definition: juce_Rectangle.h:165
void copyWithRounding(Rectangle< double > &result) const noexcept
Definition: juce_Rectangle.h:922
Rectangle & operator-=(Point< ValueType > deltaPosition) noexcept
Definition: juce_Rectangle.h:327
Rectangle operator/=(FloatType scaleFactor) noexcept
Definition: juce_Rectangle.h:387
Rectangle< float > toFloat() const noexcept
Definition: juce_Rectangle.h:792
void setLeft(ValueType newLeft) noexcept
Definition: juce_Rectangle.h:235
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Definition: juce_Rectangle.h:549
void copyWithRounding(Rectangle< int > &result) const noexcept
Definition: juce_Rectangle.h:920
static int ceilAsInt(double n) noexcept
Definition: juce_Rectangle.h:929
Definition: juce_Point.h:39
Definition: juce_String.h:43
Rectangle operator*(FloatType scaleFactor) const noexcept
Definition: juce_Rectangle.h:339
long b
Definition: jpegint.h:371
static Rectangle findAreaContainingPoints(const Point< ValueType > *const points, const int numPoints) noexcept
Definition: juce_Rectangle.h:820
Rectangle withHeight(ValueType newHeight) const noexcept
Definition: juce_Rectangle.h:222
Rectangle< TargetType > toType() const noexcept
Definition: juce_Rectangle.h:812
Rectangle removeFromLeft(ValueType amountToRemove) noexcept
Definition: juce_Rectangle.h:500
Range< ValueType > getHorizontalRange() const noexcept
Definition: juce_Rectangle.h:162
void setBounds(ValueType newX, ValueType newY, ValueType newWidth, ValueType newHeight) noexcept
Definition: juce_Rectangle.h:171
ValueType getBottom() const noexcept
Definition: juce_Rectangle.h:122
Rectangle & operator+=(Point< ValueType > deltaPosition) noexcept
Definition: juce_Rectangle.h:314
void setX(ValueType newX) noexcept
Definition: juce_Rectangle.h:175
Definition: juce_Rectangle.h:36
Rectangle(ValueType initialX, ValueType initialY, ValueType width, ValueType height) noexcept
Definition: juce_Rectangle.h:55
static int parseIntAfterSpace(StringRef s) noexcept
Definition: juce_Rectangle.h:917
Point< ValueType > getBottomRight() const noexcept
Definition: juce_Rectangle.h:159
void setSize(ValueType newWidth, ValueType newHeight) noexcept
Definition: juce_Rectangle.h:168
Rectangle operator/(FloatType scaleFactor) const noexcept
Definition: juce_Rectangle.h:378
Rectangle withWidth(ValueType newWidth) const noexcept
Definition: juce_Rectangle.h:219
bool isFinite() const noexcept
Definition: juce_Rectangle.h:104
Rectangle & operator=(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:89
Rectangle() noexcept
Definition: juce_Rectangle.h:43
void setY(ValueType newY) noexcept
Definition: juce_Rectangle.h:178
static Rectangle fromString(StringRef stringVersion)
Definition: juce_Rectangle.h:895
Rectangle operator+(Point< ValueType > deltaPosition) const noexcept
Definition: juce_Rectangle.h:308
void setRight(ValueType newRight) noexcept
Definition: juce_Rectangle.h:259
Rectangle withTrimmedBottom(ValueType amountToRemove) const noexcept
Definition: juce_Rectangle.h:289
Rectangle< double > toDouble() const noexcept
Definition: juce_Rectangle.h:801
Rectangle withX(ValueType newX) const noexcept
Definition: juce_Rectangle.h:200
bool intersectRectangle(ValueType &otherX, ValueType &otherY, ValueType &otherW, ValueType &otherH) const noexcept
Definition: juce_Rectangle.h:626
Type jmax(const Type a, const Type b)
Definition: juce_core.h:101
bool enlargeIfAdjacent(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:679
Rectangle withSizeKeepingCentre(ValueType newWidth, ValueType newHeight) const noexcept
Definition: juce_Rectangle.h:228
void setPosition(ValueType newX, ValueType newY) noexcept
Definition: juce_Rectangle.h:147
Point< ValueType > getPosition() const noexcept
Definition: juce_Rectangle.h:141
png_const_structrp png_const_inforp int png_fixed_point * width
Definition: juce_PNGLoader.cpp:2339
Definition: juce_StringArray.h:39
bool intersects(const Line< ValueType > &line) const noexcept
Definition: juce_Rectangle.h:597
static Rectangle leftTopRightBottom(ValueType left, ValueType top, ValueType right, ValueType bottom) noexcept
Definition: juce_Rectangle.h:83
void setVerticalRange(Range< ValueType > range) noexcept
Definition: juce_Rectangle.h:197
Type jlimit(const Type lowerLimit, const Type upperLimit, const Type valueToConstrain) noexcept
Definition: juce_MathsFunctions.h:220
static Range withStartAndLength(const ValueType startValue, const ValueType length) noexcept
Definition: juce_Range.h:81
Rectangle expanded(ValueType delta) const noexcept
Definition: juce_Rectangle.h:438
Rectangle constrainedWithin(const Rectangle &areaToFitWithin) const noexcept
Definition: juce_Rectangle.h:738
float type
Definition: juce_MathsFunctions.h:607
void preallocateBytes(size_t numBytesNeeded)
Definition: juce_String.cpp:300
ValueType h
Definition: juce_Rectangle.h:915
Point< ValueType > getRelativePoint(double relativeX, double relativeY) const noexcept
Definition: juce_Rectangle.h:579
ValueType getY() const noexcept
Definition: juce_Rectangle.h:110
void setBottom(ValueType newBottom) noexcept
Definition: juce_Rectangle.h:271
Rectangle< int > getSmallestIntegerContainer() const noexcept
Definition: juce_Rectangle.h:779
void setWidth(ValueType newWidth) noexcept
Definition: juce_Rectangle.h:181
bool intersectRectangle(Rectangle< ValueType > &rectangleToClip) const noexcept
Definition: juce_Rectangle.h:649
Rectangle removeFromBottom(ValueType amountToRemove) noexcept
Definition: juce_Rectangle.h:533
Rectangle(const Rectangle &other) noexcept
Definition: juce_Rectangle.h:49
ValueType getCentreY() const noexcept
Definition: juce_Rectangle.h:128
Rectangle operator-(Point< ValueType > deltaPosition) const noexcept
Definition: juce_Rectangle.h:321
void reduce(ValueType deltaX, ValueType deltaY) noexcept
Definition: juce_Rectangle.h:448
Rectangle reduced(ValueType delta) const noexcept
Definition: juce_Rectangle.h:470
Rectangle getIntersection(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:609
bool juce_isfinite(NumericType) noexcept
Definition: juce_core.h:374
bool contains(Point< ValueType > point) const noexcept
Definition: juce_Rectangle.h:555
Rectangle removeFromTop(ValueType amountToRemove) noexcept
Definition: juce_Rectangle.h:484
Point< ValueType > getTopRight() const noexcept
Definition: juce_Rectangle.h:153
static int floorAsInt(int n) noexcept
Definition: juce_Rectangle.h:924
Rectangle operator*=(FloatType scaleFactor) noexcept
Definition: juce_Rectangle.h:352
void setPosition(Point< ValueType > newPos) noexcept
Definition: juce_Rectangle.h:144
void translate(ValueType deltaX, ValueType deltaY) noexcept
Definition: juce_Rectangle.h:293
Rectangle withTop(ValueType newTop) const noexcept
Definition: juce_Rectangle.h:253
~Rectangle() noexcept
Definition: juce_Rectangle.h:97
Rectangle reduced(ValueType deltaX, ValueType deltaY) const noexcept
Definition: juce_Rectangle.h:459
static bool intersectRectangles(ValueType &x1, ValueType &y1, ValueType &w1, ValueType &h1, const ValueType x2, const ValueType y2, const ValueType w2, const ValueType h2) noexcept
Definition: juce_Rectangle.h:846
Point< ValueType > getTopLeft() const noexcept
Definition: juce_Rectangle.h:150
static int floorAsInt(float n) noexcept
Definition: juce_Rectangle.h:925
Rectangle withTrimmedRight(ValueType amountToRemove) const noexcept
Definition: juce_Rectangle.h:283
static int ceilAsInt(float n) noexcept
Definition: juce_Rectangle.h:928
Point< ValueType > getConstrainedPoint(Point< ValueType > point) const noexcept
Definition: juce_Rectangle.h:568
JUCE_DEPRECATED_WITH_BODY(Rectangle transformed(const AffineTransform &t) const noexcept,{return transformedBy(t);}) private Point< ValueType > pos
Definition: juce_Rectangle.h:908
String toString() const
Definition: juce_Rectangle.h:877
Definition: juce_StringRef.h:65
bool operator==(const Rectangle &other) const noexcept
Definition: juce_Rectangle.h:543
bool isEmpty() const noexcept
Definition: juce_Rectangle.h:101