Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / core / geometry_func.cpp
blobdccef72ecc5883f853fde33f61bd98ae62e08ec5
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file geometry_func.cpp Geometry functions. */
10 #include "../stdafx.h"
11 #include "geometry_func.hpp"
12 #include "math_func.hpp"
14 #include "../safeguards.h"
16 /**
17 * Compute bounding box of both dimensions.
18 * @param d1 First dimension.
19 * @param d2 Second dimension.
20 * @return The bounding box of both dimensions, the smallest dimension that surrounds both arguments.
22 Dimension maxdim(const Dimension &d1, const Dimension &d2)
24 Dimension d;
25 d.width = std::max(d1.width, d2.width);
26 d.height = std::max(d1.height, d2.height);
27 return d;
30 /**
31 * Compute the bounding rectangle around two rectangles.
32 * @param r1 First rectangle.
33 * @param r2 Second rectangle.
34 * @return The bounding rectangle, the smallest rectangle that contains both arguments.
36 Rect BoundingRect(const Rect &r1, const Rect &r2)
38 /* If either the first or the second is empty, return the other. */
39 if (IsEmptyRect(r1)) return r2;
40 if (IsEmptyRect(r2)) return r1;
42 Rect r;
44 r.top = std::min(r1.top, r2.top);
45 r.bottom = std::max(r1.bottom, r2.bottom);
46 r.left = std::min(r1.left, r2.left);
47 r.right = std::max(r1.right, r2.right);
49 return r;