#include "KRect.hpp" ➔ struct KRect

KRect

A struct that represents a rectangle.

struct KRect<> {
    int x, y;
    int w, h;
};

Template

class KRect <type1, type2> {
    type1 x, y;
    type2 w, h;
}

Template arguments lets customize the type of the position and dimension variables.

Constructor

KRect<>(int x, int y, int w, int h);

Set all its attributes.

Member

int x, y;
int w, h;

x and y store the position (top left corner).
w and h store the dimension (width and height).

Method

bool is_on(KRect<> rect);

Test whether two rectangles are overlapping each other or not.

Operator

std::ostream& operator<<(std::ostream& ostream, KRect<> rect);
std::istream& operator>>(std::istream& istream, KRect<> rect);

Provide conversion to iostream.

Example

KRect<> rect1(10, 10, 40, 20);
KRect<float, int> rect2(16.26, 10.5, 10, 40);

std::cout << rect1 << ", " << rect2 << std::endl;