Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::Extend2D Struct Reference

Axis-aligned rectangle defined by an anchor point and size. More...

#include <spk_extend_2d.hpp>

Collaboration diagram for spk::Extend2D:
Collaboration graph

Public Types

using Anchor = spk::Vector2Int
 Position of the rectangle, expressed as its top-left corner.
using Size = spk::Vector2UInt
 Width and height of the rectangle.

Public Member Functions

 Extend2D ()
 Builds a zero-sized rectangle at the origin.
 Extend2D (const Vector2Int &p_anchor, const Vector2UInt &p_size)
 Builds a rectangle from anchor and size vectors.
 Extend2D (const Vector2Int &p_anchor, size_t p_width, size_t p_height)
 Builds a rectangle from anchor and explicit dimensions.
 Extend2D (int p_x, int p_y, const Vector2UInt &p_size)
 Builds a rectangle from coordinates and size vector.
 Extend2D (int p_x, int p_y, size_t p_width, size_t p_height)
 Builds a rectangle from coordinates and explicit dimensions.
Extend2D atOrigin () const
 Returns a copy translated to the origin.
bool contains (const Vector2Int &p_point) const
 Tests whether a point lies within the rectangle bounds.
Extend2D shrink (const Vector2Int &p_offset) const
 Returns a rectangle shrunk by the provided offset on each side.
Extend2D intersect (const Extend2D &p_other) const
 Computes the intersection of two rectangles.
Extend2D operator+ (const Extend2D &p_other) const
 Translates the rectangle by another rectangle's anchor.
Extend2D operator- (const Extend2D &p_other) const
 Translates the rectangle negatively by another rectangle's anchor.
Extend2Doperator+= (const Extend2D &p_other)
 In-place translation by another rectangle's anchor.
Extend2Doperator-= (const Extend2D &p_other)
 In-place negative translation by another rectangle's anchor.
std::string toString () const
 Converts the rectangle to a readable string.
std::wstring toWstring () const
 Converts the rectangle to a wide string.
bool operator== (const Extend2D &p_other) const
 Equality comparison between rectangles.
bool operator!= (const Extend2D &p_other) const
 Inequality comparison between rectangles.

Public Attributes

union { 
   Anchor   anchor 
   struct { 
      Anchor::value_type   x 
      Anchor::value_type   y 
   } 
}; 
union { 
   Size   size 
   struct { 
      Size::value_type   width 
      Size::value_type   height 
   } 
}; 

Friends

std::ostream & operator<< (std::ostream &p_stream, const Extend2D &p_extend)
 Streams a rectangle to an output stream.
std::wostream & operator<< (std::wostream &p_stream, const Extend2D &p_extend)
 Streams a rectangle to a wide output stream.

Detailed Description

Axis-aligned rectangle defined by an anchor point and size.

See also
spk::Vector2Int, spk::Vector2UInt
spk::Extend2D area{{0, 0}, {640, 480}};
if (area.contains({100, 120}))
{
// point is inside the rectangle
}
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24
bool contains(const Vector2Int &p_point) const
Tests whether a point lies within the rectangle bounds.
Definition spk_extend_2d.cpp:43

Constructor & Destructor Documentation

◆ Extend2D() [1/4]

spk::Extend2D::Extend2D ( const Vector2Int & p_anchor,
const Vector2UInt & p_size )

Builds a rectangle from anchor and size vectors.

Parameters
p_anchorTop-left position.
p_sizeWidth and height.

◆ Extend2D() [2/4]

spk::Extend2D::Extend2D ( const Vector2Int & p_anchor,
size_t p_width,
size_t p_height )

Builds a rectangle from anchor and explicit dimensions.

Parameters
p_anchorTop-left position.
p_widthRectangle width.
p_heightRectangle height.

◆ Extend2D() [3/4]

spk::Extend2D::Extend2D ( int p_x,
int p_y,
const Vector2UInt & p_size )

Builds a rectangle from coordinates and size vector.

