close(this->fd);
}
}
+
+void rectangle::scale(int to_w, int to_h, bool keep_aspect)
+{
+ if (!keep_aspect) {
+ w = to_w;
+ h = to_h;
+ return;
+ }
+
+ int64_t resized_w = int64_t(to_h) * int64_t(w) / int64_t(h);
+
+ if (resized_w <= to_w) {
+ /* use aspect by height */
+ w = resized_w;
+ h = to_h;
+ } else {
+ /* use aspect by width */
+ w = to_h;
+ h = int64_t(to_w) * int64_t(h) / int64_t(w);
+ }
+}
+
+void rectangle::center(int outer_w, int outer_h)
+{
+ x = (outer_w - w) / 2;
+ y = (outer_h - h) / 2;
+}