FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SFML/test/Graphics/Rect.test.cpp at master · githubhy/SFML · GitHub
githubhy
/
SFML
Public
forked from
SFML/SFML
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SFML
/
test
/
Graphics
/
Rect.test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
106 lines (87 loc) · 4.39 KB
Breadcrumbs
SFML
/
test
/
Graphics
/
Rect.test.cpp
Copy path
File metadata and controls
106 lines (87 loc) · 4.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
include
<
SFML/Graphics/Rect.hpp
>
#
include
<
SFML/System/Vector2.hpp
>
#
include
<
catch2/catch_template_test_macros.hpp
>
#
include
<
GraphicsUtil.hpp
>
#
include
<
type_traits
>
TEMPLATE_TEST_CASE
(
"
[Graphics] sf::Rect
"
,
"
"
,
int
,
float
)
{
SECTION
(
"
Type traits
"
)
{
STATIC_CHECK
(std::is_copy_constructible_v<sf::Rect<TestType>>);
STATIC_CHECK
(std::is_copy_assignable_v<sf::Rect<TestType>>);
STATIC_CHECK
(std::is_nothrow_move_constructible_v<sf::Rect<TestType>>);
STATIC_CHECK
(std::is_nothrow_move_assignable_v<sf::Rect<TestType>>);
}
SECTION
(
"
Construction
"
)
{
SECTION
(
"
Default constructor
"
)
{
constexpr
sf::Rect<TestType> rectangle;
STATIC_CHECK
(rectangle.
position
== sf::Vector2<TestType>());
STATIC_CHECK
(rectangle.
size
== sf::Vector2<TestType>());
}
SECTION
(
"
(Vector2, Vector2) constructor
"
)
{
constexpr
sf::Vector2<TestType>
position
(
1
,
2
);
constexpr
sf::Vector2<TestType>
dimension
(
3
,
4
);
constexpr
sf::Rect<TestType>
rectangle
(position, dimension);
STATIC_CHECK
(rectangle.
position
== position);
STATIC_CHECK
(rectangle.
size
== dimension);
}
SECTION
(
"
Conversion constructor
"
)
{
constexpr
sf::FloatRect
sourceRectangle
({
1
.
0f
,
2
.
0f
}, {
3
.
0f
,
4
.
0f
});
constexpr
sf::IntRect
rectangle
(sourceRectangle);
STATIC_CHECK
(rectangle.
position
==
sf::Vector2i
(
1
,
2
));
STATIC_CHECK
(rectangle.
size
==
sf::Vector2i
(
3
,
4
));
}
}
SECTION
(
"
contains(Vector2)
"
)
{
constexpr
sf::Rect<TestType>
rectangle
({
0
,
0
}, {
10
,
10
});
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
0
,
0
)) ==
true
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
9
,
0
)) ==
true
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
0
,
9
)) ==
true
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
9
,
9
)) ==
true
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
9
,
10
)) ==
false
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
10
,
9
)) ==
false
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
10
,
10
)) ==
false
);
STATIC_CHECK
(rectangle.
contains
(sf::Vector2<TestType>(
15
,
15
)) ==
false
);
}
SECTION
(
"
findIntersection()
"
)
{
constexpr
sf::Rect<TestType>
rectangle
({
0
,
0
}, {
10
,
10
});
constexpr
sf::Rect<TestType>
intersectingRectangle
({
5
,
5
}, {
10
,
10
});
constexpr
auto
intersectionResult = rectangle.
findIntersection
(intersectingRectangle);
STATIC_REQUIRE
(intersectionResult.
has_value
());
STATIC_CHECK
(*intersectionResult == sf::Rect<TestType>({
5
,
5
}, {
5
,
5
}));
constexpr
sf::Rect<TestType>
nonIntersectingRectangle
({-
5
, -
5
}, {
5
,
5
});
STATIC_CHECK_FALSE
(rectangle.
findIntersection
(nonIntersectingRectangle).
has_value
());
}
SECTION
(
"
getCenter()
"
)
{
STATIC_CHECK
(sf::Rect<TestType>({}, {}).
getCenter
() == sf::Vector2<TestType>());
STATIC_CHECK
(sf::Rect<TestType>({
1
,
2
}, {
4
,
6
}).
getCenter
() == sf::Vector2<TestType>(
3
,
5
));
}
SECTION
(
"
Operators
"
)
{
SECTION
(
"
operator==
"
)
{
STATIC_CHECK
(sf::Rect<TestType>() == sf::Rect<TestType>());
STATIC_CHECK
(sf::Rect<TestType>({
1
,
3
}, {
2
,
5
}) == sf::Rect<TestType>({
1
,
3
}, {
2
,
5
}));
STATIC_CHECK_FALSE
(sf::Rect<TestType>({
1
,
0
}, {
0
,
0
}) == sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK_FALSE
(sf::Rect<TestType>({
0
,
1
}, {
0
,
0
}) == sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK_FALSE
(sf::Rect<TestType>({
0
,
0
}, {
1
,
0
}) == sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK_FALSE
(sf::Rect<TestType>({
0
,
0
}, {
0
,
1
}) == sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
}
SECTION
(
"
operator!=
"
)
{
STATIC_CHECK
(sf::Rect<TestType>({
1
,
0
}, {
0
,
0
}) != sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK
(sf::Rect<TestType>({
0
,
1
}, {
0
,
0
}) != sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK
(sf::Rect<TestType>({
0
,
0
}, {
1
,
0
}) != sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK
(sf::Rect<TestType>({
0
,
0
}, {
0
,
1
}) != sf::Rect<TestType>({
0
,
0
}, {
0
,
0
}));
STATIC_CHECK_FALSE
(sf::Rect<TestType>() != sf::Rect<TestType>());
STATIC_CHECK_FALSE
(sf::Rect<TestType>({
1
,
3
}, {
2
,
5
}) != sf::Rect<TestType>({
1
,
3
}, {
2
,
5
}));
}
}
}
Back
|
FazBrowse Home
|
New Git URL