Louvre  v2.3.2-1
C++ library for Wayland compositors
Public Member Functions | Static Public Member Functions | List of all members
LRegion Class Reference

Collection of non-overlapping rectangles. More...

Public Member Functions

 LRegion () noexcept
 Constructor for creating an empty LRegion. More...
 
 LRegion (const LRect &rect) noexcept
 Initialize the region with a rect. More...
 
 ~LRegion () noexcept
 Destructor for freeing resources associated with LRegion. More...
 
 LRegion (const LRegion &other) noexcept
 Copy constructor. More...
 
 LRegion (LRegion &&other) noexcept
 Move constructor. More...
 
LRegionoperator= (const LRegion &other) noexcept
 Copy assignment operator. More...
 
LRegionoperator= (LRegion &&other) noexcept
 Move assignment operator. More...
 
void clear () noexcept
 Clears the LRegion, deleting all rectangles. More...
 
void addRect (const LRect &rect) noexcept
 Adds a rectangle to the LRegion (union operation). More...
 
void addRect (const LPoint &pos, const LSize &size) noexcept
 Adds a rectangle to the LRegion (union operation). More...
 
void addRect (Int32 x, Int32 y, const LSize &size) noexcept
 Adds a rectangle to the LRegion (union operation). More...
 
void addRect (const LPoint &pos, Int32 w, Int32 h) noexcept
 Adds a rectangle to the LRegion (union operation). More...
 
void addRect (Int32 x, Int32 y, Int32 w, Int32 h) noexcept
 Adds a rectangle to the LRegion (union operation). More...
 
void addRegion (const LRegion &region) noexcept
 Adds the content of another LRegion to this LRegion (union operation). More...
 
void subtractRect (const LRect &rect) noexcept
 Subtracts a rectangle from the LRegion. More...
 
void subtractRect (const LPoint &pos, const LSize &size) noexcept
 Subtracts a rectangle from the LRegion. More...
 
void subtractRect (const LPoint &pos, Int32 w, Int32 h) noexcept
 Subtracts a rectangle from the LRegion. More...
 
void subtractRect (Int32 x, Int32 y, const LSize &size) noexcept
 Subtracts a rectangle from the LRegion. More...
 
void subtractRect (Int32 x, Int32 y, Int32 w, Int32 h) noexcept
 Subtracts a rectangle from the LRegion. More...
 
void subtractRegion (const LRegion &region) noexcept
 Subtracts another LRegion from this LRegion. More...
 
void intersectRegion (const LRegion &region) noexcept
 Intersects this LRegion with another LRegion. More...
 
void multiply (Float32 factor) noexcept
 Multiplies the components of each rectangle in the LRegion by the given factor. More...
 
void multiply (Float32 xFactor, Float32 yFactor) noexcept
 Multiplies the components of each rectangle in the LRegion by the given factor. More...
 
bool containsPoint (const LPoint &point) const noexcept
 Check if the LRegion contains a specific point. More...
 
void offset (const LPoint &offset) noexcept
 Translate each rectangle in the LRegion by the specified offset. More...
 
void offset (Int32 x, Int32 y) noexcept
 Translate each rectangle in the LRegion by the specified offset. More...
 
void inverse (const LRect &rect) noexcept
 Invert the region contained within the specified rectangle. More...
 
bool empty () const noexcept
 Check if the LRegion is empty (contains no rectangles). More...
 
void clip (const LRect &rect) noexcept
 Clips the LRegion to the area defined by the specified rectangle. More...
 
void clip (const LPoint &pos, const LSize &size) noexcept
 Clips the LRegion to the area defined by the specified rectangle. More...
 
void clip (Int32 x, Int32 y, Int32 w, Int32 h) noexcept
 Clips the LRegion to the area defined by the specified rectangle. More...
 
const LBoxextents () const noexcept
 Gets the extents of the LRegion. More...
 
const LBoxboxes (Int32 *n) const noexcept
 Retrieves the list of rectangles that form the LRegion. More...
 
void transform (const LSize &size, LTransform transform) noexcept
 Applies the specified transform to all rectangles within the given size. More...
 
LPointF closestPointFrom (const LPointF &point, Float32 padding=0.f) const noexcept
 Returns the point within the region closest to the given point. More...
 
void simplifyToExtents (Int32 threshold) noexcept
 Replace the rectangles with a single enclosing one if the number is >= threshold. More...
 

Static Public Member Functions

static const LRegionEmptyRegion () noexcept
 Const reference to an empty region. More...
 

Detailed Description

Collection of non-overlapping rectangles.

