1 #ifndef INCLUDED_RECTANGLE_H
2 #define INCLUDED_RECTANGLE_H
4 #include "fixed_point.h"
11 static inline vec2d
vec2d_add(vec2d v1
, vec2d v2
) {
13 fixed_point_add(v1
.x
, v2
.x
),
14 fixed_point_add(v1
.y
, v2
.y
)
19 static inline vec2d
vec2d_sub(vec2d v1
, vec2d v2
) {
21 fixed_point_sub(v1
.x
, v2
.x
),
22 fixed_point_sub(v1
.y
, v2
.y
)
27 static inline vec2d
vec2d_neg(vec2d v
) {
40 static inline rectangle
rectangle_new(vec2d pos
, vec2d extent
) { rectangle r
= { pos
, extent
}; return r
; }
42 static inline fixed_point
rectangle_top (rectangle
const *r
) { return r
->pos
.y
; }
43 static inline fixed_point
rectangle_left (rectangle
const *r
) { return r
->pos
.x
; }
44 static inline fixed_point
rectangle_bottom(rectangle
const *r
) { return fixed_point_add(rectangle_top (r
), r
->extent
.y
); }
45 static inline fixed_point
rectangle_right (rectangle
const *r
) { return fixed_point_add(rectangle_left(r
), r
->extent
.x
); }
47 static inline fixed_point
rectangle_width (rectangle
const *r
) { return r
->extent
.x
; }
48 static inline fixed_point
rectangle_height(rectangle
const *r
) { return r
->extent
.y
; }
50 static inline fixed_point
rectangle_mid_x (rectangle
const *r
) { return fixed_point_add(r
->pos
.x
, fixed_point_div(r
->extent
.x
, FIXED_INT(2))); }
51 static inline fixed_point
rectangle_mid_y (rectangle
const *r
) { return fixed_point_add(r
->pos
.y
, fixed_point_div(r
->extent
.y
, FIXED_INT(2))); }
53 static inline vec2d
rectangle_mid (rectangle
const *r
) { vec2d v
= { rectangle_mid_x(r
), rectangle_mid_y(r
) }; return v
; }
55 static inline void rectangle_move_to (rectangle
*r
, vec2d new_pos
) { r
->pos
= new_pos
; }
56 static inline void rectangle_move_to_x(rectangle
*r
, fixed_point new_x
) { r
->pos
.x
= new_x
; }
57 static inline void rectangle_move_to_y(rectangle
*r
, fixed_point new_y
) { r
->pos
.x
= new_y
; }
59 static inline void rectangle_move_rel (rectangle
*r
, vec2d vec
) { r
->pos
= vec2d_add(r
->pos
, vec
); }
60 static inline void rectangle_expand (rectangle
*r
, vec2d extent
) { r
->extent
= extent
; }
62 static inline bool rectangle_intersect(rectangle
const *r1
,
63 rectangle
const *r2
) {
64 return (fixed_point_lt(rectangle_top (r1
), rectangle_bottom(r2
)) &&
65 fixed_point_gt(rectangle_bottom(r1
), rectangle_top (r2
)) &&
66 fixed_point_lt(rectangle_left (r1
), rectangle_right (r2
)) &&
67 fixed_point_gt(rectangle_right (r1
), rectangle_left (r2
)));
This page took 0.04376 seconds and 5 git commands to generate.