11 Real x; Real y; Real w; Real h;
12 //Rect() = default; // Needed so we can fread/fwrite this struct
13 Rect(Real _x=0, Real _y=0, Real _w=1, Real _h=1) : x(_x), y(_y), w(_w), h(_h) {}
14 std::string Str() const
17 // float conversion needed because it is fucking impossible to get ostreams working with template classes
18 s << "{" << Float(x) << ", " << Float(y) << ", " << Float(x + w) << ", " << Float(y + h) << " (w: " << Float(w) <<", h: " << Float(h) <<")}";
21 inline bool PointIn(Real pt_x, Real pt_y) const
23 if (pt_x <= x) return false;
24 if (pt_y <= y) return false;
25 if (pt_x >= x + w) return false;
26 if (pt_y >= y + h) return false;
30 inline bool Intersects(const Rect& other) const
32 if (x + w < other.x) return false;
33 if (y + h < other.y) return false;
34 if (x > other.x + other.w) return false;
35 if (y > other.y + other.h) return false;
40 inline Rect TransformRectCoordinates(const Rect& view, const Rect& r)
43 Real w = (view.w == Real(0))?Real(1):view.w;
44 Real h = (view.h == Real(0))?Real(1):view.h;
45 out.x = (r.x - view.x) / w;
46 out.y = (r.y - view.y) / h;
52 inline Vec2 TransformPointCoordinates(const Rect& view, const Vec2& v)
55 out.x = (v.x - view.x) / view.w;
56 out.y = (v.y - view.y) / view.h;