The LRegion class provides an efficient mechanism for creating sets of rectangles that do not overlap in their geometries. It offers methods for performing operations such as additions, subtractions, intersections, and more on rectangles. This class is extensively used by the library for tasks like calculating surface damage, defining opaque, translucent, and input regions, among others. Internally, LRegion employs the algorithm and functions from the Pixman library.

Constructor & Destructor Documentation

◆ LRegion() [1/4]

LRegion ( )
inlinenoexcept

Constructor for creating an empty LRegion.

◆ LRegion() [2/4]

LRegion ( const LRect rect)
inlinenoexcept

Initialize the region with a rect.

◆ ~LRegion()

~LRegion ( )
inlinenoexcept

Destructor for freeing resources associated with LRegion.

◆ LRegion() [3/4]

LRegion ( const LRegion other)
inlinenoexcept

Copy constructor.

Parameters
otherThe LRegion to copy from.

◆ LRegion() [4/4]

LRegion ( LRegion &&  other)
inlinenoexcept

Move constructor.

Constructs an LRegion by moving the contents from another LRegion, leaving the source LRegion empty.
The source LRegion remains valid and can be used afterwards.

Parameters
otherThe LRegion to move from.

Member Function Documentation

◆ operator=() [1/2]

LRegion& operator= ( const LRegion other)
inlinenoexcept

Copy assignment operator.

Parameters
otherThe LRegion to assign from.
Returns
A reference to the modified LRegion.

◆ operator=() [2/2]

LRegion& operator= ( LRegion &&  other)
inlinenoexcept

Move assignment operator.

Assigns the contents of another LRegion to this LRegion by moving, leaving the source LRegion empty.
The source LRegion remains valid and can be used afterwards.

Parameters
otherThe LRegion to move from.
Returns
A reference to this LRegion after the move.

◆ clear()

void clear ( )
inlinenoexcept

Clears the LRegion, deleting all rectangles.

◆ addRect() [1/5]

void addRect ( const LRect rect)
inlinenoexcept

Adds a rectangle to the LRegion (union operation).

Parameters
rectThe rectangle to add.

◆ addRect() [2/5]

void addRect ( const LPoint pos,
const LSize size 
)
inlinenoexcept

Adds a rectangle to the LRegion (union operation).

Parameters
posThe rectangle's top-left corner.
sizeThe rectangle's size.

◆ addRect() [3/5]

void addRect ( Int32  x,
Int32  y,
const LSize size 
)
inlinenoexcept

Adds a rectangle to the LRegion (union operation).

Parameters
xThe x-coordinate of the rectangle's top-left corner.
yThe y-coordinate of the rectangle's top-left corner.
sizeThe rectangle's size.

◆ addRect() [4/5]

void addRect ( const LPoint pos,
Int32  w,
Int32  h 
)
inlinenoexcept

Adds a rectangle to the LRegion (union operation).

Parameters
posThe rectangle's top-left corner.
wThe width of the rectangle.
hThe height of the rectangle.

◆ addRect() [5/5]

void addRect ( Int32  x,
Int32  y,
Int32  w,
Int32  h 
)
inlinenoexcept

Adds a rectangle to the LRegion (union operation).

Parameters
xThe x-coordinate of the rectangle's top-left corner.
yThe y-coordinate of the rectangle's top-left corner.
wThe width of the rectangle.
hThe height of the rectangle.

◆ addRegion()

void addRegion ( const LRegion region)
inlinenoexcept

Adds the content of another LRegion to this LRegion (union operation).

Parameters
regionThe LRegion to add.

◆ subtractRect() [1/5]

void subtractRect ( const LRect rect)
inlinenoexcept

Subtracts a rectangle from the LRegion.

Parameters
rectThe rectangle to subtract.

◆ subtractRect() [2/5]

void subtractRect ( const LPoint pos,
const LSize size 
)
inlinenoexcept

Subtracts a rectangle from the LRegion.

Parameters
posThe rectangle's top-left corner.
sizeThe rectangle's size.

◆ subtractRect() [3/5]

void subtractRect ( const LPoint pos,
Int32  w,
Int32  h 
)
inlinenoexcept

Subtracts a rectangle from the LRegion.

Parameters
posThe rectangle's top-left corner.
wThe width of the rectangle.
hThe height of the rectangle.

◆ subtractRect() [4/5]

void subtractRect ( Int32  x,
Int32  y,
const LSize size 
)
inlinenoexcept

Subtracts a rectangle from the LRegion.

Parameters
xThe x-coordinate of the rectangle's top-left corner.
yThe y-coordinate of the rectangle's top-left corner.
sizeThe rectangle's size.

