static VALUE rb_cpBBToString(VALUE self) { char str[256]; cpBB *bb = BBGET(self); sprintf(str, "#<CP::BB:(% .3f, % .3f) -> (% .3f, % .3f)>", bb->l, bb->b, bb->r, bb->t); return rb_str_new2(str); }
static VALUE rb_cpBBInitialize(VALUE self, VALUE l, VALUE b, VALUE r, VALUE t) { cpBB *bb = BBGET(self); bb->l = NUM2DBL(l); bb->b = NUM2DBL(b); bb->r = NUM2DBL(r); bb->t = NUM2DBL(t); return self; }
/// Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit. static VALUE rb_cpBBSegmentQuery(VALUE self, VALUE va, VALUE vb) { cpVect *a, *b; a = VGET(va); b = VGET(vb); if(a && b) { return DBL2NUM(cpBBSegmentQuery(*BBGET(self), *a, *b)); } rb_raise(rb_eArgError, "query requires 2 Vect2 arguments"); return Qnil; }
static VALUE rb_cpBBInitialize(int argc, VALUE *argv, VALUE self) { VALUE l, b, r, t; cpBB *bb = BBGET(self); rb_scan_args(argc, argv, "04", &l, &b, &r, &t); // initialize as a circle bounds box if ony 2 params if (NIL_P(r)) { if(NIL_P(l)) { (*bb) = cpBBNew(0, 0, 1, 1); // unit box. } else { cpVect * p = VGET(l); (*bb) = cpBBNewForCircle(*p, NUM2DBL(b)); } } else { (*bb) = cpBBNew(NUM2DBL(l), NUM2DBL(b), NUM2DBL(r), NUM2DBL(t)); } return self; }
static VALUE rb_cpBBSetB(VALUE self, VALUE val) { BBGET(self)->b = NUM2DBL(val); return val; }
static VALUE rb_cpBBGetT(VALUE self) { return rb_float_new(BBGET(self)->t); }
static VALUE rb_cpBBWrapVect(VALUE self, VALUE v) { return VNEW(cpBBWrapVect(*BBGET(self), *VGET(v))); }
static VALUE rb_cpBBintersects(VALUE self, VALUE other) { int value = cpBBintersects(*BBGET(self), *BBGET(other)); return value ? Qtrue : Qfalse; }
static VALUE rb_cpBBContainsVect(VALUE self, VALUE other) { int value = cpBBContainsVect(*BBGET(self), *VGET(other)); return CP_INT_BOOL(value); }
static VALUE rb_cpBBMergedArea(VALUE self, VALUE other) { return DBL2NUM(cpBBMergedArea(*BBGET(self), *BBGET(other))); }
static VALUE rb_cpBBArea(VALUE self) { return DBL2NUM(cpBBArea(*BBGET(self))); }
static VALUE rb_cpBBexpand(VALUE self, VALUE other) { return BBNEW(cpBBExpand(*BBGET(self), *VGET(other))); }
static VALUE rb_cpBBmerge(VALUE self, VALUE other) { return BBNEW(cpBBMerge(*BBGET(self), *BBGET(other))); }
static VALUE rb_cpBBIntersectsSegment(VALUE self, VALUE a, VALUE b) { int value = cpBBIntersectsSegment(*BBGET(self), *VGET(a), *VGET(b)); return CP_INT_BOOL(value); }
static VALUE rb_cpBBIntersectsBB(VALUE self, VALUE other) { int value = cpBBIntersects(*BBGET(self), *BBGET(other)); return CP_INT_BOOL(value); }
static VALUE rb_cpBBcontainsVect(VALUE self, VALUE other) { int value = cpBBcontainsVect(*BBGET(self), *VGET(other)); return value ? Qtrue : Qfalse; }