Rectangles
PBSize
Structure: A 2D size with integer dimensions.
Fields
width (int32_t
): The horizontal dimension
height (int32_t
): The vertical dimension.
PBRectangle
Structure: A 2D rectangle with 32-bit integer coordinates.
Fields
l (int32_t
): The horizontal coordinate giving the left side of the rectangle.
r (int32_t
): The horizontal coordinate giving the right side of the rectangle. When working with pixels, note that the coordinate of a pixel denotes its top-left corner; thus, for a pixel to be inside this rectangle, its x-coordinate must be at least l and strictly less than r.
t (int32_t
): The vertical coordinate giving the top side of the rectangle.
b (int32_t
): The vertical coordinate giving the bottom side of the rectangle. When working with pixels, note that the coordinate of a pixel denotes its top-left corner; thus, for a pixel to be inside this rectangle, its y-coordinate must be at least t and strictly less than b.
PBRectangle64
Structure: A 2D rectangle with 64-bit integer coordinates.
Fields
l (int64_t
): See PBRectangle for a description.
r (int64_t
): See PBRectangle for a description.
t (int64_t
): See PBRectangle for a description.
b (int64_t
): See PBRectangle for a description.
PBRectangleMake
Function: Populate a PBRectangle structure.
Syntax (C/C++)
PBRectangle PBRectangleMake(int32_t l, int32_t r, int32_t t, int32_t b);
Syntax (Python)
RectangleMake(l, r, t, b) -> (result)
Parameters and Return Values
[in] l (int32_t
): The horizontal coordinate of the left side.
[in] r (int32_t
): The horizontal coordinate of the right side.
[in] t (int32_t
): The vertical coordinate of the top side.
[in] b (int32_t
): The vertical coordinate of the bottom side.
[out] result (PBRectangle): The populated structure.
Discussion
This is equivalent to manually setting all the fields of the structure.
See Also
PBRectangleIntersection
Function: Calculate the intersection of two rectangles.
Syntax (C/C++)
PBRectangle PBRectangleIntersection(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleIntersection(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): One of the rectangles.
[in] b (PBRectangle): The other rectangle.
[out] result (PBRectangle): The intersection of the input rectangles. If the rectangles do not intersect, then an invalid rectangle (as determined by PBRectangleValid) is returned.
Discussion
The returned left and top coordinate is the maximum of the input left coordinates and input top coordinates respectively. The returned right and bottom coordinate is the minimum of the input right coordinates and input bottom coordinates respectively.
See Also
PBRectangleBounding
Function: Calculate the smallest rectangle that contains two other rectangles.
Syntax (C/C++)
PBRectangle PBRectangleBounding(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleBounding(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): One of the rectangles.
[in] b (PBRectangle): The other rectangle.
[out] result (PBRectangle): The smallest rectangle that contains (see PBRectangleContains for a definition) both of the input rectangles.
Discussion
The returned left and top coordinate is the minimum of the input left coordinates and input top coordinates respectively. The returned right and bottom coordinate is the maximum of the input right coordinates and input bottom coordinates respectively.
See Also
PBRectangleTranslate
Function: Move a rectangle by a given offset.
Syntax (C/C++)
PBRectangle PBRectangleTranslate(PBRectangle a, int32_t x, int32_t y);
Syntax (Python)
RectangleTranslate(a, x, y) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle to move.
[in] x (int32_t
): The value to add to the left and right coordinates.
[in] y (int32_t
): The value to add to the top and bottom coordinates.
[out] result (PBRectangle): The moved rectangle.
See Also
PBRectangleTranslateByTopLeft
Function: Move a rectangle by the offset of another's top-left vertex.
Syntax (C/C++)
PBRectangle PBRectangleTranslateByTopLeft(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleTranslateByTopLeft(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle to move.
[in] b (PBRectangle): The rectangle giving the top-left vertex. Its right and bottom sides are ignored.
[out] result (PBRectangle): The moved rectangle.
Discussion
This is equivalent to calling PBRectangleTranslate with the left and top coordinates of the second rectangle as the x and y parameters respectively. It performs the inverse operation to PBRectangleTranslateByTopLeftInverse.
See Also
PBRectangleTranslateByTopLeftInverse
Function: Move a rectangle by the negated offset of another's top-left vertex.
Syntax (C/C++)
PBRectangle PBRectangleTranslateByTopLeftInverse(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleTranslateByTopLeftInverse(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle to move.
[in] b (PBRectangle): The rectangle giving the top-left vertex. Its right and bottom sides are ignored.
[out] result (PBRectangle): The moved rectangle.
Discussion
This is equivalent to calling PBRectangleTranslate with the negation of the left and top coordinates of the second rectangle as the x and y parameters respectively. It performs the inverse operation to PBRectangleTranslateByTopLeft.
See Also
PBRectangleValid
Function: Check a rectangle is well-formed.
Syntax (C/C++)
bool PBRectangleValid(PBRectangle a);
Syntax (Python)
RectangleValid(a) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle.
[out] result (bool
): True if the left coordinate is strictly less than the right, and the top is strictly less than the bottom.
Discussion
This is equivalent to checking the width and height are both positive (but avoids the potential numeric overflow).
See Also
PBRectangleEquals
Function: Test if two rectangles are exactly the same.
Syntax (C/C++)
bool PBRectangleEquals(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleEquals(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): One of the rectangles.
[in] b (PBRectangle): The other rectangle.
[out] result (bool
): True if all coordinates are equal; otherwise false.
See Also
PBRectangleContains
Function: Test if a rectangle contains a unit square.
Syntax (C/C++)
bool PBRectangleContains(PBRectangle a, int32_t x, int32_t y);
Syntax (Python)
RectangleContains(a, x, y) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle.
[in] x (int32_t
): The x-coordinate of the left side of the unit square.
[in] y (int32_t
): The y-coordinate of the top side of the unit square.
[out] result (bool
): True if the unit square is fully inside the rectangle.
Discussion
This is equivalent to checking x is greater than or equal to the left side of the rectangle but strictly less than the right side; and that y is greater than or equal to the top and strictly less than the bottom.
See Also
PBRectangleAdd
Function: Add the four coordinates of two rectangles together separately.
Syntax (C/C++)
PBRectangle PBRectangleAdd(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleAdd(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): One of the rectangles.
[in] b (PBRectangle): The other rectangle.
[out] result (PBRectangle): The summation.
Discussion
The left coordinates are added; the right coordinates are added; the top coordinates are added; and the bottom coordinates are added.
See Also
PBRectangleSubtract
Function: Subtract the four coordinates of two rectangles together separately.
Syntax (C/C++)
PBRectangle PBRectangleSubtract(PBRectangle a, PBRectangle b);
Syntax (Python)
RectangleSubtract(a, b) -> (result)
Parameters and Return Values
[in] a (PBRectangle): The rectangle from which to subtract.
[in] b (PBRectangle): The amount to subtract.
[out] result (PBRectangle): The subtraction.
Discussion
The left coordinates are subtracted; the right coordinates are subtracted; the top coordinates are subtracted; and the bottom coordinates are subtracted.