-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.cpp
More file actions
526 lines (492 loc) · 11.9 KB
/
Copy pathmatrix.cpp
File metadata and controls
526 lines (492 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
#include "matrix.hpp"
#define SEGMENT_METHODS(type) \
LUNAR_METHOD(type, __index), \
LUNAR_METHOD(type, __newindex)
#define MATRIXBASE_METHODS(type) \
LUNAR_METHOD(type, __call), \
LUNAR_METHOD(type, __add), \
LUNAR_METHOD(type, __sub), \
LUNAR_METHOD(type, __mul), \
LUNAR_METHOD(type, __div), \
LUNAR_METHOD(type, __unm), \
LUNAR_METHOD(type, __len), \
LUNAR_METHOD(type, __tostring), \
LUNAR_METHOD(type, add), \
LUNAR_METHOD(type, sub), \
LUNAR_METHOD(type, mul), \
LUNAR_METHOD(type, div), \
LUNAR_METHOD(type, set), \
LUNAR_METHOD(type, rows), \
LUNAR_METHOD(type, cols), \
LUNAR_METHOD(type, size), \
LUNAR_METHOD(type, data), \
LUNAR_METHOD(type, setZero), \
LUNAR_METHOD(type, totable)
#define MATRIX_METHODS(type) \
MATRIXBASE_METHODS(type), \
LUNAR_METHOD(type, determinant), \
LUNAR_METHOD(type, inverse), \
LUNAR_METHOD(type, transpose)
#define VECTOR_METHODS(type) \
MATRIXBASE_METHODS(type), \
LUNAR_METHOD(type, dot), \
LUNAR_METHOD(type, norm), \
LUNAR_METHOD(type, squaredNorm)
namespace LuaEigen {
template<>
const char Vector2f::className[] = "Vector2f";
template<>
const LunarType<Vector2f>::Reg Vector2f::methods[] = {
VECTOR_METHODS(Vector2f),
LUNAR_METHOD(Vector2f, x),
LUNAR_METHOD(Vector2f, y),
{NULL, NULL}
};
template<>
const char Vector3f::className[] = "Vector3f";
template<>
const LunarType<Vector3f>::Reg Vector3f::methods[] = {
VECTOR_METHODS(Vector3f),
LUNAR_METHOD(Vector3f, x),
LUNAR_METHOD(Vector3f, y),
LUNAR_METHOD(Vector3f, z),
LUNAR_METHOD(Vector3f, cross),
{NULL, NULL}
};
template<>
const char Vector4f::className[] = "Vector4f";
template<>
const LunarType<Vector4f>::Reg Vector4f::methods[] = {
VECTOR_METHODS(Vector4f),
LUNAR_METHOD(Vector4f, x),
LUNAR_METHOD(Vector4f, y),
LUNAR_METHOD(Vector4f, z),
LUNAR_METHOD(Vector4f, w),
{NULL, NULL}
};
template<>
int VectorXf::onpush(lua_State *L) {
const int l_self = lua_absindex(L, -1);
Lunar<Type>::extend(L); // [-0,+0,e]
Lunar<Segment<Type, 2, 1>>::push(L, new Segment<Type, 2, 1>(this), true); // [-0,+1,e]
lua_setfield(L, l_self, "segment2"); // [-1,+0,e]
Lunar<Segment<Type, 3, 1>>::push(L, new Segment<Type, 3, 1>(this), true); // [-0,+1,e]
lua_setfield(L, l_self, "segment3"); // [-1,+0,e]
assert(l_self == lua_gettop(L));
return 0;
}
template<>
int VectorXf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(n);
setZero();
return 0;
}
template<>
int VectorXf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char VectorXf::className[] = "VectorXf";
template<>
const LunarType<VectorXf>::Reg VectorXf::methods[] = {
VECTOR_METHODS(VectorXf),
LUNAR_METHOD(VectorXf, resize),
{NULL, NULL}
};
template<>
const char SegmentXf2::className[] = "SegmentXf2";
template<>
const LunarType<SegmentXf2>::Reg SegmentXf2::methods[] = {
SEGMENT_METHODS(SegmentXf2),
{NULL, NULL}
};
template<>
const char SegmentXf3::className[] = "SegmentXf3";
template<>
const LunarType<SegmentXf3>::Reg SegmentXf3::methods[] = {
SEGMENT_METHODS(SegmentXf3),
{NULL, NULL}
};
template<>
const char Vector2Tf::className[] = "Vector2Tf";
template<>
const LunarType<Vector2Tf>::Reg Vector2Tf::methods[] = {
VECTOR_METHODS(Vector2Tf),
LUNAR_METHOD(Vector2Tf, x),
LUNAR_METHOD(Vector2Tf, y),
{NULL, NULL}
};
template<>
const char Vector3Tf::className[] = "Vector3Tf";
template<>
const LunarType<Vector3Tf>::Reg Vector3Tf::methods[] = {
VECTOR_METHODS(Vector3Tf),
LUNAR_METHOD(Vector3Tf, x),
LUNAR_METHOD(Vector3Tf, y),
LUNAR_METHOD(Vector3Tf, z),
LUNAR_METHOD(Vector3Tf, cross),
{NULL, NULL}
};
template<>
const char Vector4Tf::className[] = "Vector4Tf";
template<>
const LunarType<Vector4Tf>::Reg Vector4Tf::methods[] = {
VECTOR_METHODS(Vector4Tf),
LUNAR_METHOD(Vector4Tf, x),
LUNAR_METHOD(Vector4Tf, y),
LUNAR_METHOD(Vector4Tf, z),
LUNAR_METHOD(Vector4Tf, w),
{NULL, NULL}
};
template<>
int VectorXTf::onpush(lua_State *L) {
const int l_self = lua_absindex(L, -1);
Lunar<Type>::extend(L); // [-0,+0,e]
Lunar<Segment<Type, 1, 2>>::push(L, new Segment<Type, 1, 2>(this), true); // [-0,+1,e]
lua_setfield(L, l_self, "segment2"); // [-1,+0,e]
Lunar<Segment<Type, 1, 3>>::push(L, new Segment<Type, 1, 3>(this), true); // [-0,+1,e]
lua_setfield(L, l_self, "segment3"); // [-1,+0,e]
assert(l_self == lua_gettop(L));
return 0;
}
template<>
int VectorXTf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(n);
setZero();
return 0;
}
template<>
int VectorXTf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char VectorXTf::className[] = "VectorXTf";
template<>
const LunarType<VectorXTf>::Reg VectorXTf::methods[] = {
VECTOR_METHODS(VectorXTf),
LUNAR_METHOD(VectorXTf, resize),
{NULL, NULL}
};
template<>
const char SegmentXTf2::className[] = "SegmentXTf2";
template<>
const LunarType<SegmentXTf2>::Reg SegmentXTf2::methods[] = {
SEGMENT_METHODS(SegmentXTf2),
{NULL, NULL}
};
template<>
const char SegmentXTf3::className[] = "SegmentXTf3";
template<>
const LunarType<SegmentXTf3>::Reg SegmentXTf3::methods[] = {
SEGMENT_METHODS(SegmentXTf3),
{NULL, NULL}
};
template<>
const char Matrix1f::className[] = "Matrix1f";
template<>
const LunarType<Matrix1f>::Reg Matrix1f::methods[] = {
MATRIX_METHODS(Matrix1f),
{NULL, NULL}
};
template<>
const char Matrix2f::className[] = "Matrix2f";
template<>
const LunarType<Matrix2f>::Reg Matrix2f::methods[] = {
MATRIX_METHODS(Matrix2f),
{NULL, NULL}
};
template<>
const char Matrix3f::className[] = "Matrix3f";
template<>
const LunarType<Matrix3f>::Reg Matrix3f::methods[] = {
MATRIX_METHODS(Matrix3f),
{NULL, NULL}
};
template<>
const char Matrix4f::className[] = "Matrix4f";
template<>
const LunarType<Matrix4f>::Reg Matrix4f::methods[] = {
MATRIX_METHODS(Matrix4f),
{NULL, NULL}
};
template<>
int MatrixXf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
float m = lua_tonumberx(L, 3, &isnum);
if (!isnum) {
return luaL_argerror(L, 3, "Argument must be a number");
}
resize(n, m);
setZero();
return 0;
}
template<>
int MatrixXf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char MatrixXf::className[] = "MatrixXf";
template<>
const LunarType<MatrixXf>::Reg MatrixXf::methods[] = {
MATRIX_METHODS(MatrixXf),
LUNAR_METHOD(MatrixXf, resize),
{NULL, NULL}
};
template<>
int Matrix2Xf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(Eigen::NoChange, n);
setZero();
return 0;
}
template<>
int Matrix2Xf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char Matrix2Xf::className[] = "Matrix2Xf";
template<>
const LunarType<Matrix2Xf>::Reg Matrix2Xf::methods[] = {
MATRIX_METHODS(Matrix2Xf),
LUNAR_METHOD(Matrix2Xf, resize),
{NULL, NULL}
};
template<>
int Matrix3Xf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(Eigen::NoChange, n);
setZero();
return 0;
}
template<>
int Matrix3Xf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char Matrix3Xf::className[] = "Matrix3Xf";
template<>
const LunarType<Matrix3Xf>::Reg Matrix3Xf::methods[] = {
MATRIX_METHODS(Matrix3Xf),
LUNAR_METHOD(Matrix3Xf, resize),
{NULL, NULL}
};
template<>
int Matrix4Xf::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(Eigen::NoChange, n);
setZero();
return 0;
}
template<>
int Matrix4Xf::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char Matrix4Xf::className[] = "Matrix4Xf";
template<>
const LunarType<Matrix4Xf>::Reg Matrix4Xf::methods[] = {
MATRIX_METHODS(Matrix4Xf),
LUNAR_METHOD(Matrix4Xf, resize),
{NULL, NULL}
};
template<>
int MatrixX2f::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(n, Eigen::NoChange);
setZero();
return 0;
}
template<>
int MatrixX2f::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char MatrixX2f::className[] = "MatrixX2f";
template<>
const LunarType<MatrixX2f>::Reg MatrixX2f::methods[] = {
MATRIX_METHODS(MatrixX2f),
LUNAR_METHOD(MatrixX2f, resize),
{NULL, NULL}
};
template<>
int MatrixX3f::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(n, Eigen::NoChange);
setZero();
return 0;
}
template<>
int MatrixX3f::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char MatrixX3f::className[] = "MatrixX3f";
template<>
const LunarType<MatrixX3f>::Reg MatrixX3f::methods[] = {
MATRIX_METHODS(MatrixX3f),
LUNAR_METHOD(MatrixX3f, resize),
{NULL, NULL}
};
template<>
int MatrixX4f::resize(lua_State *L) {
int isnum = false;
float n = lua_tonumberx(L, 2, &isnum);
if (!isnum) {
return luaL_argerror(L, 2, "Argument must be a number");
}
resize(n, Eigen::NoChange);
setZero();
return 0;
}
template<>
int MatrixX4f::oninit(lua_State *L) {
Type *o = Lunar<Type>::test(L, 2);
if (o != nullptr) {
*this = *o;
}
else {
resize(L);
}
return 0;
}
template<>
const char MatrixX4f::className[] = "MatrixX4f";
template<>
const LunarType<MatrixX4f>::Reg MatrixX4f::methods[] = {
MATRIX_METHODS(MatrixX4f),
LUNAR_METHOD(MatrixX4f, resize),
{NULL, NULL}
};
template<>
const char Matrix32f::className[] = "Matrix32f";
template<>
const LunarType<Matrix32f>::Reg Matrix32f::methods[] = {
MATRIX_METHODS(Matrix32f),
{NULL, NULL}
};
template<>
const char Matrix23f::className[] = "Matrix23f";
template<>
const LunarType<Matrix23f>::Reg Matrix23f::methods[] = {
MATRIX_METHODS(Matrix23f),
{NULL, NULL}
};
template<>
const char Matrix24f::className[] = "Matrix24f";
template<>
const LunarType<Matrix24f>::Reg Matrix24f::methods[] = {
MATRIX_METHODS(Matrix24f),
{NULL, NULL}
};
template<>
const char Matrix34f::className[] = "Matrix34f";
template<>
const LunarType<Matrix34f>::Reg Matrix34f::methods[] = {
MATRIX_METHODS(Matrix34f),
{NULL, NULL}
};
template<>
const char Matrix42f::className[] = "Matrix42f";
template<>
const LunarType<Matrix42f>::Reg Matrix42f::methods[] = {
MATRIX_METHODS(Matrix42f),
{NULL, NULL}
};
template<>
const char Matrix43f::className[] = "Matrix43f";
template<>
const LunarType<Matrix43f>::Reg Matrix43f::methods[] = {
MATRIX_METHODS(Matrix43f),
{NULL, NULL}
};
}