Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rect in c or c++ language

Tags:

c++

Is there a type called rect in C or class Rect in C++ language.

like image 548
boom Avatar asked Mar 06 '26 19:03

boom


2 Answers

No.

These languages generally don't include application-specific APIs and types.

Microsoft's Win32 API includes a type called RECT, and there are probably countless others once you start looking at external API:s.

like image 50
unwind Avatar answered Mar 08 '26 09:03

unwind


Write

template<class T>
struct podrect
{
    T left;
    T top;
    T right;
    T bottom;
};

template<class T>
struct rect
{
    rect() : left(), top(), right(), bottom() {}
    rect(T left, T top, T right, T bottom) : 
        left(left), top(top), right(right), bottom(bottom) {}
    template<class Point>
    rect(Point p, T width, T height) : 
      left(p.x), right(p.y), right(p.x + width), bottom(p.y + height) {}

    T left;
    T top;
    T right;
    T bottom;
};

typedef rect<int> intrect;
typedef rect<float> floatrect;

or something like this. It's very simple.

like image 32
Alexey Malistov Avatar answered Mar 08 '26 07:03

Alexey Malistov