RavEngine
Loading...
Searching...
No Matches
rect.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_MATHS_RECT_H_
29#define OZZ_OZZ_BASE_MATHS_RECT_H_
30
31#include "../platform.h"
32
33namespace ozz {
34namespace math {
35
36// Defines a rectangle by the integer coordinates of its lower-left and
37// width-height.
38struct OZZ_BASE_DLL RectInt {
39 // Constructs a uninitialized rectangle.
40 RectInt() {}
41
42 // Constructs a rectangle with the specified arguments.
43 RectInt(int _left, int _bottom, int _width, int _height)
44 : left(_left), bottom(_bottom), width(_width), height(_height) {}
45
46 // Tests whether _x and _y coordinates are within rectangle bounds.
47 bool is_inside(int _x, int _y) const {
48 return _x >= left && _x < left + width && _y >= bottom &&
49 _y < bottom + height;
50 }
51
52 // Gets the rectangle x coordinate of the right rectangle side.
53 int right() const { return left + width; }
54
55 // Gets the rectangle y coordinate of the top rectangle side.
56 int top() const { return bottom + height; }
57
58 // Specifies the x-coordinate of the lower side.
59 int left;
60 // Specifies the x-coordinate of the left side.
61 int bottom;
62 // Specifies the width of the rectangle.
63 int width;
64 // Specifies the height of the rectangle..
65 int height;
66};
67
68// Defines a rectangle by the floating point coordinates of its lower-left
69// and width-height.
70struct OZZ_BASE_DLL RectFloat {
71 // Constructs a uninitialized rectangle.
72 RectFloat() {}
73
74 // Constructs a rectangle with the specified arguments.
75 RectFloat(float _left, float _bottom, float _width, float _height)
76 : left(_left), bottom(_bottom), width(_width), height(_height) {}
77
78 // Tests whether _x and _y coordinates are within rectangle bounds
79 bool is_inside(float _x, float _y) const {
80 return _x >= left && _x < left + width && _y >= bottom &&
81 _y < bottom + height;
82 }
83
84 // Gets the rectangle x coordinate of the right rectangle side.
85 float right() const { return left + width; }
86
87 // Gets the rectangle y coordinate of the top rectangle side.
88 float top() const { return bottom + height; }
89
90 // Specifies the x-coordinate of the lower side.
91 float left;
92 // Specifies the x-coordinate of the left side.
93 float bottom;
94 // Specifies the width of the rectangle.
95 float width;
96 // Specifies the height of the rectangle.
97 float height;
98};
99} // namespace math
100} // namespace ozz
101#endif // OZZ_OZZ_BASE_MATHS_RECT_H_
Definition rect.h:70
Definition rect.h:38