Axis-aligned half-open rectangle [left, right) x [top, bottom). More...
#include <SimdRectangle.hpp>
Public Types | |
| typedef T | Type |
Public Member Functions | |
| Rectangle () | |
| template<typename TL , typename TT , typename TR , typename TB > | |
| Rectangle (TL l, TT t, TR r, TB b) | |
| template<typename TLT , typename TRB > | |
| Rectangle (const Point< TLT > <, const Point< TRB > &rb) | |
| template<typename TRB > | |
| Rectangle (const Point< TRB > &rb) | |
| template<class TR , template< class > class TRectangle> | |
| Rectangle (const TRectangle< TR > &r) | |
| template<class TR > | |
| Rectangle (const cv::Rect_< TR > &r) | |
| ~Rectangle () | |
| template<class TR , template< class > class TRectangle> | |
| operator TRectangle< TR > () const | |
| template<class TR > | |
| operator cv::Rect_< TR > () const | |
| template<typename TR > | |
| Rectangle< T > & | operator= (const Rectangle< TR > &r) |
| template<typename TR > | |
| Rectangle< T > & | operator= (const cv::Rect_< TR > &r) |
| template<typename TL > | |
| Rectangle< T > & | SetLeft (const TL &l) |
| template<typename TT > | |
| Rectangle< T > & | SetTop (const TT &t) |
| template<typename TR > | |
| Rectangle< T > & | SetRight (const TR &r) |
| template<typename TB > | |
| Rectangle< T > & | SetBottom (const TB &b) |
| template<typename TP > | |
| Rectangle< T > & | SetTopLeft (const Point< TP > &topLeft) |
| template<typename TP > | |
| Rectangle< T > & | SetTopRight (const Point< TP > &topRight) |
| template<typename TP > | |
| Rectangle< T > & | SetBottomLeft (const Point< TP > &bottomLeft) |
| template<typename TP > | |
| Rectangle< T > & | SetBottomRight (const Point< TP > &bottomRight) |
| T | Left () const |
| T | Top () const |
| T | Right () const |
| T | Bottom () const |
| Point< T > | TopLeft () const |
| Point< T > | TopRight () const |
| Point< T > | BottomLeft () const |
| Point< T > | BottomRight () const |
| T | Width () const |
| T | Height () const |
| T | Area () const |
| bool | Empty () const |
| Point< T > | Size () const |
| Point< T > | Center () const |
| template<typename TX , typename TY > | |
| bool | Contains (TX x, TY y) const |
| template<typename TP > | |
| bool | Contains (const Point< TP > &p) const |
| template<typename TL , typename TT , typename TR , typename TB > | |
| bool | Contains (TL l, TT t, TR r, TB b) const |
| template<typename TR > | |
| bool | Contains (const Rectangle< TR > &r) const |
| template<typename TP > | |
| Rectangle< T > & | Shift (const Point< TP > &shift) |
| template<typename TX , typename TY > | |
| Rectangle< T > & | Shift (TX shiftX, TY shiftY) |
| template<typename TP > | |
| Rectangle< T > | Shifted (const Point< TP > &shift) const |
| template<typename TX , typename TY > | |
| Rectangle< T > | Shifted (TX shiftX, TY shiftY) const |
| template<typename TB > | |
| Rectangle< T > & | AddBorder (TB border) |
| template<typename TR > | |
| Rectangle< T > | Intersection (const Rectangle< TR > &r) const |
| template<typename TP > | |
| Rectangle< T > & | operator&= (const Point< TP > &p) |
| template<typename TR > | |
| Rectangle< T > & | operator&= (const Rectangle< TR > &r) |
| template<typename TP > | |
| Rectangle< T > & | operator|= (const Point< TP > &p) |
| template<typename TR > | |
| Rectangle< T > & | operator|= (const Rectangle< TR > &r) |
| template<typename TR > | |
| Rectangle< T > & | operator+= (const Rectangle< TR > &r) |
| bool | Overlaps (const Rectangle< T > &r) const |
Detailed Description
struct Simd::Rectangle< T >
Axis-aligned half-open rectangle [left, right) x [top, bottom).
Rectangle<T> stores the four sides of an axis-aligned rectangle. The right and bottom sides are exclusive: the covered area is [left, right) x [top, bottom). Width() is right - left and Height() is bottom - top. Image coordinates have their origin at the top-left corner, X grows to the right and Y grows downward. Contains(x, y), DrawFilledRectangle, View::Region, Frame::Region, CopyFrame and FillFrame all use that half-open range. A point with x == right or y == bottom lies outside the rectangle.
Rectangle<ptrdiff_t> is the image rectangle. View::Region, View::Clone, View::Copy and Frame::Region take it as a region of interest. Simd::DrawRectangle and Simd::DrawFilledRectangle draw it. Simd::CopyFrame and Simd::FillFrame leave its interior unchanged and process the border around it. Simd::ShiftBilinear shifts pixels inside the crop and copies the area outside the crop from the source. Simd::SegmentationShrinkRegion rewrites the rectangle as the bounding box of one mask index. Motion::Rect is an object box or a moving region. ContourDetector::Rect is the region of interest. ShiftDetector::Rect is the correlation window.
Rectangle() is (0, 0, 0, 0). Its area is 0, so Empty() is true. Motion starts a moving region from Rect() and grows it with operator |= and each accepted pixel. ContourDetector replaces an empty ROI with Rect(src.Size()). SegmentationShrinkRegion writes (0, 0, 0, 0) when the index is absent.
Rectangle(point) sets the top-left corner to (0, 0) and the bottom-right corner to the point, so Rectangle(view.Size()) is the whole image [0, width) x [0, height). TestImageMatcher passes Rect(src.Size()) as the crop of Simd::ShiftBilinear. SegmentationShrinkRegion tightens a rectangle to the ROI mask. DrawFilledRectangle clips the fill with rect &= Rectangle(canvas.Size()).
Values passed to a constructor are converted to T. Conversion of float or double to ptrdiff_t rounds to the nearest integer, with halves away from zero. Other conversions are a C-style cast. Assignment from another Rectangle and the converting constructor copy the four sides the same way. operator* and operator/ scale every side and then construct the result, so a floating factor applied to Rectangle<ptrdiff_t> is rounded. Rect(0, 0, 10, 20) * 1.5 is (0, 0, 15, 30). Rect(0, 0, 11, 21) / 2 uses integer division and is (0, 0, 5, 10). A motion trajectory is averaged by adding rectangles with operator += and dividing by the count.
operator |= with a point grows the half-open box so that the pixel is inside. An empty rectangle becomes the one-pixel cell [x, x + 1) x [y, y + 1). Motion flood-fill writes region->rect |= current for every accepted pixel. operator |= with a rectangle is the bounding union. Font::Draw unions glyph cells into the alpha rectangle. operator &= with a rectangle is the in-place intersection. An empty rectangle is left unchanged. An empty argument replaces this rectangle. ShiftDetector clips a shifted window with region &= Rect(image.Size()) and then Shift(-shift) moves it back. Motion clips a tracked object with object->rect &= Rect(frameSize). Intersection returns a new rectangle and leaves this one unchanged. A disjoint pair produces an empty rectangle whose width and height are non-negative. Font skips a glyph when canvas.Intersection(shifted).Empty().
AddBorder adds the same margin on every side: left and top decrease, right and bottom increase. A negative margin shrinks the rectangle. Motion::ShrinkRoi calls AddBorder(1) after SegmentationShrinkRegion. ExpandRoi expands the parent ROI with AddBorder(1) and insets the child mask with AddBorder(-1) before operator &=. Enlarged grows a box by a fraction of (Width() + Height()) / 2 so Contains can link a center that lies just outside the original box. TestShift shrinks the correlation window with AddBorder(-hs / 4).
Shift adds a translation to all four sides. Shifted returns the translated rectangle and leaves this one unchanged. ShiftDetector compares background.Region(region.Shifted(shift)) with current.Region(region). Motion recenters a tracked box with object->rect.Shift(nearest->rect.Center() - object->rect.Center()). Font places a glyph with current.Shifted(shift + indent) and moves the alpha box to the origin with alphaRect.Shift(-alphaRect.TopLeft()).
With SIMD_OPENCV_ENABLE, a rectangle converts to and from cv::Rect_<T>. OpenCV stores (x, y, width, height). This structure stores (left, top, right, bottom). Assignment from cv::Rect sets left = x, top = y, right = x + width and bottom = y + height. Assignment to cv::Rect sets x = left, y = top, width = right - left and height = bottom - top.
Using example:
OpenCV conversion (define SIMD_OPENCV_ENABLE before including this header):
Member Typedef Documentation
◆ Type
| typedef T Type |
Side coordinate type. ptrdiff_t is a pixel rectangle.
Constructor & Destructor Documentation
◆ Rectangle() [1/6]
| SIMD_INLINE Rectangle |
Creates the empty rectangle (0, 0, 0, 0).
Empty() is true. Motion starts a moving region from Rect() and grows it with operator |=. ContourDetector treats an empty ROI as the whole image.
◆ Rectangle() [2/6]
| Rectangle | ( | TL | l, |
| TT | t, | ||
| TR | r, | ||
| TB | b | ||
| ) |
Creates a rectangle from the four sides.
Each side is converted to T. float and double values converted to ptrdiff_t are rounded to the nearest integer, with halves rounded away from zero. The rectangle is half-open: [l, r) x [t, b). TestShift builds the correlation window as Rect(c.x - hs, c.y - hs, c.x + hs, c.y + hs). CopyFrame and FillFrame require 0 <= left <= right <= width and 0 <= top <= bottom <= height.
- Parameters
-
[in] l - initial left side. Pixels with x >= left are inside. [in] t - initial top side. Pixels with y >= top are inside. [in] r - initial right side. Pixels with x >= right are outside. [in] b - initial bottom side. Pixels with y >= bottom are outside.
◆ Rectangle() [3/6]
Creates a rectangle from its top-left and bottom-right corners.
left and top are taken from lt. right and bottom are taken from rb. Each coordinate is converted to T. DrawRectangle(topLeft, bottomRight) builds this rectangle and draws the frame. Font::Draw builds a glyph cell as Rect(curr, curr + glyphSize), where curr + glyphSize is the exclusive bottom-right corner.
- Parameters
-
[in] lt - top-left corner. Its x and y become left and top. [in] rb - bottom-right corner. Its x and y become right and bottom.
◆ Rectangle() [4/6]
Creates a rectangle [0, rb.x) x [0, rb.y).
The top-left corner is (0, 0). The point is the exclusive bottom-right corner, so Rectangle(view.Size()) is the whole image. TestImageMatcher passes Rect(src.Size()) as the ShiftBilinear crop. SegmentationShrinkRegion checks Contains against Rectangle(mask.Size()). DrawFilledRectangle and ShiftDetector clip a rectangle with &= Rectangle(image.Size()).
- Parameters
-
[in] rb - exclusive bottom-right corner. x becomes right and y becomes bottom.
◆ Rectangle() [5/6]
| Rectangle | ( | const TRectangle< TR > & | r | ) |
Creates a rectangle by copying the four sides of another rectangle type.
The source must be a class template with left, top, right and bottom. Each side is converted to T. This copies between Rectangle<ptrdiff_t> and Rectangle<double>. With SIMD_OPENCV_ENABLE the cv::Rect_ constructor below is a separate overload: OpenCV stores width and height, and this constructor does not read them.
- Parameters
-
[in] r - a rectangle of arbitrary type with left, top, right and bottom.
◆ Rectangle() [6/6]
| Rectangle | ( | const cv::Rect_< TR > & | r | ) |
Creates a rectangle from an OpenCV rectangle.
cv::Rect_ stores (x, y, width, height). The Simd rectangle stores the half-open sides left = x, top = y, right = x + width and bottom = y + height. Each value is converted to T, so a floating OpenCV rectangle assigned to Rectangle<ptrdiff_t> is rounded.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Parameters
-
[in] r - an OpenCV rectangle (x, y, width, height).
◆ ~Rectangle()
| SIMD_INLINE ~Rectangle |
Destroys the rectangle. The destructor has no side effects.
Member Function Documentation
◆ operator TRectangle< TR >()
| operator TRectangle< TR > | ( | ) | const |
Converts this rectangle to another rectangle type constructed from the four sides.
The target is constructed as TRectangle<TR>(left, top, right, bottom). Each side is converted to TR. With SIMD_OPENCV_ENABLE, conversion to cv::Rect_ uses the dedicated operator below, which passes width and height rather than right and bottom.
- Returns
- a rectangle of arbitrary type.
◆ operator cv::Rect_< TR >()
| operator cv::Rect_< TR > | ( | ) | const |
Converts this rectangle to an OpenCV rectangle.
The result is cv::Rect_<TR>(left, top, right - left, bottom - top). OpenCV therefore receives x, y, width and height. Conversion to ptrdiff_t rounds float and double; conversion to any other type is a C-style cast. A Rectangle<ptrdiff_t> converted to cv::Rect_<double> keeps the integer sides.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Returns
- an OpenCV rectangle (x, y, width, height).
◆ operator=() [1/2]
Copies the four sides of another rectangle.
Each side is converted to T. Assigning Rectangle<double> to Rectangle<ptrdiff_t> rounds every side.
- Parameters
-
[in] r - a rectangle of arbitrary coordinate type.
- Returns
- a reference to itself.
◆ operator=() [2/2]
| Rectangle< T > & operator= | ( | const cv::Rect_< TR > & | r | ) |
Copies an OpenCV rectangle into this rectangle.
left = x, top = y, right = x + width and bottom = y + height. Each value is converted to T.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Parameters
-
[in] r - an OpenCV rectangle (x, y, width, height).
- Returns
- a reference to itself.
◆ SetLeft()
| Rectangle< T > & SetLeft | ( | const TL & | l | ) |
Sets the left side.
The value is converted to T. Pixels with x >= left are candidates for the interior. The method does not move the other sides.
- Parameters
-
[in] l - a new left side.
- Returns
- a reference to itself.
◆ SetTop()
| Rectangle< T > & SetTop | ( | const TT & | t | ) |
Sets the top side.
The value is converted to T. Pixels with y >= top are candidates for the interior. The method does not move the other sides.
- Parameters
-
[in] t - a new top side.
- Returns
- a reference to itself.
◆ SetRight()
| Rectangle< T > & SetRight | ( | const TR & | r | ) |
Sets the right side.
The value is converted to T. The right side is exclusive: pixels with x >= right are outside. The method does not move the other sides.
- Parameters
-
[in] r - a new right side.
- Returns
- a reference to itself.
◆ SetBottom()
| Rectangle< T > & SetBottom | ( | const TB & | b | ) |
Sets the bottom side.
The value is converted to T. The bottom side is exclusive: pixels with y >= bottom are outside. The method does not move the other sides.
- Parameters
-
[in] b - a new bottom side.
- Returns
- a reference to itself.
◆ SetTopLeft()
Sets the top-left corner.
left and top are converted from the point. right and bottom stay unchanged. Motion::ExpandRoi maps a parent ROI onto the next pyramid level with SetTopLeft(parent.TopLeft() * 2 - Point(1, 1)).
- Parameters
-
[in] topLeft - a new top-left corner.
- Returns
- a reference to itself.
◆ SetTopRight()
Sets the top-right corner.
right and top are converted from the point. left and bottom stay unchanged. The right coordinate remains exclusive.
- Parameters
-
[in] topRight - a new top-right corner.
- Returns
- a reference to itself.
◆ SetBottomLeft()
Sets the bottom-left corner.
left and bottom are converted from the point. right and top stay unchanged. The bottom coordinate remains exclusive.
- Parameters
-
[in] bottomLeft - a new bottom-left corner.
- Returns
- a reference to itself.
◆ SetBottomRight()
Sets the bottom-right corner.
right and bottom are converted from the point. left and top stay unchanged. Motion::ExpandRoi writes the child corner with SetBottomRight(parent.BottomRight() * 2 + Point(1, 1)).
- Parameters
-
[in] bottomRight - a new bottom-right corner.
- Returns
- a reference to itself.
◆ Left()
| SIMD_INLINE T Left |
◆ Top()
| SIMD_INLINE T Top |
Returns the inclusive top side.
- Returns
- the top side.
◆ Right()
| SIMD_INLINE T Right |
Returns the exclusive right side.
- Returns
- the right side.
◆ Bottom()
| SIMD_INLINE T Bottom |
Returns the exclusive bottom side.
- Returns
- the bottom side.
◆ TopLeft()
| SIMD_INLINE Point< T > TopLeft |
Returns the top-left corner (left, top).
Motion::ExpandRoi scales this corner onto the next pyramid level with TopLeft() * 2 - Point(1, 1). Font::Draw shifts glyph cells by -alphaRect.TopLeft() so the alpha image starts at the origin.
- Returns
- the top-left corner.
◆ TopRight()
| SIMD_INLINE Point< T > TopRight |
Returns the top-right corner (right, top).
right is the exclusive edge, so this corner lies outside the rectangle when the width is positive.
- Returns
- the top-right corner.
◆ BottomLeft()
| SIMD_INLINE Point< T > BottomLeft |
Returns the bottom-left corner (left, bottom).
bottom is the exclusive edge, so this corner lies outside the rectangle when the height is positive.
- Returns
- the bottom-left corner.
◆ BottomRight()
| SIMD_INLINE Point< T > BottomRight |
Returns the bottom-right corner (right, bottom).
Both coordinates are exclusive. Motion::ExpandRoi scales this corner with BottomRight() * 2 + Point(1, 1).
- Returns
- the bottom-right corner.
◆ Width()
| SIMD_INLINE T Width |
Returns the width, right - left.
The width is negative when right < left. CopyFrame requires Width() >= 0. ShiftDetector compares current.Size() with region.Size(), whose x is this width. LBP detection steps across a feature with Width() * column. TestResize builds the UV rectangle as the luma rectangle divided by 2, which divides this width as well.
- Returns
- the width.
◆ Height()
| SIMD_INLINE T Height |
◆ Area()
| SIMD_INLINE T Area |
Returns the area, Width() * Height().
Empty() is true when this product is 0. A negative width and a negative height give a positive area. ShiftDetector rejects a window with Area() < regionAreaMin and divides a pixel difference by region.Area(). Motion drops a region whose Area() is at most areaRegionMinEstimated.
- Returns
- the area. It is 0 for the default rectangle.
◆ Empty()
| SIMD_INLINE bool Empty |
Returns true when Width() * Height() is 0.
The default rectangle is empty. A rectangle with right == left or bottom == top is empty even when the other side is positive. ContourDetector replaces an empty ROI with the whole image. Motion keeps a region only when the tightened box is not empty. Font skips the alpha blit when the glyph intersection is empty. operator |= replaces an empty receiver with the argument and leaves a non-empty receiver unchanged when the argument is empty. operator &= leaves an empty receiver unchanged.
- Returns
- true when the area is 0.
◆ Size()
| SIMD_INLINE Point< T > Size |
Returns the size as Point<T>(Width(), Height()).
x is the width and y is the height. Font::Draw recreates the glyph alpha image with alpha.Recreate(alphaRect.Size()). ShiftDetector requires current.Size() == region.Size().
- Returns
- the size point.
◆ Center()
| SIMD_INLINE Point< T > Center |
Returns the center, rounded to T.
The coordinates are (left + right) / 2 and (top + bottom) / 2, computed in double and then converted to T. Halves round away from zero. For a non-negative one-pixel cell [x, x + 1) x [y, y + 1) the rounded center is (x + 1, y + 1), which Contains does not include. Motion stores region->point = region->rect.Center() and picks the nearest tracked object by SquaredDistance of the two centers. After averaging a trajectory it recenters the box on that point with Shift. TestRandom uses Center() as the middle of a rhombus mask.
- Returns
- the center point.
◆ Contains() [1/4]
| bool Contains | ( | TX | x, |
| TY | y | ||
| ) | const |
Returns true when the pixel (x, y) lies inside the half-open rectangle.
The pixel is inside when x >= left && x < right && y >= top && y < bottom. The coordinates are converted to T before the comparison, so a floating point passed to Rectangle<ptrdiff_t> is rounded first. The right column and the bottom row are outside.
- Parameters
-
[in] x - x-coordinate of the checked point. [in] y - y-coordinate of the checked point.
- Returns
- true when the point is inside.
◆ Contains() [2/4]
| bool Contains | ( | const Point< TP > & | p | ) | const |
Returns true when the point lies inside the half-open rectangle.
This calls Contains(p.x, p.y). Motion::LinkObjects accepts a region when the enlarged region contains the object center or the enlarged object contains the region center.
- Parameters
-
[in] p - a checked point.
- Returns
- true when the point is inside.
◆ Contains() [3/4]
| bool Contains | ( | TL | l, |
| TT | t, | ||
| TR | r, | ||
| TB | b | ||
| ) | const |
Returns true when the half-open rectangle [l, r) x [t, b) lies inside this rectangle.
The four sides are converted to T. The result is true when l >= left && r <= right && t >= top && b <= bottom. The tested right and bottom may touch this rectangle's exclusive edges. A tested rectangle that sticks out by one pixel is outside.
- Parameters
-
[in] l - left side of the checked rectangle. [in] t - top side of the checked rectangle. [in] r - right side of the checked rectangle. [in] b - bottom side of the checked rectangle.
- Returns
- true when the checked rectangle is inside.
◆ Contains() [4/4]
| bool Contains | ( | const Rectangle< TR > & | r | ) | const |
Returns true when the other rectangle lies inside this rectangle.
This calls Contains(r.left, r.top, r.right, r.bottom). SegmentationShrinkRegion requires Rectangle(mask.Size()).Contains(rect) before it searches. TestRandom checks the same condition for a mask rhombus.
- Parameters
-
[in] r - a checked rectangle.
- Returns
- true when the checked rectangle is inside.
◆ Shift() [1/2]
Translates this rectangle by a point.
All four sides move by the same converted offset. The width and the height stay the same. This method writes into this rectangle. Shifted returns a new rectangle. Motion recenters a tracked box with Shift(region.Center() - object.Center()). ShiftDetector moves a clipped window back with Shift(-currentShift). Font moves the alpha box to the origin with Shift(-TopLeft()).
- Parameters
-
[in] shift - a point with the translation. x moves left and right, y moves top and bottom.
- Returns
- a reference to itself.
◆ Shift() [2/2]
| Rectangle< T > & Shift | ( | TX | shiftX, |
| TY | shiftY | ||
| ) |
Translates this rectangle by two offsets.
The offsets are converted to T through Point<T> and then added to every side. A floating offset applied to Rectangle<ptrdiff_t> is rounded. TestShift builds the current view as background.Region(region.Shifted(10, 10)); the Shifted overload uses this translation and leaves the original region in place.
- Parameters
-
[in] shiftX - translation along X. [in] shiftY - translation along Y.
- Returns
- a reference to itself.
◆ Shifted() [1/2]
Returns this rectangle translated by a point.
This rectangle is not modified. ShiftDetector reads background.Region(region.Shifted(shift)) while the correlation window itself stays on the current image. Font places a glyph with current.Shifted(shift + indent).
- Parameters
-
[in] shift - a point with the translation.
- Returns
- the translated rectangle.
◆ Shifted() [2/2]
| Rectangle< T > Shifted | ( | TX | shiftX, |
| TY | shiftY | ||
| ) | const |
Returns this rectangle translated by two offsets.
This rectangle is not modified. The offsets are converted to T before they are added. TestShift passes region.Shifted(ss) to ShiftDetector::Estimate and draws both the original window and the shifted window.
- Parameters
-
[in] shiftX - translation along X. [in] shiftY - translation along Y.
- Returns
- the translated rectangle.
◆ AddBorder()
| Rectangle< T > & AddBorder | ( | TB | border | ) |
Grows or shrinks the rectangle by the same margin on every side.
left and top decrease by the margin. right and bottom increase by the margin. The margin is converted to T. A positive margin makes the rectangle larger. A negative margin shrinks it and can make it empty. Motion::ShrinkRoi calls AddBorder(1) so the mask index found by SegmentationShrinkRegion has a one-pixel neighbourhood. ExpandRoi calls AddBorder(1) on the scaled ROI and AddBorder(-1) on the child image rectangle. Enlarged adds ceil(((Width() + Height()) / 2) * TrackingAdditionalLinking), where the inner division is integer division. ShiftDetector enlarges the 3x3 search window with AddBorder(1). TestShift shrinks the correlation window with AddBorder(-hs / 4).
- Parameters
-
[in] border - a margin added on every side. A negative value shrinks the rectangle.
- Returns
- a reference to itself.
◆ Intersection()
Returns the intersection of this rectangle and another rectangle.
This rectangle is not modified. The other rectangle is converted to T. The result has left = max(left, r.left), top = max(top, r.top), right = max(left, min(right, r.right)) and bottom = max(top, min(bottom, r.bottom)), so its width and height are non-negative. A disjoint pair is empty. Font::Draw skips a glyph when canvas.Intersection(shifted).Empty(). operator &= writes an intersection into this rectangle and treats an empty receiver differently: an empty receiver stays unchanged.
- Parameters
-
[in] r - the other rectangle.
- Returns
- the intersection. It is empty when the rectangles do not overlap.
◆ operator&=() [1/2]
Replaces this rectangle with its intersection with the one-pixel cell of a point.
The point is converted to T. When Contains(p) is true, the rectangle becomes [p.x, p.x + 1) x [p.y, p.y + 1). Otherwise it becomes empty while keeping its previous left and top (right = left and bottom = top). TestCheckCpp intersects two rectangles and then applies this operator to a point inside the result. Clipping to an image uses operator &= with Rectangle(image.Size()), which keeps the overlapping area.
- Parameters
-
[in] p - a point.
- Returns
- a reference to itself.
◆ operator&=() [2/2]
Replaces this rectangle with its intersection with another rectangle.
When this rectangle is empty, it stays unchanged. When the argument is empty, this rectangle becomes a copy of that argument. Otherwise each side is clipped and the result keeps a non-negative width and height. DrawFilledRectangle clips the fill with rect &= Rectangle(canvas.Size()) before the per-pixel loop. ShiftDetector clips a shifted window with region &= Rect(level.current.Size()). Motion clips propagated regions with &= rectChild and clips a tracked object with &= Rect(frameSize). Intersection returns a new rectangle instead of writing into this one.
- Parameters
-
[in] r - the other rectangle.
- Returns
- a reference to itself.
◆ operator|=() [1/2]
Grows this rectangle so that the pixel of the point is inside.
The point is converted to T. An empty rectangle becomes the one-pixel cell [p.x, p.x + 1) x [p.y, p.y + 1). A point already inside does not change the rectangle. A point with p.x >= right sets right to p.x + 1, and a point with p.y >= bottom sets bottom to p.y + 1, because those edges are exclusive. Motion flood-fill writes region->rect |= current for every mask pixel it accepts, starting from Rect().
- Parameters
-
[in] p - a point to include.
- Returns
- a reference to itself.
◆ operator|=() [2/2]
Replaces this rectangle with the bounding union of two rectangles.
An empty receiver becomes a copy of the argument. An empty argument leaves this rectangle unchanged. Otherwise left and top become the minima and right and bottom become the maxima. Font::Draw unions visible glyph cells into alphaRect and canvasRect.
- Parameters
-
[in] r - the other rectangle.
- Returns
- a reference to itself.
◆ operator+=()
Adds the four sides of another rectangle to this rectangle.
left, top, right and bottom each grow by the converted side of the argument. This is a sum of coordinates. The bounding union is operator |=. Motion averages a trajectory by accumulating sum += region.rect and then dividing by the number of positions. Adding to the default rectangle copies the argument when the coordinate types match.
- Parameters
-
[in] r - the rectangle whose sides are added.
- Returns
- a reference to itself.
◆ Overlaps()
| SIMD_INLINE bool Overlaps | ( | const Rectangle< T > & | r | ) | const |
Returns true when the two half-open rectangles have a common point.
For rectangles of non-negative size this is left < r.right && right > r.left && top < r.bottom && bottom > r.top. Edges that only touch do not overlap: right == r.left is outside both interiors. The implementation compares the two horizontal tests with each other and the two vertical tests with each other. Font tests overlap with Intersection and operator &=.
- Parameters
-
[in] r - the other rectangle.
- Returns
- true when the rectangles overlap.