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 8 /** @file geometry_type.hpp All geometry types in OpenTTD. */ 9 10 #ifndef GEOMETRY_TYPE_HPP 11 #define GEOMETRY_TYPE_HPP 12 13 #if defined(__APPLE__) 14 /* Mac OS X already has both Rect and Point declared */ 15 # define Rect OTTD_Rect 16 # define Point OTTD_Point 17 #endif /* __APPLE__ */ 18 19 20 /** Coordinates of a point in 2D */ 21 struct Point { 22 int x; 23 int y; 24 }; 25 26 /** Dimensions (a width and height) of a rectangle in 2D */ 27 struct Dimension { 28 uint width; 29 uint height; 30 DimensionDimension31 Dimension(uint w = 0, uint h = 0) : width(w), height(h) {}; 32 operator <Dimension33 bool operator< (const Dimension &other) const 34 { 35 int x = (*this).width - other.width; 36 if (x != 0) return x < 0; 37 return (*this).height < other.height; 38 } 39 operator ==Dimension40 bool operator== (const Dimension &other) const 41 { 42 return (*this).width == other.width && (*this).height == other.height; 43 } 44 }; 45 46 /** Specification of a rectangle with absolute coordinates of all edges */ 47 struct Rect { 48 int left; 49 int top; 50 int right; 51 int bottom; 52 }; 53 54 /** 55 * Specification of a rectangle with an absolute top-left coordinate and a 56 * (relative) width/height 57 */ 58 struct PointDimension { 59 int x; 60 int y; 61 int width; 62 int height; 63 }; 64 65 #endif /* GEOMETRY_TYPE_HPP */ 66