OpenTTD Source  20241120-master-g6d3adc6169
geometry_func.cpp
Go to the documentation of this file.
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  */
7 
10 #include "../stdafx.h"
11 #include "geometry_func.hpp"
12 #include "math_func.hpp"
13 
14 #include "../safeguards.h"
15 
22 Dimension maxdim(const Dimension &d1, const Dimension &d2)
23 {
24  Dimension d;
25  d.width = std::max(d1.width, d2.width);
26  d.height = std::max(d1.height, d2.height);
27  return d;
28 }
29 
36 Rect BoundingRect(const Rect &r1, const Rect &r2)
37 {
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;
41 
42  Rect r;
43 
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);
48 
49  return r;
50 }
Rect BoundingRect(const Rect &r1, const Rect &r2)
Compute the bounding rectangle around two rectangles.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
Integer math functions.
Dimensions (a width and height) of a rectangle in 2D.
Specification of a rectangle with absolute coordinates of all edges.