Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
geometry.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 XITRIX
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <string>
20
21namespace aurore
22{
23
24// A structure that contains a point in a two-dimensional coordinate system.
25struct Point
26{
27 float x; // The x-coordinate of the point.
28 float y; // The y-coordinate of the point.
29
30 // Creates a point with location (0,0).
32
33 // Creates a point with coordinates specified as float values.
34 Point(float x, float y);
35
36 Point operator+(const Point& a) const;
37 Point operator-(const Point& a) const;
38 Point operator/(const float& a) const;
39 Point operator*(const float& a) const;
40 bool operator==(const Point& other) const;
41 bool operator!=(const Point& other) const;
42 void operator+=(const Point& a);
43 void operator-=(const Point& a);
44
45 Point lerp(const Point& other, const float& percent) const;
46};
47
48// A structure that contains width and height values.
49struct Size
50{
51 float width; // A width value.
52 float height; // A height value.
53
54 // Creates a size with zero width and height.
56
57 // Creates a size with dimensions specified as float values.
58 Size(float width, float height);
59
60 Size operator+(const Size& a) const;
61 Size operator-(const Size& a) const;
62 Size operator/(const float& a) const;
63 Size operator*(const float& a) const;
64 bool operator==(const Size& other) const;
65};
66
67// Rect
68// A structure that contains the location and dimensions of a rectangle.
69struct Rect
70{
71 Point origin; // A point that specifies the coordinates of the rectangle’s origin.
72 Size size; // A size that specifies the height and width of the rectangle.
73
74 // Creates a rectangle with origin (0,0) and size (0,0).
76
77 // Creates a rectangle with the specified origin and size.
79
80 // Creates a rectangle with coordinates and dimensions specified as float values.
81 Rect(float x, float y, float width, float height);
82
83 // Returns the width of a rectangle.
84 float getWidth() const;
85 // Returns the height of a rectangle.
86 float getHeight() const;
87
88 // Returns the smallest value for the x-coordinate of the rectangle.
89 float getMinX() const;
90 // Returns the smallest value for the y-coordinate of the rectangle.
91 float getMinY() const;
92
93 // Returns the x-coordinate that establishes the center of a rectangle.
94 float getMidX() const;
95 // Returns the y-coordinate that establishes the center of the rectangle.
96 float getMidY() const;
97
98 // Returns the largest value of the x-coordinate for the rectangle.
99 float getMaxX() const;
100 // Returns the largest value for the y-coordinate of the rectangle.
101 float getMaxY() const;
102
103 bool operator==(const Rect& other) const;
104
105 // Returns true if point is inside this Rect.
106 bool pointInside(Point point);
107
108 // Returns string with description of current Rect.
109 std::string describe();
110
111 // Returns true if two rects have shared area.
112 bool collideWith(const Rect& other) const;
113
114 // Returns true if this rect inscribed in other.
115 bool inscribed(const Rect& other) const;
116
117 // Returns Rect with offset by presented Point.
118 Rect offsetBy(const Point& origin) const;
119};
120
121} // namespace aurore
Definition actions.hpp:25
Definition geometry.hpp:26
Point lerp(const Point &other, const float &percent) const
float x
Definition geometry.hpp:27
bool operator!=(const Point &other) const
float y
Definition geometry.hpp:28
Point operator/(const float &a) const
Point operator-(const Point &a) const
Point operator*(const float &a) const
void operator-=(const Point &a)
bool operator==(const Point &other) const
Point operator+(const Point &a) const
void operator+=(const Point &a)
Point(float x, float y)
Definition geometry.hpp:70
Size size
Definition geometry.hpp:72
bool operator==(const Rect &other) const
float getMinX() const
std::string describe()
float getMidY() const
float getMidX() const
bool collideWith(const Rect &other) const
bool pointInside(Point point)
float getWidth() const
Rect offsetBy(const Point &origin) const
float getMaxY() const
float getHeight() const
Rect(Point origin, Size size)
Rect(float x, float y, float width, float height)
bool inscribed(const Rect &other) const
Point origin
Definition geometry.hpp:71
float getMinY() const
float getMaxX() const
Definition geometry.hpp:50
float width
Definition geometry.hpp:51
Size operator-(const Size &a) const
Size(float width, float height)
Size operator+(const Size &a) const
float height
Definition geometry.hpp:52
Size operator/(const float &a) const
Size operator*(const float &a) const
bool operator==(const Size &other) const