Class: RedBird::Rect
- Inherits:
-
Data
- Object
- Data
- RedBird::Rect
- Defined in:
- ext/red_bird/rect.c,
ext/red_bird/rect.c
Overview
An abstract rectangular object used mainly for collision detection.
Instance Method Summary collapse
-
#collide?(rect) ⇒ Boolean
Test if this rectangle collided with another rectangle.
-
#height ⇒ Integer
Height of this rectangle.
-
#height=(height) ⇒ Object
Set the height of this rectangle.
- #initialize(x, y, width, height) ⇒ Object constructor
-
#width ⇒ Integer
Width of this rectangle.
-
#width=(width) ⇒ Object
Set the width of this rectangle.
-
#x ⇒ Integer
Coordinate x of this rectangle.
-
#x=(x) ⇒ Object
Set the coordinate x of this rectangle.
-
#y ⇒ Integer
Coordinate y of this rectangle.
-
#y=(y) ⇒ Object
Set the coordinate y of this rectangle.
Constructor Details
#initialize(x, y, width, height) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'ext/red_bird/rect.c', line 59
VALUE
bird_cRect_initialize(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height)
{
struct bird_rect_data *ptr;
RB_INTEGER_TYPE_P(x);
RB_INTEGER_TYPE_P(y);
RB_INTEGER_TYPE_P(width);
RB_INTEGER_TYPE_P(height);
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
ptr->data.x = NUM2INT(x);
ptr->data.y = NUM2INT(y);
ptr->data.w = NUM2INT(width);
ptr->data.h = NUM2INT(height);
return self;
}
|
Instance Method Details
#collide?(rect) ⇒ Boolean
Test if this rectangle collided with another rectangle.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'ext/red_bird/rect.c', line 219
VALUE
bird_cRect_collide(VALUE self, VALUE rect)
{
struct bird_rect_data *ptr1, *ptr2;
if(!rb_obj_is_kind_of(rect, bird_cRect))
rb_raise(rb_eTypeError, "%s",
"rect must be an instance of RedBird::Rect");
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr1);
TypedData_Get_Struct(rect, struct bird_rect_data, &bird_rect_type, ptr2);
if(ptr1->data.x <= ptr2->data.x + ptr2->data.w &&
ptr1->data.x + ptr1->data.w >= ptr2->data.x &&
ptr1->data.y <= ptr2->data.y + ptr2->data.h &&
ptr1->data.y + ptr1->data.h >= ptr2->data.y)
return Qtrue;
else
return Qfalse;
}
|
#height ⇒ Integer
Returns height of this rectangle.
163 164 165 166 167 168 169 170 171 |
# File 'ext/red_bird/rect.c', line 163
VALUE
bird_cRect_get_height(VALUE self)
{
struct bird_rect_data *ptr;
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
return INT2FIX(ptr->data.h);
}
|
#height=(height) ⇒ Object
Set the height of this rectangle.
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'ext/red_bird/rect.c', line 198
VALUE
bird_cRect_set_height(VALUE self, VALUE height)
{
struct bird_rect_data *ptr;
RB_INTEGER_TYPE_P(height);
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
ptr->data.h = FIX2INT(height);
return height;
}
|
#width ⇒ Integer
Returns width of this rectangle.
149 150 151 152 153 154 155 156 157 |
# File 'ext/red_bird/rect.c', line 149
VALUE
bird_cRect_get_width(VALUE self)
{
struct bird_rect_data *ptr;
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
return INT2FIX(ptr->data.w);
}
|
#width=(width) ⇒ Object
Set the width of this rectangle.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'ext/red_bird/rect.c', line 179
VALUE
bird_cRect_set_width(VALUE self, VALUE width)
{
struct bird_rect_data *ptr;
RB_INTEGER_TYPE_P(width);
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
ptr->data.w = FIX2INT(width);
return width;
}
|
#x ⇒ Integer
Returns coordinate x of this rectangle.
83 84 85 86 87 88 89 90 91 |
# File 'ext/red_bird/rect.c', line 83
VALUE
bird_cRect_get_x(VALUE self)
{
struct bird_rect_data *ptr;
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
return INT2FIX(ptr->data.x);
}
|
#x=(x) ⇒ Object
Set the coordinate x of this rectangle.
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'ext/red_bird/rect.c', line 113
VALUE
bird_cRect_set_x(VALUE self, VALUE x)
{
struct bird_rect_data *ptr;
RB_INTEGER_TYPE_P(x);
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
ptr->data.x = FIX2INT(x);
return x;
}
|
#y ⇒ Integer
Returns coordinate y of this rectangle.
97 98 99 100 101 102 103 104 105 |
# File 'ext/red_bird/rect.c', line 97
VALUE
bird_cRect_get_y(VALUE self)
{
struct bird_rect_data *ptr;
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
return INT2FIX(ptr->data.y);
}
|
#y=(y) ⇒ Object
Set the coordinate y of this rectangle.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'ext/red_bird/rect.c', line 132
VALUE
bird_cRect_set_y(VALUE self, VALUE y)
{
struct bird_rect_data *ptr;
RB_INTEGER_TYPE_P(y);
TypedData_Get_Struct(self, struct bird_rect_data, &bird_rect_type, ptr);
ptr->data.y = FIX2INT(y);
return y;
}
|