OpenTTD Source: src/core/geometry_func.cpp Source File

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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}
BoundingRect
Rect BoundingRect(const Rect &r1, const Rect &r2)
Compute the bounding rectangle around two rectangles.
Definition geometry_func.cpp:36
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
IsEmptyRect
bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
Definition geometry_func.hpp:22
math_func.hpp
Integer math functions.
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101