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/>.
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"
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
)
25 d
.width
= std::max(d1
.width
, d2
.width
);
26 d
.height
= std::max(d1
.height
, d2
.height
);
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
;
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
);