3 #include "coord-circle.h"
10 bool rect_def::contains(const coord_def
& p
) const
12 return (p
.x
>= min
.x
&& p
.x
<= max
.x
&& p
.y
>= min
.y
&& p
.y
<= max
.y
);
15 rect_def
rect_def::intersect(const rect_def
& other
) const
18 res
.min
.x
= std::max(min
.x
, other
.min
.x
);
19 res
.min
.y
= std::max(min
.y
, other
.min
.y
);
20 res
.max
.x
= std::min(max
.x
, other
.max
.x
);
21 res
.max
.y
= std::min(max
.y
, other
.max
.y
);
25 rectangle_iterator
rect_def::iter() const
27 return (rectangle_iterator(min
, max
));
30 circle_def::circle_def()
31 : los_radius(true), origin(coord_def(0,0)), check_bounds(false)
33 // Set up bounding box and shape.
34 init(LOS_MAX_RADIUS
, C_ROUND
);
37 circle_def::circle_def(const coord_def
& origin_
, const circle_def
& bds
)
38 : los_radius(bds
.los_radius
), shape(bds
.shape
),
39 origin(origin_
), check_bounds(true),
40 radius(bds
.radius
), radius_sq(bds
.radius_sq
)
42 // Set up bounding box.
46 circle_def::circle_def(int param
, circle_type ctype
)
47 : los_radius(false), origin(coord_def(0,0)), check_bounds(false)
52 circle_def::circle_def(const coord_def
&origin_
, int param
,
54 : los_radius(false), origin(origin_
), check_bounds(true)
59 void circle_def::init(int param
, circle_type ctype
)
70 radius
= ceil(sqrt((float)radius_sq
));
75 radius_sq
= radius
* radius
+ 1;
80 radius_sq
= radius
* radius
;
85 void circle_def::init_bbox()
87 bbox
= rect_def(origin
- coord_def(radius
, radius
),
88 origin
+ coord_def(radius
, radius
));
90 bbox
= bbox
.intersect(RECT_MAP_BOUNDS
);
93 const rect_def
& circle_def::get_bbox() const
98 const coord_def
& circle_def::get_center() const
103 circle_iterator
circle_def::iter() const
105 return (circle_iterator(*this));
108 bool circle_def::contains(const coord_def
&p
) const
110 if (!bbox
.contains(p
))
115 return ((p
- origin
).rdist() <= radius
);
118 int r_sq
= los_radius
? get_los_radius_sq() : radius_sq
;
119 return ((p
- origin
).abs() <= r_sq
);