Class: TG::Geometry::Rect
- Inherits:
-
Object
- Object
- TG::Geometry::Rect
- Defined in:
- ext/tg_geometry/tg_geometry_ext.c
Instance Method Summary collapse
- #center ⇒ Object
- #contains_point?(x_value, y_value) ⇒ Boolean
- #expand_to_include(other) ⇒ Object
- #expand_to_include_point(x_value, y_value) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #intersects?(other) ⇒ Boolean
- #max_x ⇒ Object
- #max_y ⇒ Object
- #min_x ⇒ Object
- #min_y ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1177
static VALUE rb_tg_geometry_rect_initialize(int argc, VALUE *argv, VALUE self) {
VALUE min_x_value;
VALUE min_y_value;
VALUE max_x_value;
VALUE max_y_value;
tg_rect_wrapper_t *rect_data;
double min_x;
double min_y;
double max_x;
double max_y;
rb_check_arity(argc, 4, 4);
rb_scan_args(argc, argv, "40", &min_x_value, &min_y_value, &max_x_value, &max_y_value);
min_x = NUM2DBL(min_x_value);
min_y = NUM2DBL(min_y_value);
max_x = NUM2DBL(max_x_value);
max_y = NUM2DBL(max_y_value);
validate_rect_coordinates(min_x, min_y, max_x, max_y);
TypedData_Get_Struct(self, tg_rect_wrapper_t, &tg_rect_type, rect_data);
rect_data->min_x = min_x;
rect_data->min_y = min_y;
rect_data->max_x = max_x;
rect_data->max_y = max_y;
rect_data->initialized = true;
rb_obj_freeze(self);
return self;
}
|
Instance Method Details
#center ⇒ Object
1229 1230 1231 1232 1233 1234 1235 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1229
static VALUE rb_tg_geometry_rect_center(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double center_x = rect_data->min_x + ((rect_data->max_x - rect_data->min_x) / 2.0);
double center_y = rect_data->min_y + ((rect_data->max_y - rect_data->min_y) / 2.0);
return rb_ary_new_from_args(2, rb_float_new(center_x), rb_float_new(center_y));
}
|
#contains_point?(x_value, y_value) ⇒ Boolean
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1244
static VALUE rb_tg_geometry_rect_contains_point_p(VALUE self, VALUE x_value, VALUE y_value) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double x = NUM2DBL(x_value);
double y = NUM2DBL(y_value);
check_finite_double(x, "x");
check_finite_double(y, "y");
return rect_contains_point_data(rect_data, x, y) ? Qtrue : Qfalse;
}
|
#expand_to_include(other) ⇒ Object
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1255
static VALUE rb_tg_geometry_rect_expand_to_include(VALUE self, VALUE other) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
tg_rect_wrapper_t *other_data = get_rect_wrapper(other);
double min_x = rect_data->min_x < other_data->min_x ? rect_data->min_x : other_data->min_x;
double min_y = rect_data->min_y < other_data->min_y ? rect_data->min_y : other_data->min_y;
double max_x = rect_data->max_x > other_data->max_x ? rect_data->max_x : other_data->max_x;
double max_y = rect_data->max_y > other_data->max_y ? rect_data->max_y : other_data->max_y;
return rect_build(min_x, min_y, max_x, max_y);
}
|
#expand_to_include_point(x_value, y_value) ⇒ Object
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1266
static VALUE rb_tg_geometry_rect_expand_to_include_point(VALUE self, VALUE x_value, VALUE y_value) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
double x = NUM2DBL(x_value);
double y = NUM2DBL(y_value);
double min_x;
double min_y;
double max_x;
double max_y;
check_finite_double(x, "x");
check_finite_double(y, "y");
min_x = rect_data->min_x < x ? rect_data->min_x : x;
min_y = rect_data->min_y < y ? rect_data->min_y : y;
max_x = rect_data->max_x > x ? rect_data->max_x : x;
max_y = rect_data->max_y > y ? rect_data->max_y : y;
return rect_build(min_x, min_y, max_x, max_y);
}
|
#intersects?(other) ⇒ Boolean
1237 1238 1239 1240 1241 1242 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1237
static VALUE rb_tg_geometry_rect_intersects_p(VALUE self, VALUE other) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
tg_rect_wrapper_t *other_data = get_rect_wrapper(other);
return rect_intersects_rect_data(rect_data, other_data) ? Qtrue : Qfalse;
}
|
#max_x ⇒ Object
1219 1220 1221 1222 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1219
static VALUE rb_tg_geometry_rect_max_x(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->max_x);
}
|
#max_y ⇒ Object
1224 1225 1226 1227 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1224
static VALUE rb_tg_geometry_rect_max_y(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->max_y);
}
|
#min_x ⇒ Object
1209 1210 1211 1212 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1209
static VALUE rb_tg_geometry_rect_min_x(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->min_x);
}
|
#min_y ⇒ Object
1214 1215 1216 1217 |
# File 'ext/tg_geometry/tg_geometry_ext.c', line 1214
static VALUE rb_tg_geometry_rect_min_y(VALUE self) {
tg_rect_wrapper_t *rect_data = get_rect_wrapper(self);
return rb_float_new(rect_data->min_y);
}
|