◆ subtractRect() [5/5]

void subtractRect ( Int32  x,
Int32  y,
Int32  w,
Int32  h 
)
inlinenoexcept

Subtracts a rectangle from the LRegion.

Parameters
xThe x-coordinate of the rectangle's top-left corner.
yThe y-coordinate of the rectangle's top-left corner.
wThe width of the rectangle.
hThe height of the rectangle.

◆ subtractRegion()

void subtractRegion ( const LRegion region)
inlinenoexcept

Subtracts another LRegion from this LRegion.

Parameters
regionThe LRegion to subtract.

◆ intersectRegion()

void intersectRegion ( const LRegion region)
inlinenoexcept

Intersects this LRegion with another LRegion.

Parameters
regionThe LRegion to intersect with.

◆ multiply() [1/2]

void multiply ( Float32  factor)
noexcept

Multiplies the components of each rectangle in the LRegion by the given factor.

Parameters
factorThe factor to multiply by.

◆ multiply() [2/2]

void multiply ( Float32  xFactor,
Float32  yFactor 
)
noexcept

Multiplies the components of each rectangle in the LRegion by the given factor.

Parameters
xFactorThe x-axis factor to multiply by.
yFactorThe y-axis factor to multiply by.

◆ containsPoint()

bool containsPoint ( const LPoint point) const
inlinenoexcept

Check if the LRegion contains a specific point.

Parameters
pointThe point to check.
Returns
true if the region contains the point, false otherwise.

◆ offset() [1/2]

void offset ( const LPoint offset)
inlinenoexcept

Translate each rectangle in the LRegion by the specified offset.

Parameters
offsetThe offset to apply.

◆ offset() [2/2]

void offset ( Int32  x,
Int32  y 
)
inlinenoexcept

Translate each rectangle in the LRegion by the specified offset.

Parameters
xThe x offset to apply.
yThe y offset to apply.

◆ inverse()

void inverse ( const LRect rect)
inlinenoexcept

Invert the region contained within the specified rectangle.

Parameters
rectThe rectangle to define the area of inversion.

◆ empty()

bool empty ( ) const
inlinenoexcept

Check if the LRegion is empty (contains no rectangles).

Returns
true if the region is empty, false otherwise.

◆ clip() [1/3]

void clip ( const LRect rect)
inlinenoexcept

Clips the LRegion to the area defined by the specified rectangle.

Parameters
rectThe rectangle used for clipping.

◆ clip() [2/3]

void clip ( const LPoint pos,
const LSize size 
)
inlinenoexcept

Clips the LRegion to the area defined by the specified rectangle.

◆ clip() [3/3]

void clip ( Int32  x,
Int32  y,
Int32  w,
Int32  h 
)
inlinenoexcept

Clips the LRegion to the area defined by the specified rectangle.

◆ extents()

const LBox& extents ( ) const
inlinenoexcept

Gets the extents of the LRegion.

This method returns a pointer to an LBox that represents the bounding box of the LRegion. The LBox contains the minimum and maximum coordinates that enclose the LRegion.

Returns
A pointer to the extents of the LRegion as an LBox.

◆ boxes()

const LBox* boxes ( Int32 n) const
inlinenoexcept

Retrieves the list of rectangles that form the LRegion.

Parameters
nA pointer to an integer that will be set to the number of rectangles.
Returns
A pointer to an array of LBox objects representing the rectangles.
Note
This variant allows you to access the rectangles using the native Pixman method, which is considerably faster.

◆ transform()

void transform ( const LSize size,
LTransform  transform 
)
noexcept

Applies the specified transform to all rectangles within the given size.

This function clips the rectangles within the specified size and applies the specified transform.

Parameters
sizeThe size used for clipping and transformation.
transformThe transform to be applied to the rectangles.

◆ closestPointFrom()

LPointF closestPointFrom ( const LPointF point,
Float32  padding = 0.f 
) const
noexcept

Returns the point within the region closest to the given point.

If the point is inside the region or the region is empty, the same point is returned.

Parameters
pointThe point to find the closest point within the region.
paddingOptional padding applied to each of the region boxes.

◆ simplifyToExtents()

void simplifyToExtents ( Int32  threshold)
inlinenoexcept

Replace the rectangles with a single enclosing one if the number is >= threshold.

Parameters
thresholdThe threshold value. If the number of rectangles is greater than or equal to this value, the rectangles will be simplified to a single enclosing rectangle.

◆ EmptyRegion()

static const LRegion& EmptyRegion ( )
inlinestaticnoexcept

Const reference to an empty region.