1
1
#include " aspect_ratio.hpp"
2
2
3
+ #include " units/display_domain.hpp"
4
+
3
5
namespace fractal {
4
6
5
- display_coordinate calculate_rectangle_end_point (
7
+ DisplayDomain calculate_rectangle_end_points (
6
8
display_coordinate start, display_coordinate current, float target_aspect_ratio
7
9
)
8
10
{
@@ -19,18 +21,30 @@ display_coordinate calculate_rectangle_end_point(
19
21
height = width / target_aspect_ratio;
20
22
}
21
23
22
- auto new_x = static_cast <float >(std::min (current.x , start.x ));
23
- auto new_y = static_cast <float >(std::min (current.y , start.y ));
24
+ auto x_pos1 = static_cast <float >(start.x );
25
+ auto y_pos1 = static_cast <float >(start.y );
26
+ auto x_pos2 = x_pos1 + width;
27
+ auto y_pos2 = y_pos1 + height;
28
+
29
+ bool flipped_horizontal = start.x > current.x ;
30
+ bool flipped_vertical = start.y > current.y ;
24
31
25
- // Adjust the top-left corner based on new dimensions
26
- if (current. x < start. x ) {
27
- new_x = static_cast < float >(start. x ) - width ;
32
+ if (flipped_vertical) {
33
+ y_pos1 -= height;
34
+ y_pos2 -= height ;
28
35
}
29
- if (current.y < start.y ) {
30
- new_y = static_cast <float >(start.y ) - height;
36
+ if (flipped_horizontal) {
37
+ x_pos1 -= width;
38
+ x_pos2 -= width;
31
39
}
32
40
33
- // Return the top-left and bottom-right corners as a pair of sf::Vector2f
34
- return {new_x + width, new_y + height};
41
+ display_coordinate top_left{
42
+ static_cast <uint16_t >(x_pos1), static_cast <uint16_t >(y_pos1)
43
+ };
44
+ display_coordinate bottom_right{
45
+ static_cast <uint16_t >(x_pos2), static_cast <uint16_t >(y_pos2)
46
+ };
47
+
48
+ return {top_left, bottom_right};
35
49
}
36
50
} // namespace fractal
0 commit comments