Class: CP::BB
- Inherits:
-
Object
- Object
- CP::BB
- Defined in:
- ext/chipmunk/rb_cpBB.c
Instance Method Summary collapse
- #area ⇒ Object
- #b ⇒ Object
- #b=(val) ⇒ Object
- #clamp_vect(v) ⇒ Object
- #contain?(other) ⇒ Boolean
-
#contain_bb?(other) ⇒ Boolean
static VALUE rb_cpBBintersects(VALUE self, VALUE a, VALUE b) { cpVect *a, *b; if(IS_NIL(b)) { // box/box intersect return CP_INT_BOOL(cpBBIntersects(*BBGET(self), *BBGET(a))); } // If we get here it’s a box/segment intersect a = VGET(va); b = VGET(vb); if(a && b) { return CP_INT_BOOL(cpBBIntersectsSegment(*BBGET(self), *a, *b)); } rb_raise(rb_eArgError, “intersects needs 1 Box or 2 Vect2 arguments”); return Qnil; }.
- #contain_vect?(other) ⇒ Boolean
-
#contains?(other) ⇒ Boolean
containsVect.
-
#contains_bb?(other) ⇒ Boolean
static VALUE rb_cpBBintersects(VALUE self, VALUE a, VALUE b) { cpVect *a, *b; if(IS_NIL(b)) { // box/box intersect return CP_INT_BOOL(cpBBIntersects(*BBGET(self), *BBGET(a))); } // If we get here it’s a box/segment intersect a = VGET(va); b = VGET(vb); if(a && b) { return CP_INT_BOOL(cpBBIntersectsSegment(*BBGET(self), *a, *b)); } rb_raise(rb_eArgError, “intersects needs 1 Box or 2 Vect2 arguments”); return Qnil; }.
- #contains_vect?(other) ⇒ Boolean
- #expand(other) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #intersect?(*args) ⇒ Boolean
- #intersect_bb?(other) ⇒ Boolean
- #intersect_segment?(a, b) ⇒ Boolean
- #intersects?(*args) ⇒ Boolean
- #intersects_bb?(other) ⇒ Boolean
- #intersects_segment?(a, b) ⇒ Boolean
- #l ⇒ Object
- #l=(val) ⇒ Object
- #merge(other) ⇒ Object
- #merged_area(other) ⇒ Object
- #r ⇒ Object
- #r=(val) ⇒ Object
-
#segment_query(va, vb) ⇒ Object
/ Returns the fraction along the segment query the cpBB is hit.
- #t ⇒ Object
- #t=(val) ⇒ Object
- #to_s ⇒ Object
- #wrap_vect(v) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'ext/chipmunk/rb_cpBB.c', line 43 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; } |
Instance Method Details
#area ⇒ Object
206 207 208 209 |
# File 'ext/chipmunk/rb_cpBB.c', line 206 static VALUE rb_cpBBArea(VALUE self) { return DBL2NUM(cpBBArea(*BBGET(self))); } |
#b ⇒ Object
147 148 149 150 |
# File 'ext/chipmunk/rb_cpBB.c', line 147 static VALUE rb_cpBBGetB(VALUE self) { return rb_float_new(BBGET(self)->b); } |
#b=(val) ⇒ Object
168 169 170 171 172 |
# File 'ext/chipmunk/rb_cpBB.c', line 168 static VALUE rb_cpBBSetB(VALUE self, VALUE val) { BBGET(self)->b = NUM2DBL(val); return val; } |
#clamp_vect(v) ⇒ Object
132 133 134 135 |
# File 'ext/chipmunk/rb_cpBB.c', line 132 static VALUE rb_cpBBClampVect(VALUE self, VALUE v) { return VNEW(cpBBClampVect(*BBGET(self), *VGET(v))); } |
#contain?(other) ⇒ Boolean
93 94 95 96 97 98 99 100 101 102 |
# File 'ext/chipmunk/rb_cpBB.c', line 93 static VALUE rb_cpBBcontains(VALUE self, VALUE other) { if (rb_class_of(other) == c_cpBB) { return rb_cpBBContainsBB(self, other); } else if (rb_class_of(other) == c_cpVect) { return rb_cpBBContainsVect(self, other); } rb_raise(rb_eArgError, "contains requires a BB or a Vect2 argument"); return Qnil; } |
#contain_bb?(other) ⇒ Boolean
static VALUE rb_cpBBintersects(VALUE self, VALUE a, VALUE b) {
cpVect *a, *b;
if(IS_NIL(b)) { // box/box intersect
return CP_INT_BOOL(cpBBIntersects(*BBGET(self), *BBGET(a)));
}
// If we get here it's a box/segment intersect
a = VGET(va);
b = VGET(vb);
if(a && b) {
return CP_INT_BOOL(cpBBIntersectsSegment(*BBGET(self), *a, *b));
}
rb_raise(rb_eArgError, "intersects needs 1 Box or 2 Vect2 arguments");
return Qnil;
}
81 82 83 84 85 |
# File 'ext/chipmunk/rb_cpBB.c', line 81 static VALUE rb_cpBBContainsBB(VALUE self, VALUE other) { int value = cpBBContainsBB(*BBGET(self), *BBGET(other)); return CP_INT_BOOL(value); } |
#contain_vect?(other) ⇒ Boolean
87 88 89 90 91 |
# File 'ext/chipmunk/rb_cpBB.c', line 87 static VALUE rb_cpBBContainsVect(VALUE self, VALUE other) { int value = cpBBContainsVect(*BBGET(self), *VGET(other)); return CP_INT_BOOL(value); } |
#contains?(other) ⇒ Boolean
containsVect
93 94 95 96 97 98 99 100 101 102 |
# File 'ext/chipmunk/rb_cpBB.c', line 93 static VALUE rb_cpBBcontains(VALUE self, VALUE other) { if (rb_class_of(other) == c_cpBB) { return rb_cpBBContainsBB(self, other); } else if (rb_class_of(other) == c_cpVect) { return rb_cpBBContainsVect(self, other); } rb_raise(rb_eArgError, "contains requires a BB or a Vect2 argument"); return Qnil; } |
#contains_bb?(other) ⇒ Boolean
static VALUE rb_cpBBintersects(VALUE self, VALUE a, VALUE b) {
cpVect *a, *b;
if(IS_NIL(b)) { // box/box intersect
return CP_INT_BOOL(cpBBIntersects(*BBGET(self), *BBGET(a)));
}
// If we get here it's a box/segment intersect
a = VGET(va);
b = VGET(vb);
if(a && b) {
return CP_INT_BOOL(cpBBIntersectsSegment(*BBGET(self), *a, *b));
}
rb_raise(rb_eArgError, "intersects needs 1 Box or 2 Vect2 arguments");
return Qnil;
}
81 82 83 84 85 |
# File 'ext/chipmunk/rb_cpBB.c', line 81 static VALUE rb_cpBBContainsBB(VALUE self, VALUE other) { int value = cpBBContainsBB(*BBGET(self), *BBGET(other)); return CP_INT_BOOL(value); } |
#contains_vect?(other) ⇒ Boolean
87 88 89 90 91 |
# File 'ext/chipmunk/rb_cpBB.c', line 87 static VALUE rb_cpBBContainsVect(VALUE self, VALUE other) { int value = cpBBContainsVect(*BBGET(self), *VGET(other)); return CP_INT_BOOL(value); } |
#expand(other) ⇒ Object
201 202 203 204 |
# File 'ext/chipmunk/rb_cpBB.c', line 201 static VALUE (VALUE self, VALUE other) { return BBNEW(cpBBExpand(*BBGET(self), *VGET(other))); } |
#intersect?(*args) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/chipmunk/rb_cpBB.c', line 116 static VALUE rb_cpBBintersects(int argc, VALUE *argv, VALUE self) { VALUE other, b; rb_scan_args(argc, argv, "11", &other, &b); if (rb_class_of(other) == c_cpBB) { return rb_cpBBIntersectsBB(self, other); } else if ((rb_class_of(other) == c_cpVect) && (rb_class_of(b) == c_cpVect)) { return rb_cpBBIntersectsSegment(self, other, b); } rb_raise(rb_eArgError, "contains requires a BB or 2 Vect2 arguments"); return Qnil; } |
#intersect_bb?(other) ⇒ Boolean
104 105 106 107 108 |
# File 'ext/chipmunk/rb_cpBB.c', line 104 static VALUE rb_cpBBIntersectsBB(VALUE self, VALUE other) { int value = cpBBIntersects(*BBGET(self), *BBGET(other)); return CP_INT_BOOL(value); } |
#intersect_segment?(a, b) ⇒ Boolean
110 111 112 113 114 |
# File 'ext/chipmunk/rb_cpBB.c', line 110 static VALUE rb_cpBBIntersectsSegment(VALUE self, VALUE a, VALUE b) { int value = cpBBIntersectsSegment(*BBGET(self), *VGET(a), *VGET(b)); return CP_INT_BOOL(value); } |
#intersects?(*args) ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/chipmunk/rb_cpBB.c', line 116 static VALUE rb_cpBBintersects(int argc, VALUE *argv, VALUE self) { VALUE other, b; rb_scan_args(argc, argv, "11", &other, &b); if (rb_class_of(other) == c_cpBB) { return rb_cpBBIntersectsBB(self, other); } else if ((rb_class_of(other) == c_cpVect) && (rb_class_of(b) == c_cpVect)) { return rb_cpBBIntersectsSegment(self, other, b); } rb_raise(rb_eArgError, "contains requires a BB or 2 Vect2 arguments"); return Qnil; } |
#intersects_bb?(other) ⇒ Boolean
104 105 106 107 108 |
# File 'ext/chipmunk/rb_cpBB.c', line 104 static VALUE rb_cpBBIntersectsBB(VALUE self, VALUE other) { int value = cpBBIntersects(*BBGET(self), *BBGET(other)); return CP_INT_BOOL(value); } |
#intersects_segment?(a, b) ⇒ Boolean
110 111 112 113 114 |
# File 'ext/chipmunk/rb_cpBB.c', line 110 static VALUE rb_cpBBIntersectsSegment(VALUE self, VALUE a, VALUE b) { int value = cpBBIntersectsSegment(*BBGET(self), *VGET(a), *VGET(b)); return CP_INT_BOOL(value); } |
#l ⇒ Object
142 143 144 145 |
# File 'ext/chipmunk/rb_cpBB.c', line 142 static VALUE rb_cpBBGetL(VALUE self) { return rb_float_new(BBGET(self)->l); } |
#l=(val) ⇒ Object
162 163 164 165 166 |
# File 'ext/chipmunk/rb_cpBB.c', line 162 static VALUE rb_cpBBSetL(VALUE self, VALUE val) { BBGET(self)->l = NUM2DBL(val); return val; } |
#merge(other) ⇒ Object
196 197 198 199 |
# File 'ext/chipmunk/rb_cpBB.c', line 196 static VALUE rb_cpBBmerge(VALUE self, VALUE other) { return BBNEW(cpBBMerge(*BBGET(self), *BBGET(other))); } |
#merged_area(other) ⇒ Object
211 212 213 214 |
# File 'ext/chipmunk/rb_cpBB.c', line 211 static VALUE rb_cpBBMergedArea(VALUE self, VALUE other) { return DBL2NUM(cpBBMergedArea(*BBGET(self), *BBGET(other))); } |
#r ⇒ Object
152 153 154 155 |
# File 'ext/chipmunk/rb_cpBB.c', line 152 static VALUE rb_cpBBGetR(VALUE self) { return rb_float_new(BBGET(self)->r); } |
#r=(val) ⇒ Object
174 175 176 177 178 |
# File 'ext/chipmunk/rb_cpBB.c', line 174 static VALUE rb_cpBBSetR(VALUE self, VALUE val) { BBGET(self)->r = NUM2DBL(val); return val; } |
#segment_query(va, vb) ⇒ Object
/ Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn’t hit.
217 218 219 220 221 222 223 224 225 226 227 |
# File 'ext/chipmunk/rb_cpBB.c', line 217 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; } |
#t ⇒ Object
157 158 159 160 |
# File 'ext/chipmunk/rb_cpBB.c', line 157 static VALUE rb_cpBBGetT(VALUE self) { return rb_float_new(BBGET(self)->t); } |
#t=(val) ⇒ Object
180 181 182 183 184 |
# File 'ext/chipmunk/rb_cpBB.c', line 180 static VALUE rb_cpBBSetT(VALUE self, VALUE val) { BBGET(self)->t = NUM2DBL(val); return val; } |
#to_s ⇒ Object
186 187 188 189 190 191 192 193 194 |
# File 'ext/chipmunk/rb_cpBB.c', line 186 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); } |
#wrap_vect(v) ⇒ Object
137 138 139 140 |
# File 'ext/chipmunk/rb_cpBB.c', line 137 static VALUE rb_cpBBWrapVect(VALUE self, VALUE v) { return VNEW(cpBBWrapVect(*BBGET(self), *VGET(v))); } |