OpenTTD Source 20260711-master-g3fb3006dff
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
9
10#include "../stdafx.h"
11#include "geometry_func.hpp"
12#include "math_func.hpp"
13#include "../strings_func.h"
14#include "../strings_type.h"
15
16#include "../safeguards.h"
17
30
37Dimension maxdim(const Dimension &d1, const Dimension &d2)
38{
39 Dimension d;
40 d.width = std::max(d1.width, d2.width);
41 d.height = std::max(d1.height, d2.height);
42 return d;
43}
44
51Rect BoundingRect(const Rect &r1, const Rect &r2)
52{
53 /* If either the first or the second is empty, return the other. */
54 if (IsEmptyRect(r1)) return r2;
55 if (IsEmptyRect(r2)) return r1;
56
57 Rect r;
58
59 r.top = std::min(r1.top, r2.top);
60 r.bottom = std::max(r1.bottom, r2.bottom);
61 r.left = std::min(r1.left, r2.left);
62 r.right = std::max(r1.right, r2.right);
63
64 return r;
65}
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.
AlignmentH
Horizontal alignments.
@ ForceRight
Force align to the right.
@ End
Align to the end, LTR/RTL aware.
@ Start
Align to the start, LTR/RTL aware.
@ ForceLeft
Force align to the left.
#define Rect
Macro that prevents name conflicts between included headers.
Integer math functions.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
Types related to strings.
@ TD_RTL
Text is written right-to-left by default.
AlignmentH ResolveRTL() const
Resolve horizontal alignment for the current text direction.
AlignmentH h
Horizontal alignment.
Dimensions (a width and height) of a rectangle in 2D.