9 template <class T = IPDF::Real>
13 //TRect() = default; // Needed so we can fread/fwrite this struct
14 TRect(T _x=0, T _y=0, T _w=1, T _h=1) : x(_x), y(_y), w(_w), h(_h) {}
15 template <class B> TRect(const TRect<B> & cpy) : x(T(cpy.x)), y(T(cpy.y)), w(T(cpy.w)), h(T(cpy.h)) {}
17 std::string Str() const
20 // float conversion needed because it is fucking impossible to get ostreams working with template classes
21 s << "{" << x << ", " << y << ", " << (x + w) << ", " << (y + h) << " (w: " << w <<", h: " << h <<")}";
24 inline bool PointIn(T pt_x, T pt_y) const
26 if (pt_x <= x) return false;
27 if (pt_y <= y) return false;
28 if (pt_x >= x + w) return false;
29 if (pt_y >= y + h) return false;
33 inline bool Intersects(const TRect& other) const
35 if (x + w < other.x) return false;
36 if (y + h < other.y) return false;
37 if (x > other.x + other.w) return false;
38 if (y > other.y + other.h) return false;
42 template <class B> TRect<B> Convert() const {return TRect<B>(B(x), B(y), B(w), B(h));}
44 template <class B> TRect<T> & operator=(const TRect<B> & equ)
56 template <class T = IPDF::Real>
57 inline TRect<T> TransformRectCoordinates(const TRect<T> & view, const TRect<T> & r)
60 T w = (view.w == T(0))?T(1):view.w;
61 T h = (view.h == T(0))?T(1):view.h;
62 out.x = (r.x - view.x) / w; //r.x = out.x *w + view.x
63 out.y = (r.y - view.y) / h; // r.y = out.y*h + view.y
64 out.w = r.w / w; // r.w = out.w * w
65 out.h = r.h / h; // r.h = out.h * h
70 template <class T = IPDF::Real>
71 inline Vec2 TransformPointCoordinates(const TRect<T> & view, const Vec2& v)
74 out.x = (v.x - view.x) / view.w;
75 out.y = (v.y - view.y) / view.h;
79 typedef TRect<Real> Rect;