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
)
20 static inline vec2d
vec2d_neg(vec2d v
) {
33 static inline rectangle
rectangle_new(vec2d pos
, vec2d extent
) { rectangle r
= { pos
, extent
}; return r
; }
35 static inline fixed_point
rectangle_top (rectangle
const *r
) { return r
->pos
.y
; }
36 static inline fixed_point
rectangle_left (rectangle
const *r
) { return r
->pos
.x
; }
37 static inline fixed_point
rectangle_bottom(rectangle
const *r
) { return fixed_point_add(rectangle_top (r
), r
->extent
.y
); }
38 static inline fixed_point
rectangle_right (rectangle
const *r
) { return fixed_point_add(rectangle_left(r
), r
->extent
.x
); }
40 static inline fixed_point
rectangle_width (rectangle
const *r
) { return r
->extent
.x
; }
41 static inline fixed_point
rectangle_height(rectangle
const *r
) { return r
->extent
.y
; }
43 static inline vec2d
rectangle_mid(rectangle
const *r
) {
44 vec2d v
= { fixed_point_add(r
->pos
.x
, fixed_point_div(r
->extent
.x
, FIXED_POINT(2, 0))),
45 fixed_point_add(r
->pos
.y
, fixed_point_div(r
->extent
.y
, FIXED_POINT(2, 0)))
50 static inline void rectangle_move_to (rectangle
*r
, vec2d new_pos
) { r
->pos
= new_pos
; }
51 static inline void rectangle_move_to_x(rectangle
*r
, fixed_point new_x
) { r
->pos
.x
= new_x
; }
52 static inline void rectangle_move_to_y(rectangle
*r
, fixed_point new_y
) { r
->pos
.x
= new_y
; }
54 static inline void rectangle_move_rel (rectangle
*r
, vec2d vec
) { r
->pos
= vec2d_add(r
->pos
, vec
); }
55 static inline void rectangle_expand (rectangle
*r
, vec2d extent
) { r
->extent
= extent
; }
57 static inline bool rectangle_intersect(rectangle
const *r1
,
58 rectangle
const *r2
) {
59 return (fixed_point_lt(rectangle_top (r1
), rectangle_bottom(r2
)) &&
60 fixed_point_gt(rectangle_bottom(r1
), rectangle_top (r2
)) &&
61 fixed_point_lt(rectangle_left (r1
), rectangle_right (r2
)) &&
62 fixed_point_gt(rectangle_right (r1
), rectangle_left (r2
)));
This page took 0.046542 seconds and 5 git commands to generate.