Parameters
p_xAnchor x coordinate.
p_yAnchor y coordinate.
p_sizeWidth and height.

◆ Extend2D() [4/4]

spk::Extend2D::Extend2D ( int p_x,
int p_y,
size_t p_width,
size_t p_height )

Builds a rectangle from coordinates and explicit dimensions.

Parameters
p_xAnchor x coordinate.
p_yAnchor y coordinate.
p_widthRectangle width.
p_heightRectangle height.

Member Function Documentation

◆ atOrigin()

Extend2D spk::Extend2D::atOrigin ( ) const

Returns a copy translated to the origin.

Returns
Rectangle anchored at (0,0).
Here is the call graph for this function:

◆ contains()

bool spk::Extend2D::contains ( const Vector2Int & p_point) const

Tests whether a point lies within the rectangle bounds.

Parameters
p_pointPoint to test.
Returns
true when the point is inside or on the edges.
Here is the caller graph for this function:

◆ intersect()

Extend2D spk::Extend2D::intersect ( const Extend2D & p_other) const

Computes the intersection of two rectangles.

Parameters
p_otherRectangle to intersect with.
Returns
Overlapping rectangle (may be empty).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=()

bool spk::Extend2D::operator!= ( const Extend2D & p_other) const

Inequality comparison between rectangles.

Parameters
p_otherRectangle to compare.
Returns
true when anchor or size differ.
Here is the call graph for this function:

◆ operator+()

Extend2D spk::Extend2D::operator+ ( const Extend2D & p_other) const

Translates the rectangle by another rectangle's anchor.

Parameters
p_otherRectangle providing offset and size delta.
Returns
Translated rectangle.
Here is the call graph for this function:

◆ operator+=()

Extend2D & spk::Extend2D::operator+= ( const Extend2D & p_other)

In-place translation by another rectangle's anchor.

Parameters
p_otherRectangle providing offset and size delta.
Returns
Reference to this rectangle.
Here is the call graph for this function:

◆ operator-()

Extend2D spk::Extend2D::operator- ( const Extend2D & p_other) const

Translates the rectangle negatively by another rectangle's anchor.

Parameters
p_otherRectangle providing offset and size delta.
Returns
Translated rectangle.
Here is the call graph for this function:

◆ operator-=()

Extend2D & spk::Extend2D::operator-= ( const Extend2D & p_other)

In-place negative translation by another rectangle's anchor.

Parameters
p_otherRectangle providing offset and size delta.
Returns
Reference to this rectangle.
Here is the call graph for this function:

◆ operator==()

bool spk::Extend2D::operator== ( const Extend2D & p_other) const

Equality comparison between rectangles.

Parameters
p_otherRectangle to compare.
Returns
true when anchor and size match.
Here is the call graph for this function:

◆ shrink()

Extend2D spk::Extend2D::shrink ( const Vector2Int & p_offset) const

Returns a rectangle shrunk by the provided offset on each side.

Parameters
p_offsetOffset to subtract from anchor and size.
Returns
Shrunk rectangle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string spk::Extend2D::toString ( ) const

Converts the rectangle to a readable string.

Returns
UTF-8 string representation.

◆ toWstring()

std::wstring spk::Extend2D::toWstring ( ) const

Converts the rectangle to a wide string.

Returns
UTF-16/32 string representation.

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & p_stream,
const Extend2D & p_extend )
friend

Streams a rectangle to an output stream.

Parameters
p_streamOutput stream.
p_extendRectangle to print.
Returns
Reference to the stream.

◆ operator<< [2/2]

std::wostream & operator<< ( std::wostream & p_stream,
const Extend2D & p_extend )
friend

Streams a rectangle to a wide output stream.

Parameters
p_streamOutput stream.
p_extendRectangle to print.
Returns
Reference to the stream.

The documentation for this struct was generated from the following files:
  • includes/structure/graphics/spk_extend_2d.hpp
  • srcs/structure/graphics/spk_extend_2d.cpp