Class: CP::Vec2
- Inherits:
-
Object
- Object
- CP::Vec2
- Defined in:
- lib/chipmunk.rb,
ext/chipmunk/rb_cpVect.c
Constant Summary collapse
- ZERO =
Vec2.new(0,0).freeze
Class Method Summary collapse
Instance Method Summary collapse
- #*(s) ⇒ Object
- #+(v) ⇒ Object
-
#+@ ⇒ Object
the usefulness of unary plus is debatable, but I’ll include it for consistency.
- #-(v) ⇒ Object
- #-@ ⇒ Object
- #/(s) ⇒ Object
- #==(other) ⇒ Object
- #clamp(len) ⇒ Object
- #cross(v) ⇒ Object
- #dist(v) ⇒ Object
- #distsq(v) ⇒ Object
- #dot(v) ⇒ Object
- #initialize(x, y) ⇒ Object constructor
- #length ⇒ Object
- #lengthsq ⇒ Object
- #lerp(v, d) ⇒ Object
- #lerpconst(v, d) ⇒ Object
- #near?(v, d) ⇒ Boolean
- #normalize ⇒ Object
- #normalize! ⇒ Object
- #normalize_safe ⇒ Object
- #normalize_safe! ⇒ Object
- #perp ⇒ Object
- #project(v) ⇒ Object
- #rotate(v) ⇒ Object
- #rperp ⇒ Object
- #slerp(v, d) ⇒ Object
- #slerpconst(v, d) ⇒ Object
- #to_a ⇒ Object
- #to_angle ⇒ Object
- #to_s ⇒ Object
- #unrotate(v) ⇒ Object
- #x ⇒ Object
- #x=(x) ⇒ Object
- #y ⇒ Object
- #y=(y) ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'ext/chipmunk/rb_cpVect.c', line 41 static VALUE rb_cpVectInitialize(VALUE self, VALUE x, VALUE y) { cpVect *v = VGET(self); v->x = NUM2DBL(x); v->y = NUM2DBL(y); return self; } |
Class Method Details
.for_angle(angle) ⇒ Object
30 31 32 33 |
# File 'ext/chipmunk/rb_cpVect.c', line 30 static VALUE rb_cpVectForAngle(VALUE self, VALUE angle) { return VNEW(cpvforangle(NUM2DBL(angle))); } |
Instance Method Details
#*(s) ⇒ Object
109 110 111 112 |
# File 'ext/chipmunk/rb_cpVect.c', line 109 static VALUE rb_cpVectSMult(VALUE self, VALUE s) { return VNEW(cpvmult(*VGET(self), NUM2DBL(s))); } |
#+(v) ⇒ Object
99 100 101 102 |
# File 'ext/chipmunk/rb_cpVect.c', line 99 static VALUE rb_cpVectAdd(VALUE self, VALUE v) { return VNEW(cpvadd(*VGET(self), *VGET(v))); } |
#+@ ⇒ Object
the usefulness of unary plus is debatable, but I’ll include it for consistency.
246 247 248 249 |
# File 'ext/chipmunk/rb_cpVect.c', line 246 static VALUE rb_cpVectUnaryplus(VALUE self) { return self; } |
#-(v) ⇒ Object
104 105 106 107 |
# File 'ext/chipmunk/rb_cpVect.c', line 104 static VALUE rb_cpVectSub(VALUE self, VALUE v) { return VNEW(cpvsub(*VGET(self), *VGET(v))); } |
#-@ ⇒ Object
94 95 96 97 |
# File 'ext/chipmunk/rb_cpVect.c', line 94 static VALUE rb_cpVectNegate(VALUE self) { return VNEW(cpvneg(*VGET(self))); } |
#/(s) ⇒ Object
114 115 116 117 118 |
# File 'ext/chipmunk/rb_cpVect.c', line 114 static VALUE rb_cpVectSDiv(VALUE self, VALUE s) { cpFloat factor = 1.0f / (float)NUM2DBL(s); return VNEW(cpvmult(*VGET(self), factor)); } |
#==(other) ⇒ Object
240 241 242 243 |
# File 'ext/chipmunk/rb_cpVect.c', line 240 static VALUE rb_cpVectEql(VALUE self, VALUE other) { return cpveql(*VGET(self), *VGET(other)) ? Qtrue : Qfalse; } |
#clamp(len) ⇒ Object
227 228 229 230 |
# File 'ext/chipmunk/rb_cpVect.c', line 227 static VALUE rb_cpVectClamp(VALUE self, VALUE len) { return VNEW(cpvclamp(*VGET(self), NUM2DBL(len))); } |
#cross(v) ⇒ Object
125 126 127 128 |
# File 'ext/chipmunk/rb_cpVect.c', line 125 static VALUE rb_cpVectCross(VALUE self, VALUE v) { return rb_float_new(cpvcross(*VGET(self), *VGET(v))); } |
#dist(v) ⇒ Object
217 218 219 220 |
# File 'ext/chipmunk/rb_cpVect.c', line 217 static VALUE rb_cpVectDist(VALUE self, VALUE v) { return rb_float_new(cpvdist(*VGET(self), *VGET(v))); } |
#distsq(v) ⇒ Object
222 223 224 225 |
# File 'ext/chipmunk/rb_cpVect.c', line 222 static VALUE rb_cpVectDistsq(VALUE self, VALUE v) { return rb_float_new(cpvdistsq(*VGET(self), *VGET(v))); } |
#dot(v) ⇒ Object
120 121 122 123 |
# File 'ext/chipmunk/rb_cpVect.c', line 120 static VALUE rb_cpVectDot(VALUE self, VALUE v) { return rb_float_new(cpvdot(*VGET(self), *VGET(v))); } |
#length ⇒ Object
130 131 132 133 134 135 |
# File 'ext/chipmunk/rb_cpVect.c', line 130 static VALUE rb_cpVectLength(VALUE self) { cpVect *v; Data_Get_Struct(self, cpVect, v); return rb_float_new(cpvlength(*v)); } |
#lengthsq ⇒ Object
137 138 139 140 141 142 |
# File 'ext/chipmunk/rb_cpVect.c', line 137 static VALUE rb_cpVectLengthsq(VALUE self) { cpVect *v; Data_Get_Struct(self, cpVect, v); return rb_float_new(cpvlengthsq(*v)); } |
#lerp(v, d) ⇒ Object
178 179 180 181 182 |
# File 'ext/chipmunk/rb_cpVect.c', line 178 static VALUE rb_cpVectLerp(VALUE self, VALUE v, VALUE d) { cpFloat df = NUM2DBL(d); return VNEW(cpvlerp(*VGET(self), *VGET(v), df)); } |
#lerpconst(v, d) ⇒ Object
184 185 186 187 188 |
# File 'ext/chipmunk/rb_cpVect.c', line 184 static VALUE rb_cpVectLerpconst(VALUE self, VALUE v, VALUE d) { cpFloat df = (cpFloat) NUM2DBL(d); return VNEW(cpvlerpconst(*VGET(self), *VGET(v), df)); } |
#near?(v, d) ⇒ Boolean
233 234 235 236 237 238 |
# File 'ext/chipmunk/rb_cpVect.c', line 233 static VALUE rb_cpVectNear(VALUE self, VALUE v, VALUE d) { cpFloat dist = NUM2DBL(d); cpVect delta = cpvsub(*VGET(self), *VGET(v)); return (cpvdot(delta, delta) <= dist * dist) ? Qtrue : Qfalse; } |
#normalize ⇒ Object
144 145 146 147 |
# File 'ext/chipmunk/rb_cpVect.c', line 144 static VALUE rb_cpVectNorm(VALUE self) { return VNEW(cpvnormalize(*VGET(self))); } |
#normalize! ⇒ Object
149 150 151 152 153 154 |
# File 'ext/chipmunk/rb_cpVect.c', line 149 static VALUE rb_cpVectNormBang(VALUE self) { cpVect *v = VGET(self); *v = cpvnormalize(*v); return self; } |
#normalize_safe ⇒ Object
156 157 158 159 |
# File 'ext/chipmunk/rb_cpVect.c', line 156 static VALUE rb_cpVectNormSafe(VALUE self) { return VNEW(cpvnormalize_safe(*VGET(self))); } |
#normalize_safe! ⇒ Object
161 162 163 164 165 166 |
# File 'ext/chipmunk/rb_cpVect.c', line 161 static VALUE rb_cpVectNormSafeBang(VALUE self) { cpVect *v = VGET(self); *v = cpvnormalize_safe(*v); return self; } |
#perp ⇒ Object
168 169 170 171 |
# File 'ext/chipmunk/rb_cpVect.c', line 168 static VALUE rb_cpVectPerp(VALUE self) { return VNEW(cpvperp(*VGET(self))); } |
#project(v) ⇒ Object
202 203 204 205 |
# File 'ext/chipmunk/rb_cpVect.c', line 202 static VALUE rb_cpVectProject(VALUE self, VALUE v) { return VNEW(cpvproject(*VGET(self), *VGET(v))); } |
#rotate(v) ⇒ Object
207 208 209 210 |
# File 'ext/chipmunk/rb_cpVect.c', line 207 static VALUE rb_cpVectRotate(VALUE self, VALUE v) { return VNEW(cpvrotate(*VGET(self), *VGET(v))); } |
#rperp ⇒ Object
173 174 175 176 |
# File 'ext/chipmunk/rb_cpVect.c', line 173 static VALUE rb_cpVectRperp(VALUE self) { return VNEW(cpvrperp(*VGET(self))); } |
#slerp(v, d) ⇒ Object
190 191 192 193 194 |
# File 'ext/chipmunk/rb_cpVect.c', line 190 static VALUE rb_cpVectSlerp(VALUE self, VALUE v, VALUE d) { cpFloat df = (cpFloat) NUM2DBL(d); return VNEW(cpvslerp(*VGET(self), *VGET(v), df)); } |
#slerpconst(v, d) ⇒ Object
196 197 198 199 200 |
# File 'ext/chipmunk/rb_cpVect.c', line 196 static VALUE rb_cpVectSlerpconst(VALUE self, VALUE v, VALUE d) { cpFloat df = (cpFloat) NUM2DBL(d); return VNEW(cpvslerpconst(*VGET(self), *VGET(v), df)); } |
#to_a ⇒ Object
82 83 84 85 86 |
# File 'ext/chipmunk/rb_cpVect.c', line 82 static VALUE rb_cpVectToArray(VALUE self) { cpVect *v = VGET(self); return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y)); } |
#to_angle ⇒ Object
88 89 90 91 |
# File 'ext/chipmunk/rb_cpVect.c', line 88 static VALUE rb_cpVectToAngle(VALUE self) { return rb_float_new(cpvtoangle(*VGET(self))); } |
#to_s ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'ext/chipmunk/rb_cpVect.c', line 72 static VALUE rb_cpVectToString(VALUE self) { char str[256]; cpVect *v = VGET(self); sprintf(str, "(% .3f, % .3f)", v->x, v->y); return rb_str_new2(str); } |
#unrotate(v) ⇒ Object
212 213 214 215 |
# File 'ext/chipmunk/rb_cpVect.c', line 212 static VALUE rb_cpVectUnRotate(VALUE self, VALUE v) { return VNEW(cpvunrotate(*VGET(self), *VGET(v))); } |
#x ⇒ Object
50 51 52 53 |
# File 'ext/chipmunk/rb_cpVect.c', line 50 static VALUE rb_cpVectGetX(VALUE self) { return rb_float_new(VGET(self)->x); } |
#x=(x) ⇒ Object
60 61 62 63 64 |
# File 'ext/chipmunk/rb_cpVect.c', line 60 static VALUE rb_cpVectSetX(VALUE self, VALUE x) { VGET(self)->x = NUM2DBL(x); return self; } |
#y ⇒ Object
55 56 57 58 |
# File 'ext/chipmunk/rb_cpVect.c', line 55 static VALUE rb_cpVectGetY(VALUE self) { return rb_float_new(VGET(self)->y); } |
#y=(y) ⇒ Object
66 67 68 69 70 |
# File 'ext/chipmunk/rb_cpVect.c', line 66 static VALUE rb_cpVectSetY(VALUE self, VALUE y) { VGET(self)->y = NUM2DBL(y); return self; } |