Changeset 1948 for libcaca/trunk/ruby/cucul
- Timestamp:
- Nov 13, 2007, 2:20:14 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/ruby/cucul/cucul-canvas.c
r1944 r1948 245 245 } 246 246 247 static VALUE draw_polyline(VALUE self, VALUE x, VALUE y, VALUE ch)247 static VALUE draw_polyline(VALUE self, VALUE points, VALUE ch) 248 248 { 249 249 int i, n; 250 250 int *ax, *ay; 251 252 n = RARRAY(x)->len; 253 254 /* Ensure x and y have the same number of elements */ 255 if(n != RARRAY(y)->len) 256 rb_raise(rb_eArgError, "Arguments do not have the same number of elements"); 251 int error = 0; 252 VALUE v, x, y; 253 254 n = RARRAY(points)->len; 257 255 258 256 ax = (int*)malloc(n*sizeof(int)); … … 269 267 for(i=0; i<n; i++) 270 268 { 271 ax[i] = NUM2INT(rb_ary_entry(x, i)); 272 ay[i] = NUM2INT(rb_ary_entry(y, i)); 269 v = rb_ary_entry(points, i); 270 if((TYPE(v) == T_ARRAY) && (RARRAY(v)->len == 2)) 271 { 272 x = rb_ary_entry(v,0); 273 y = rb_ary_entry(v,1); 274 if(rb_obj_is_kind_of(x, rb_cInteger) && 275 rb_obj_is_kind_of(y, rb_cInteger)) 276 { 277 ax[i] = NUM2INT(x); 278 ay[i] = NUM2INT(y); 279 } else 280 error = 1; 281 } 282 else 283 error = 1; 284 } 285 286 if(error) 287 { 288 free(ax); 289 free(ay); 290 rb_raise(rb_eArgError, "Invalid list of points"); 273 291 } 274 292 … … 289 307 } 290 308 291 292 static VALUE draw_thin_polyline(VALUE self, VALUE x, VALUE y) 309 static VALUE draw_thin_polyline(VALUE self, VALUE points) 293 310 { 294 311 int i, n; 295 312 int *ax, *ay; 296 297 n = RARRAY(x)->len; 298 299 /* Ensure x and y have the same number of elements */ 300 if(n != RARRAY(y)->len) 301 rb_raise(rb_eArgError, "Arguments do not have the same number of elements"); 313 int error = 0; 314 VALUE v, x, y; 315 316 n = RARRAY(points)->len; 302 317 303 318 ax = (int*)malloc(n*sizeof(int)); … … 314 329 for(i=0; i<n; i++) 315 330 { 316 ax[i] = NUM2INT(rb_ary_entry(x, i)); 317 ay[i] = NUM2INT(rb_ary_entry(y, i)); 331 v = rb_ary_entry(points, i); 332 if((TYPE(v) == T_ARRAY) && (RARRAY(v)->len == 2)) 333 { 334 x = rb_ary_entry(v,0); 335 y = rb_ary_entry(v,1); 336 if(rb_obj_is_kind_of(x, rb_cInteger) && 337 rb_obj_is_kind_of(y, rb_cInteger)) 338 { 339 ax[i] = NUM2INT(x); 340 ay[i] = NUM2INT(y); 341 } else 342 error = 1; 343 } 344 else 345 error = 1; 346 } 347 348 if(error) 349 { 350 free(ax); 351 free(ay); 352 rb_raise(rb_eArgError, "Invalid list of points"); 318 353 } 319 354 … … 575 610 576 611 rb_define_method(cCanvas, "draw_line", draw_line, 5); 577 rb_define_method(cCanvas, "draw_polyline", draw_polyline, 3);612 rb_define_method(cCanvas, "draw_polyline", draw_polyline, 2); 578 613 rb_define_method(cCanvas, "draw_thin_line", draw_thin_line, 4); 579 rb_define_method(cCanvas, "draw_thin_polyline", draw_thin_polyline, 2);614 rb_define_method(cCanvas, "draw_thin_polyline", draw_thin_polyline, 1); 580 615 rb_define_method(cCanvas, "draw_circle", draw_circle, 4); 581 616 rb_define_method(cCanvas, "draw_ellipse", draw_ellipse, 5);
Note: See TracChangeset
for help on using the changeset viewer.