Class: Chipmunk::Vec2

Inherits:
Object
  • Object
show all
Defined in:
ext/chipmunk/rb_cpVect.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject


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_angleObject


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

#*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)));
}

#+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)));
}

#[email protected]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;
}

#-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)));
}

#[email protected]Object


94
95
96
97
# File 'ext/chipmunk/rb_cpVect.c', line 94

static VALUE
rb_cpVectNegate(VALUE self) {
  return VNEW(cpvneg(*VGET(self)));
}

#/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));
}

#==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;
}

#clampObject


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)));
}

#crossObject


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)));
}

#distObject


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)));
}

#distsqObject


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)));
}

#dotObject


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)));
}

#lengthObject


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));
}

#lengthsqObject


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));
}

#lerpObject


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));
}

#lerpconstObject


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?Boolean

Returns:

  • (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;
}

#normalizeObject


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_safeObject


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;
}

#perpObject


168
169
170
171
# File 'ext/chipmunk/rb_cpVect.c', line 168

static VALUE
rb_cpVectPerp(VALUE self) {
  return VNEW(cpvperp(*VGET(self)));
}

#projectObject


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)));
}

#rotateObject


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)));
}

#rperpObject


173
174
175
176
# File 'ext/chipmunk/rb_cpVect.c', line 173

static VALUE
rb_cpVectRperp(VALUE self) {
  return VNEW(cpvrperp(*VGET(self)));
}

#slerpObject


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));
}

#slerpconstObject


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_aObject


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_angleObject


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_sObject


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);
}

#unrotateObject


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)));
}

#xObject


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=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;
}

#yObject


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=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;
}