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
)
25 static inline fixed_point
rectangle_top (rectangle
const *r
) { return r
->pos
.y
; }
26 static inline fixed_point
rectangle_left (rectangle
const *r
) { return r
->pos
.x
; }
27 static inline fixed_point
rectangle_bottom(rectangle
const *r
) { return fixed_point_add(rectangle_top (r
), r
->extent
.y
); }
28 static inline fixed_point
rectangle_right (rectangle
const *r
) { return fixed_point_add(rectangle_left(r
), r
->extent
.x
); }
30 static inline fixed_point
rectangle_width (rectangle
const *r
) { return r
->extent
.x
; }
31 static inline fixed_point
rectangle_height(rectangle
const *r
) { return r
->extent
.y
; }
33 static inline vec2d
rectangle_mid(rectangle
const *r
) {
34 vec2d v
= { fixed_point_add(r
->pos
.x
, fixed_point_div(r
->extent
.x
, FIXED_POINT(2, 0))),
35 fixed_point_add(r
->pos
.y
, fixed_point_div(r
->extent
.y
, FIXED_POINT(2, 0)))
40 static inline void rectangle_move_to (rectangle
*r
, vec2d new_pos
) { r
->pos
= new_pos
; }
41 static inline void rectangle_move_to_x(rectangle
*r
, fixed_point new_x
) { r
->pos
.x
= new_x
; }
42 static inline void rectangle_move_to_y(rectangle
*r
, fixed_point new_y
) { r
->pos
.x
= new_y
; }
44 static inline bool rectangle_intersect(rectangle
const *r1
,
45 rectangle
const *r2
) {
46 return (fixed_point_lt(rectangle_top (r1
), rectangle_bottom(r2
)) &&
47 fixed_point_gt(rectangle_bottom(r1
), rectangle_top (r2
)) &&
48 fixed_point_lt(rectangle_left (r1
), rectangle_right (r2
)) &&
49 fixed_point_gt(rectangle_right (r1
), rectangle_left (r2
)));
This page took 0.048046 seconds and 5 git commands to generate.