rename symbol q to symbol p
[liba.git] / javascript / src / a.cpp
blob7948e8fbf8c18e759ef24bbeb6b22cbb3557da38
1 #include "a/a.h"
2 #include <emscripten/bind.h>
3 #if defined(__has_feature) && __has_feature(address_sanitizer)
4 #include <sanitizer/lsan_interface.h>
5 #endif /* -fsanitize=address */
7 namespace
10 static emscripten::val js_concat(emscripten::val x)
12 emscripten::val val = emscripten::val::array();
13 return val["concat"].call<emscripten::val>("apply", val, x);
16 static a_float *js_array_num_get(emscripten::val const &x, a_float *p, a_size n)
18 a_size length = x["length"].as<a_size>();
19 n = (n < length ? length : n) * sizeof(a_float);
20 p = a_cast_s(a_float *, a_alloc(p, n));
21 for (a_size i = 0; i < length; ++i)
23 p[i] = x[i].as<a_float>();
25 return p;
28 static emscripten::val js_array_num_new(a_float const *p, a_size n)
30 return emscripten::val(emscripten::typed_memory_view(n, p));
33 static a_u32 hash_bkdr(std::string const &str, a_u32 val)
35 return a_hash_bkdr_(str.data(), str.length(), val);
38 static a_u32 hash_sdbm(std::string const &str, a_u32 val)
40 return a_hash_sdbm_(str.data(), str.length(), val);
43 } /* namespace */
45 #include "a/crc.h"
47 struct crc8
49 a_u8 table[0x100];
50 std::vector<a_byte> _pack;
51 A_INLINE emscripten::val get_table() const
53 return emscripten::val(emscripten::typed_memory_view(0x100, table));
55 A_INLINE a_u8 operator()(std::string const &block, a_u8 value = 0)
57 return a_crc8(table, block.data(), block.length(), value);
59 A_INLINE emscripten::val pack(std::string const &block, a_u8 value = 0)
61 size_t n = block.length();
62 size_t m = block.length() + sizeof(value);
63 if (_pack.size() < m) { _pack.resize(m); }
64 std::copy(block.data(), block.data() + n, _pack.data());
65 *(_pack.data() + n) = a_crc8(table, block.data(), n, value);
66 return emscripten::val(emscripten::typed_memory_view(m, _pack.data()));
68 A_INLINE crc8 *gen(a_u8 poly, bool reversed = false)
70 reversed ? a_crc8l_init(table, poly) : a_crc8m_init(table, poly);
71 return this;
73 A_INLINE crc8(a_u8 poly, bool reversed = false)
75 gen(poly, reversed);
79 struct crc16
81 a_u16 table[0x100];
82 std::vector<a_byte> _pack;
83 a_u16 (*eval)(a_u16 const[0x100], void const *, a_size, a_u16);
84 A_INLINE emscripten::val get_table() const
86 return emscripten::val(emscripten::typed_memory_view(0x100, table));
88 A_INLINE a_u16 operator()(std::string const &block, a_u16 value = 0)
90 return eval(table, block.data(), block.length(), value);
92 A_INLINE emscripten::val pack(std::string const &block, a_u16 value = 0)
94 size_t n = block.length();
95 size_t m = block.length() + sizeof(value);
96 if (_pack.size() < m) { _pack.resize(m); }
97 std::copy(block.data(), block.data() + n, _pack.data());
98 value = eval(table, block.data(), n, value);
99 a_byte *p = _pack.data() + n;
100 eval == a_crc16m ? a_u16_setb(p, value) : a_u16_setl(p, value);
101 return emscripten::val(emscripten::typed_memory_view(m, _pack.data()));
103 A_INLINE crc16 *gen(a_u16 poly, bool reversed = false)
105 if (reversed)
107 a_crc16l_init(table, poly);
108 eval = a_crc16l;
110 else
112 a_crc16m_init(table, poly);
113 eval = a_crc16m;
115 return this;
117 A_INLINE crc16(a_u16 poly, bool reversed = false)
119 gen(poly, reversed);
123 struct crc32
125 a_u32 table[0x100];
126 std::vector<a_byte> _pack;
127 a_u32 (*eval)(a_u32 const[0x100], void const *, a_size, a_u32);
128 A_INLINE emscripten::val get_table() const
130 return emscripten::val(emscripten::typed_memory_view(0x100, table));
132 A_INLINE a_u32 operator()(std::string const &block, a_u32 value = 0)
134 return eval(table, block.data(), block.length(), value);
136 A_INLINE emscripten::val pack(std::string const &block, a_u32 value = 0)
138 size_t n = block.length();
139 size_t m = block.length() + sizeof(value);
140 if (_pack.size() < m) { _pack.resize(m); }
141 std::copy(block.data(), block.data() + n, _pack.data());
142 value = eval(table, block.data(), n, value);
143 a_byte *p = _pack.data() + n;
144 eval == a_crc32m ? a_u32_setb(p, value) : a_u32_setl(p, value);
145 return emscripten::val(emscripten::typed_memory_view(m, _pack.data()));
147 A_INLINE crc32 *gen(a_u32 poly, bool reversed = false)
149 if (reversed)
151 a_crc32l_init(table, poly);
152 eval = a_crc32l;
154 else
156 a_crc32m_init(table, poly);
157 eval = a_crc32m;
159 return this;
161 A_INLINE crc32(a_u32 poly, bool reversed = false)
163 gen(poly, reversed);
167 #if defined(WASM_BIGINT)
168 struct crc64
170 a_u64 table[0x100];
171 std::vector<a_byte> _pack;
172 a_u64 (*eval)(a_u64 const[0x100], void const *, a_size, a_u64);
173 A_INLINE emscripten::val get_table() const
175 return emscripten::val(emscripten::typed_memory_view(0x100, table));
177 A_INLINE emscripten::val operator()(std::string const &block, a_u64 value = 0)
179 return emscripten::val(eval(table, block.data(), block.length(), value));
181 A_INLINE emscripten::val pack(std::string const &block, a_u64 value = 0)
183 size_t n = block.length();
184 size_t m = block.length() + sizeof(value);
185 if (_pack.size() < m) { _pack.resize(m); }
186 std::copy(block.data(), block.data() + n, _pack.data());
187 value = eval(table, block.data(), n, value);
188 a_byte *p = _pack.data() + n;
189 eval == a_crc64m ? a_u64_setb(p, value) : a_u64_setl(p, value);
190 return emscripten::val(emscripten::typed_memory_view(m, _pack.data()));
192 A_INLINE crc64 *gen(a_u64 poly, bool reversed = false)
194 if (reversed)
196 a_crc64l_init(table, poly);
197 eval = a_crc64l;
199 else
201 a_crc64m_init(table, poly);
202 eval = a_crc64m;
204 return this;
206 A_INLINE crc64(a_u64 poly, bool reversed = false)
208 gen(poly, reversed);
211 #endif /* WASM_BIGINT */
213 #include "a/hpf.h"
215 struct hpf: public a_hpf
217 A_INLINE hpf(a_float fc, a_float ts)
219 alpha = A_HPF_GEN(fc, ts);
220 output = 0;
221 input = 0;
223 A_INLINE hpf(a_float _alpha)
225 alpha = _alpha;
226 output = 0;
227 input = 0;
229 A_INLINE hpf *gen(a_float fc, a_float ts)
231 a_hpf::gen(fc, ts);
232 return this;
234 A_INLINE a_float operator()(a_float x)
236 return a_hpf::operator()(x);
238 A_INLINE hpf *zero()
240 a_hpf::zero();
241 return this;
245 #include "a/lpf.h"
247 struct lpf: public a_lpf
249 A_INLINE lpf(a_float fc, a_float ts)
251 alpha = A_LPF_GEN(fc, ts);
252 output = 0;
254 A_INLINE lpf(a_float _alpha)
256 alpha = _alpha;
257 output = 0;
259 A_INLINE lpf *gen(a_float fc, a_float ts)
261 a_lpf::gen(fc, ts);
262 return this;
264 A_INLINE a_float operator()(a_float x)
266 return a_lpf::operator()(x);
268 A_INLINE lpf *zero()
270 a_lpf::zero();
271 return this;
275 #include "a/mf.h"
277 struct mf
279 static unsigned int const NUL;
280 static a_float gauss(a_float x, a_float sigma, a_float c)
282 return a_mf_gauss(x, sigma, c);
284 static unsigned int const GAUSS;
285 static a_float gauss2(a_float x, a_float sigma1, a_float c1, a_float sigma2, a_float c2)
287 return a_mf_gauss2(x, sigma1, c1, sigma2, c2);
289 static unsigned int const GAUSS2;
290 static a_float gbell(a_float x, a_float a, a_float b, a_float c)
292 return a_mf_gbell(x, a, b, c);
294 static unsigned int const GBELL;
295 static a_float sig(a_float x, a_float a, a_float c)
297 return a_mf_sig(x, a, c);
299 static unsigned int const SIG;
300 static a_float dsig(a_float x, a_float a1, a_float c1, a_float a2, a_float c2)
302 return a_mf_dsig(x, a1, c1, a2, c2);
304 static unsigned int const DSIG;
305 static a_float psig(a_float x, a_float a1, a_float c1, a_float a2, a_float c2)
307 return a_mf_psig(x, a1, c1, a2, c2);
309 static unsigned int const PSIG;
310 static a_float trap(a_float x, a_float a, a_float b, a_float c, a_float d)
312 return a_mf_trap(x, a, b, c, d);
314 static unsigned int const TRAP;
315 static a_float tri(a_float x, a_float a, a_float b, a_float c)
317 return a_mf_tri(x, a, b, c);
319 static unsigned int const TRI;
320 static a_float lins(a_float x, a_float a, a_float b)
322 return a_mf_lins(x, a, b);
324 static unsigned int const LINS;
325 static a_float linz(a_float x, a_float a, a_float b)
327 return a_mf_linz(x, a, b);
329 static unsigned int const LINZ;
330 static a_float s(a_float x, a_float a, a_float b)
332 return a_mf_s(x, a, b);
334 static unsigned int const S;
335 static a_float z(a_float x, a_float a, a_float b)
337 return a_mf_z(x, a, b);
339 static unsigned int const Z;
340 static a_float pi(a_float x, a_float a, a_float b, a_float c, a_float d)
342 return a_mf_pi(x, a, b, c, d);
344 static unsigned int const PI;
346 unsigned int const mf::NUL = A_MF_NUL;
347 unsigned int const mf::GAUSS = A_MF_GAUSS;
348 unsigned int const mf::GAUSS2 = A_MF_GAUSS2;
349 unsigned int const mf::GBELL = A_MF_GBELL;
350 unsigned int const mf::SIG = A_MF_SIG;
351 unsigned int const mf::DSIG = A_MF_DSIG;
352 unsigned int const mf::PSIG = A_MF_PSIG;
353 unsigned int const mf::TRAP = A_MF_TRAP;
354 unsigned int const mf::TRI = A_MF_TRI;
355 unsigned int const mf::LINS = A_MF_LINS;
356 unsigned int const mf::LINZ = A_MF_LINZ;
357 unsigned int const mf::S = A_MF_S;
358 unsigned int const mf::Z = A_MF_Z;
359 unsigned int const mf::PI = A_MF_PI;
361 #include "a/pid.h"
363 struct pid: public a_pid
365 A_INLINE pid *kpid(a_float _kp, a_float _ki, a_float _kd)
367 a_pid::kpid(_kp, _ki, _kd);
368 return this;
370 A_INLINE a_float run(a_float set, a_float _fdb)
372 return a_pid::run(set, _fdb);
374 A_INLINE a_float pos(a_float set, a_float _fdb)
376 return a_pid::pos(set, _fdb);
378 A_INLINE a_float inc(a_float set, a_float _fdb)
380 return a_pid::inc(set, _fdb);
382 A_INLINE pid *zero()
384 a_pid::zero();
385 return this;
387 A_INLINE pid()
389 kp = 1;
390 ki = 0;
391 kd = 0;
392 summax = +A_FLOAT_INF;
393 summin = -A_FLOAT_INF;
394 outmax = +A_FLOAT_INF;
395 outmin = -A_FLOAT_INF;
396 a_pid_init(this);
398 static unsigned int const RUN;
399 static unsigned int const POS;
400 static unsigned int const INC;
402 unsigned int const pid::RUN = A_PID_RUN;
403 unsigned int const pid::POS = A_PID_POS;
404 unsigned int const pid::INC = A_PID_INC;
406 #include "a/pid_fuzzy.h"
408 struct pid_fuzzy: public a_pid_fuzzy
410 A_INLINE pid_fuzzy *set_op(unsigned int _op)
412 a_pid_fuzzy::set_op(_op);
413 return this;
415 A_INLINE pid_fuzzy *rule(emscripten::val const &_me,
416 emscripten::val const &_mec,
417 emscripten::val const &_mkp,
418 emscripten::val const &_mki,
419 emscripten::val const &_mkd)
421 union
423 a_float const *p;
424 a_float *o;
425 } u;
426 order = _me["length"].as<unsigned int>();
427 u.p = me;
428 emscripten::val val = js_concat(_me);
429 me = js_array_num_get(val, u.o, 0);
430 val.delete_(val);
431 u.p = mec;
432 val = js_concat(_mec);
433 mec = js_array_num_get(val, u.o, 0);
434 val.delete_(val);
435 u.p = mkp;
436 val = js_concat(_mkp);
437 mkp = js_array_num_get(val, u.o, 0);
438 val.delete_(val);
439 u.p = mki;
440 val = js_concat(_mki);
441 mki = js_array_num_get(val, u.o, 0);
442 val.delete_(val);
443 u.p = mkd;
444 val = js_concat(_mkd);
445 mkd = js_array_num_get(val, u.o, 0);
446 val.delete_(val);
447 return this;
449 A_INLINE pid_fuzzy *set_joint(unsigned int num)
451 void *ptr = a_alloc(a_pid_fuzzy_joint(this), A_PID_FUZZY_JOINT(num));
452 a_pid_fuzzy_set_joint(this, ptr, num);
453 return this;
455 A_INLINE pid_fuzzy *kpid(a_float _kp, a_float _ki, a_float _kd)
457 a_pid_fuzzy::kpid(_kp, _ki, _kd);
458 return this;
460 A_INLINE a_float run(a_float set, a_float fdb)
462 return a_pid_fuzzy::run(set, fdb);
464 A_INLINE a_float pos(a_float set, a_float fdb)
466 return a_pid_fuzzy::pos(set, fdb);
468 A_INLINE a_float inc(a_float set, a_float fdb)
470 return a_pid_fuzzy::inc(set, fdb);
472 A_INLINE pid_fuzzy *zero()
474 a_pid_fuzzy::zero();
475 return this;
477 A_INLINE pid_fuzzy()
479 pid.kp = 1;
480 pid.ki = 0;
481 pid.kd = 0;
482 pid.summax = +A_FLOAT_INF;
483 pid.summin = -A_FLOAT_INF;
484 pid.outmax = +A_FLOAT_INF;
485 pid.outmin = -A_FLOAT_INF;
486 kp = 1;
487 ki = 0;
488 kd = 0;
489 me = nullptr;
490 mec = nullptr;
491 mkp = nullptr;
492 mki = nullptr;
493 mkd = nullptr;
494 idx = nullptr;
495 val = nullptr;
496 op = a_pid_fuzzy_op(A_PID_FUZZY_EQU);
497 order = 0;
498 joint = 0;
499 a_pid_fuzzy_init(this);
501 A_INLINE ~pid_fuzzy()
503 union
505 a_float const *p;
506 a_float *o;
507 } u;
508 a_alloc(a_pid_fuzzy_joint(this), 0);
509 u.p = me;
510 a_alloc(u.o, 0);
511 u.p = mec;
512 a_alloc(u.o, 0);
513 u.p = mkp;
514 a_alloc(u.o, 0);
515 u.p = mki;
516 a_alloc(u.o, 0);
517 u.p = mkd;
518 a_alloc(u.o, 0);
520 A_INLINE unsigned int get_joint() const { return joint; }
521 A_INLINE a_float get_summax() const { return pid.summax; }
522 A_INLINE void set_summax(a_float summax) { pid.summax = summax; }
523 A_INLINE a_float get_summin() const { return pid.summin; }
524 A_INLINE void set_summin(a_float summin) { pid.summin = summin; }
525 A_INLINE a_float get_outmax() const { return pid.outmax; }
526 A_INLINE void set_outmax(a_float outmax) { pid.outmax = outmax; }
527 A_INLINE a_float get_outmin() const { return pid.outmin; }
528 A_INLINE void set_outmin(a_float outmin) { pid.outmin = outmin; }
529 A_INLINE a_float get_out() const { return pid.out; }
530 A_INLINE a_float get_fdb() const { return pid.fdb; }
531 A_INLINE a_float get_err() const { return pid.err; }
532 static unsigned int const CAP;
533 static unsigned int const CAP_ALGEBRA;
534 static unsigned int const CAP_BOUNDED;
535 static unsigned int const CUP;
536 static unsigned int const CUP_ALGEBRA;
537 static unsigned int const CUP_BOUNDED;
538 static unsigned int const EQU;
540 unsigned int const pid_fuzzy::CAP = A_PID_FUZZY_CAP;
541 unsigned int const pid_fuzzy::CAP_ALGEBRA = A_PID_FUZZY_CAP_ALGEBRA;
542 unsigned int const pid_fuzzy::CAP_BOUNDED = A_PID_FUZZY_CAP_BOUNDED;
543 unsigned int const pid_fuzzy::CUP = A_PID_FUZZY_CUP;
544 unsigned int const pid_fuzzy::CUP_ALGEBRA = A_PID_FUZZY_CUP_ALGEBRA;
545 unsigned int const pid_fuzzy::CUP_BOUNDED = A_PID_FUZZY_CUP_BOUNDED;
546 unsigned int const pid_fuzzy::EQU = A_PID_FUZZY_EQU;
548 #include "a/pid_neuro.h"
550 struct pid_neuro: public a_pid_neuro
552 A_INLINE pid_neuro *kpid(a_float _k, a_float kp, a_float ki, a_float kd)
554 a_pid_neuro::kpid(_k, kp, ki, kd);
555 return this;
557 A_INLINE pid_neuro *wpid(a_float _wp, a_float _wi, a_float _wd)
559 a_pid_neuro::wpid(_wp, _wi, _wd);
560 return this;
562 A_INLINE a_float run(a_float set, a_float fdb)
564 return a_pid_neuro::run(set, fdb);
566 A_INLINE a_float inc(a_float set, a_float fdb)
568 return a_pid_neuro::inc(set, fdb);
570 A_INLINE pid_neuro *zero()
572 a_pid_neuro::zero();
573 return this;
575 A_INLINE pid_neuro()
577 pid.summax = +A_FLOAT_INF;
578 pid.summin = -A_FLOAT_INF;
579 pid.outmax = +A_FLOAT_INF;
580 pid.outmin = -A_FLOAT_INF;
581 pid.kp = 0;
582 pid.ki = 0;
583 pid.kd = 0;
584 k = 1;
585 wp = A_FLOAT_C(0.1);
586 wi = A_FLOAT_C(0.1);
587 wd = A_FLOAT_C(0.1);
588 a_pid_neuro_init(this);
590 A_INLINE a_float get_kp() const { return pid.kp; }
591 A_INLINE void set_kp(a_float kp) { pid.kp = kp; }
592 A_INLINE a_float get_ki() const { return pid.ki; }
593 A_INLINE void set_ki(a_float ki) { pid.ki = ki; }
594 A_INLINE a_float get_kd() const { return pid.kd; }
595 A_INLINE void set_kd(a_float kd) { pid.kd = kd; }
596 A_INLINE a_float get_outmax() const { return pid.outmax; }
597 A_INLINE void set_outmax(a_float outmax) { pid.outmax = outmax; }
598 A_INLINE a_float get_outmin() const { return pid.outmin; }
599 A_INLINE void set_outmin(a_float outmin) { pid.outmin = outmin; }
600 A_INLINE a_float get_out() const { return pid.out; }
601 A_INLINE a_float get_fdb() const { return pid.fdb; }
602 A_INLINE a_float get_err() const { return pid.err; }
605 #include "a/tf.h"
607 struct tf: public a_tf
609 void set_num_(emscripten::val const &_num, a_float *num)
611 a_uint num_n = _num["length"].as<a_uint>();
612 a_float *p = js_array_num_get(_num, num, a_size_c(num_n) * 2);
613 a_tf_set_num(this, num_n, p, p + num_n);
615 void set_den_(emscripten::val const &_den, a_float *den)
617 a_uint den_n = _den["length"].as<a_uint>();
618 a_float *p = js_array_num_get(_den, den, a_size_c(den_n) * 2);
619 a_tf_set_den(this, den_n, p, p + den_n);
621 A_INLINE tf(emscripten::val const &num, emscripten::val const &den)
623 set_num_(num, nullptr);
624 set_den_(den, nullptr);
626 ~tf()
628 union
630 a_float const *p;
631 a_float *o;
632 } u;
633 u.p = num_p;
634 a_alloc(u.o, 0);
635 u.p = den_p;
636 a_alloc(u.o, 0);
638 A_INLINE emscripten::val get_input() const { return js_array_num_new(input, num_n); }
639 A_INLINE emscripten::val get_output() const { return js_array_num_new(output, den_n); }
640 A_INLINE emscripten::val get_num() const { return js_array_num_new(num_p, num_n); }
641 A_INLINE emscripten::val get_den() const { return js_array_num_new(den_p, den_n); }
642 A_INLINE tf *set_num(emscripten::val const &num)
644 union
646 a_float const *p;
647 a_float *o;
648 } u = {num_p};
649 set_num_(num, u.o);
650 return this;
652 A_INLINE tf *set_den(emscripten::val const &den)
654 union
656 a_float const *p;
657 a_float *o;
658 } u = {den_p};
659 set_den_(den, u.o);
660 return this;
662 A_INLINE a_float operator()(a_float x)
664 return a_tf::operator()(x);
666 A_INLINE tf *zero()
668 a_tf::zero();
669 return this;
673 #include "a/trajbell.h"
675 struct trajbell: public a_trajbell
677 A_INLINE a_float gen(a_float _jm, a_float _am, a_float _vm, a_float _p0, a_float _p1,
678 a_float _v0 = 0, a_float _v1 = 0)
680 return a_trajbell::gen(_jm, _am, _vm, _p0, _p1, _v0, _v1);
682 A_INLINE a_float pos(a_float dt) { return a_trajbell::pos(dt); }
683 A_INLINE a_float vel(a_float dt) { return a_trajbell::vel(dt); }
684 A_INLINE a_float acc(a_float dt) { return a_trajbell::acc(dt); }
685 A_INLINE a_float jer(a_float dt) { return a_trajbell::jer(dt); }
688 #include "a/trajpoly3.h"
690 struct trajpoly3: public a_trajpoly3
692 A_INLINE trajpoly3(a_float ts, a_float p0, a_float p1,
693 a_float v0 = 0, a_float v1 = 0)
695 a_trajpoly3_gen(this, ts, p0, p1, v0, v1);
697 A_INLINE a_float pos(a_float dt) { return a_trajpoly3::pos(dt); }
698 A_INLINE a_float vel(a_float dt) { return a_trajpoly3::vel(dt); }
699 A_INLINE a_float acc(a_float dt) { return a_trajpoly3::acc(dt); }
700 A_INLINE emscripten::val get_p() const { return js_array_num_new(p, A_LEN(p)); }
701 A_INLINE emscripten::val get_v() const { return js_array_num_new(v, A_LEN(v)); }
702 A_INLINE emscripten::val get_a() const { return js_array_num_new(a, A_LEN(a)); }
705 #include "a/trajpoly5.h"
707 struct trajpoly5: public a_trajpoly5
709 A_INLINE trajpoly5(a_float ts, a_float p0, a_float p1,
710 a_float v0 = 0, a_float v1 = 0,
711 a_float a0 = 0, a_float a1 = 0)
713 a_trajpoly5_gen(this, ts, p0, p1, v0, v1, a0, a1);
715 A_INLINE a_float pos(a_float dt) { return a_trajpoly5::pos(dt); }
716 A_INLINE a_float vel(a_float dt) { return a_trajpoly5::vel(dt); }
717 A_INLINE a_float acc(a_float dt) { return a_trajpoly5::acc(dt); }
718 A_INLINE emscripten::val get_p() const { return js_array_num_new(p, A_LEN(p)); }
719 A_INLINE emscripten::val get_v() const { return js_array_num_new(v, A_LEN(v)); }
720 A_INLINE emscripten::val get_a() const { return js_array_num_new(a, A_LEN(a)); }
723 #include "a/trajpoly7.h"
725 struct trajpoly7: public a_trajpoly7
727 A_INLINE trajpoly7(a_float ts, a_float p0, a_float p1,
728 a_float v0 = 0, a_float v1 = 0,
729 a_float a0 = 0, a_float a1 = 0,
730 a_float j0 = 0, a_float j1 = 0)
732 a_trajpoly7_gen(this, ts, p0, p1, v0, v1, a0, a1, j0, j1);
734 A_INLINE a_float pos(a_float dt) { return a_trajpoly7::pos(dt); }
735 A_INLINE a_float vel(a_float dt) { return a_trajpoly7::vel(dt); }
736 A_INLINE a_float acc(a_float dt) { return a_trajpoly7::acc(dt); }
737 A_INLINE a_float jer(a_float dt) { return a_trajpoly7::jer(dt); }
738 A_INLINE emscripten::val get_p() const { return js_array_num_new(p, A_LEN(p)); }
739 A_INLINE emscripten::val get_v() const { return js_array_num_new(v, A_LEN(v)); }
740 A_INLINE emscripten::val get_a() const { return js_array_num_new(a, A_LEN(a)); }
741 A_INLINE emscripten::val get_j() const { return js_array_num_new(j, A_LEN(j)); }
744 #include "a/trajtrap.h"
746 struct trajtrap: public a_trajtrap
748 A_INLINE a_float gen(a_float vm, a_float _ac, a_float _de, a_float _p0, a_float _p1,
749 a_float _v0 = 0, a_float _v1 = 0)
751 return a_trajtrap::gen(vm, _ac, _de, _p0, _p1, _v0, _v1);
753 A_INLINE a_float pos(a_float dt) { return a_trajtrap::pos(dt); }
754 A_INLINE a_float vel(a_float dt) { return a_trajtrap::vel(dt); }
755 A_INLINE a_float acc(a_float dt) { return a_trajtrap::acc(dt); }
758 #include "a/version.h"
759 #undef a_version_check
761 struct version: public a_version
763 A_INLINE a_int cmp(version const &ver) const
765 return a_version::cmp(ver);
767 A_INLINE a_bool operator<(version const &ver) const
769 return a_version::operator<(ver);
771 A_INLINE a_bool operator>(version const &ver) const
773 return a_version::operator>(ver);
775 A_INLINE a_bool operator<=(version const &ver) const
777 return a_version::operator<=(ver);
779 A_INLINE a_bool operator>=(version const &ver) const
781 return a_version::operator>=(ver);
783 A_INLINE a_bool operator==(version const &ver) const
785 return a_version::operator==(ver);
787 A_INLINE a_bool operator!=(version const &ver) const
789 return a_version::operator!=(ver);
791 A_INLINE version *parse(std::string const &ver)
793 a_version::parse(ver.c_str());
794 return this;
796 A_INLINE std::string toString()
798 std::string s = std::to_string(major) + "." +
799 std::to_string(minor) + "." +
800 std::to_string(third);
801 if (extra)
803 s += "." + std::to_string(extra);
805 return s;
807 A_INLINE version(unsigned int _major = 0,
808 unsigned int _minor = 0,
809 unsigned int _third = 0,
810 unsigned int _extra = 0)
812 major = _major;
813 minor = _minor;
814 third = _third;
815 extra = _extra;
819 #include "a/math.h"
820 #if __has_warning("-Wglobal-constructors")
821 #pragma GCC diagnostic ignored "-Wglobal-constructors"
822 #endif /* -Wglobal-constructors */
823 EMSCRIPTEN_BINDINGS(liba) // NOLINT
825 emscripten::function("isqrt", a_u32_sqrt);
826 emscripten::function("rsqrt", a_f64_rsqrt);
827 emscripten::function("hash_bkdr", hash_bkdr);
828 emscripten::function("hash_sdbm", hash_sdbm);
829 emscripten::class_<mf>("mf")
830 .class_property("NUL", &mf::NUL)
831 .class_function("gauss", &mf::gauss)
832 .class_property("GAUSS", &mf::GAUSS)
833 .class_function("gauss2", &mf::gauss2)
834 .class_property("GAUSS2", &mf::GAUSS2)
835 .class_function("gbell", &mf::gbell)
836 .class_property("GBELL", &mf::GBELL)
837 .class_function("sig", &mf::sig)
838 .class_property("SIG", &mf::SIG)
839 .class_function("dsig", &mf::dsig)
840 .class_property("DSIG", &mf::DSIG)
841 .class_function("psig", &mf::psig)
842 .class_property("PSIG", &mf::PSIG)
843 .class_function("trap", &mf::trap)
844 .class_property("TRAP", &mf::TRAP)
845 .class_function("tri", &mf::tri)
846 .class_property("TRI", &mf::TRI)
847 .class_function("lins", &mf::lins)
848 .class_property("LINS", &mf::LINS)
849 .class_function("linz", &mf::linz)
850 .class_property("LINZ", &mf::LINZ)
851 .class_function("s", &mf::s)
852 .class_property("S", &mf::S)
853 .class_function("z", &mf::z)
854 .class_property("Z", &mf::Z)
855 .class_function("pi", &mf::pi)
856 .class_property("PI", &mf::PI);
857 emscripten::class_<crc8>("crc8")
858 .constructor<a_u8>()
859 .constructor<a_u8, bool>()
860 .property("table", &crc8::get_table)
861 .function("eval", &crc8::operator())
862 .function("pack", &crc8::pack)
863 .function("gen", &crc8::gen, emscripten::allow_raw_pointers());
864 emscripten::class_<crc16>("crc16")
865 .constructor<a_u16>()
866 .constructor<a_u16, bool>()
867 .property("table", &crc16::get_table)
868 .function("eval", &crc16::operator())
869 .function("pack", &crc16::pack)
870 .function("gen", &crc16::gen, emscripten::allow_raw_pointers());
871 emscripten::class_<crc32>("crc32")
872 .constructor<a_u32>()
873 .constructor<a_u32, bool>()
874 .property("table", &crc32::get_table)
875 .function("eval", &crc32::operator())
876 .function("pack", &crc32::pack)
877 .function("gen", &crc32::gen, emscripten::allow_raw_pointers());
878 #if defined(WASM_BIGINT)
879 emscripten::class_<crc64>("crc64")
880 .constructor<a_u64>()
881 .constructor<a_u64, bool>()
882 .property("table", &crc64::get_table)
883 .function("eval", &crc64::operator())
884 .function("pack", &crc64::pack)
885 .function("gen", &crc64::gen, emscripten::allow_raw_pointers());
886 #endif /* WASM_BIGINT */
887 emscripten::class_<hpf>("hpf")
888 .constructor<a_float>()
889 .constructor<a_float, a_float>()
890 .function("iter", &hpf::operator())
891 .function("gen", &hpf::gen, emscripten::allow_raw_pointers())
892 .function("zero", &hpf::zero, emscripten::allow_raw_pointers())
893 .property<a_float const, void>("alpha", &hpf::alpha)
894 .property<a_float const, void>("output", &hpf::output)
895 .property<a_float const, void>("input", &hpf::input);
896 emscripten::class_<lpf>("lpf")
897 .constructor<a_float>()
898 .constructor<a_float, a_float>()
899 .function("iter", &lpf::operator())
900 .function("gen", &lpf::gen, emscripten::allow_raw_pointers())
901 .function("zero", &lpf::zero, emscripten::allow_raw_pointers())
902 .property<a_float const, void>("alpha", &lpf::alpha)
903 .property<a_float const, void>("output", &lpf::output);
904 emscripten::class_<pid>("pid")
905 .constructor<>()
906 .function("kpid", &pid::kpid, emscripten::allow_raw_pointers())
907 .function("zero", &pid::zero, emscripten::allow_raw_pointers())
908 .function("run", &pid::run)
909 .function("pos", &pid::pos)
910 .function("inc", &pid::inc)
911 .class_property("RUN", &pid::RUN)
912 .class_property("POS", &pid::POS)
913 .class_property("INC", &pid::INC)
914 .property<a_float, void>("kp", &pid::kp)
915 .property<a_float, void>("ki", &pid::ki)
916 .property<a_float, void>("kd", &pid::kd)
917 .property<a_float, void>("summax", &pid::summax)
918 .property<a_float, void>("summin", &pid::summin)
919 .property<a_float, void>("outmax", &pid::outmax)
920 .property<a_float, void>("outmin", &pid::outmin)
921 .property<a_float const, void>("out", &pid::out)
922 .property<a_float const, void>("fdb", &pid::fdb)
923 .property<a_float const, void>("err", &pid::err);
924 emscripten::class_<pid_fuzzy>("pid_fuzzy")
925 .constructor<>()
926 .function("op", &pid_fuzzy::set_op, emscripten::allow_raw_pointers())
927 .function("rule", &pid_fuzzy::rule, emscripten::allow_raw_pointers())
928 .function("set_joint", &pid_fuzzy::set_joint, emscripten::allow_raw_pointers())
929 .function("kpid", &pid_fuzzy::kpid, emscripten::allow_raw_pointers())
930 .function("zero", &pid_fuzzy::zero, emscripten::allow_raw_pointers())
931 .function("run", &pid_fuzzy::run)
932 .function("pos", &pid_fuzzy::pos)
933 .function("inc", &pid_fuzzy::inc)
934 .class_property("CAP", &pid_fuzzy::CAP)
935 .class_property("CAP_ALGEBRA", &pid_fuzzy::CAP_ALGEBRA)
936 .class_property("CAP_BOUNDED", &pid_fuzzy::CAP_BOUNDED)
937 .class_property("CUP", &pid_fuzzy::CUP)
938 .class_property("CUP_ALGEBRA", &pid_fuzzy::CUP_ALGEBRA)
939 .class_property("CUP_BOUNDED", &pid_fuzzy::CUP_BOUNDED)
940 .class_property("EQU", &pid_fuzzy::EQU)
941 .property<a_float, void>("kp", &pid_fuzzy::kp)
942 .property<a_float, void>("ki", &pid_fuzzy::ki)
943 .property<a_float, void>("kd", &pid_fuzzy::kd)
944 .property("summax", &pid_fuzzy::get_summax, &pid_fuzzy::set_summax)
945 .property("summin", &pid_fuzzy::get_summin, &pid_fuzzy::set_summin)
946 .property("outmax", &pid_fuzzy::get_outmax, &pid_fuzzy::set_outmax)
947 .property("outmin", &pid_fuzzy::get_outmin, &pid_fuzzy::set_outmin)
948 .property("out", &pid_fuzzy::get_out)
949 .property("fdb", &pid_fuzzy::get_fdb)
950 .property("err", &pid_fuzzy::get_err)
951 .property<unsigned int const, void>("order", &pid_fuzzy::order)
952 .property("joint", &pid_fuzzy::get_joint, &pid_fuzzy::set_joint);
953 emscripten::class_<pid_neuro>("pid_neuro")
954 .constructor<>()
955 .function("kpid", &pid_neuro::kpid, emscripten::allow_raw_pointers())
956 .function("wpid", &pid_neuro::wpid, emscripten::allow_raw_pointers())
957 .function("zero", &pid_neuro::zero, emscripten::allow_raw_pointers())
958 .function("run", &pid_neuro::run)
959 .function("inc", &pid_neuro::inc)
960 .property<a_float, void>("k", &pid_neuro::k)
961 .property("kp", &pid_neuro::get_kp, &pid_neuro::set_kp)
962 .property("ki", &pid_neuro::get_ki, &pid_neuro::set_ki)
963 .property("kd", &pid_neuro::get_kd, &pid_neuro::set_kd)
964 .property<a_float, void>("wp", &pid_neuro::wp)
965 .property<a_float, void>("wi", &pid_neuro::wi)
966 .property<a_float, void>("wd", &pid_neuro::wd)
967 .property("outmax", &pid_neuro::get_outmax, &pid_neuro::set_outmax)
968 .property("outmin", &pid_neuro::get_outmin, &pid_neuro::set_outmin)
969 .property("out", &pid_neuro::get_out)
970 .property("fdb", &pid_neuro::get_fdb)
971 .property("err", &pid_neuro::get_err)
972 .property<a_float const, void>("ec", &pid_neuro::ec);
973 emscripten::class_<tf>("tf")
974 .constructor<emscripten::val, emscripten::val>()
975 .function("set_num", &tf::set_num, emscripten::allow_raw_pointers())
976 .function("set_den", &tf::set_den, emscripten::allow_raw_pointers())
977 .function("zero", &tf::zero, emscripten::allow_raw_pointers())
978 .function("iter", &tf::operator())
979 .property("input", &tf::get_input)
980 .property("output", &tf::get_output)
981 .property("num", &tf::get_num, &tf::set_num)
982 .property("den", &tf::get_den, &tf::set_den);
983 emscripten::class_<trajbell>("trajbell")
984 .constructor<>()
985 .function("gen", &trajbell::gen)
986 .function("pos", &trajbell::pos)
987 .function("vel", &trajbell::vel)
988 .function("acc", &trajbell::acc)
989 .function("jer", &trajbell::jer)
990 .property<a_float const, void>("t", &trajbell::t)
991 .property<a_float const, void>("tv", &trajbell::tv)
992 .property<a_float const, void>("ta", &trajbell::ta)
993 .property<a_float const, void>("td", &trajbell::td)
994 .property<a_float const, void>("taj", &trajbell::taj)
995 .property<a_float const, void>("tdj", &trajbell::tdj)
996 .property<a_float const, void>("p0", &trajbell::p0)
997 .property<a_float const, void>("p1", &trajbell::p1)
998 .property<a_float const, void>("v0", &trajbell::v0)
999 .property<a_float const, void>("v1", &trajbell::v1)
1000 .property<a_float const, void>("vm", &trajbell::vm)
1001 .property<a_float const, void>("jm", &trajbell::jm)
1002 .property<a_float const, void>("am", &trajbell::am)
1003 .property<a_float const, void>("dm", &trajbell::dm);
1004 emscripten::class_<trajpoly3>("trajpoly3")
1005 .constructor<a_float, a_float, a_float>()
1006 .constructor<a_float, a_float, a_float, a_float, a_float>()
1007 .function("pos", &trajpoly3::pos)
1008 .function("vel", &trajpoly3::vel)
1009 .function("acc", &trajpoly3::acc)
1010 .property("p", &trajpoly3::get_p)
1011 .property("v", &trajpoly3::get_v)
1012 .property("a", &trajpoly3::get_a);
1013 emscripten::class_<trajpoly5>("trajpoly5")
1014 .constructor<a_float, a_float, a_float>()
1015 .constructor<a_float, a_float, a_float, a_float, a_float>()
1016 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1017 .function("pos", &trajpoly5::pos)
1018 .function("vel", &trajpoly5::vel)
1019 .function("acc", &trajpoly5::acc)
1020 .property("p", &trajpoly5::get_p)
1021 .property("v", &trajpoly5::get_v)
1022 .property("a", &trajpoly5::get_a);
1023 emscripten::class_<trajpoly7>("trajpoly7")
1024 .constructor<a_float, a_float, a_float>()
1025 .constructor<a_float, a_float, a_float, a_float, a_float>()
1026 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1027 .constructor<a_float, a_float, a_float, a_float, a_float, a_float, a_float, a_float, a_float>()
1028 .function("pos", &trajpoly7::pos)
1029 .function("vel", &trajpoly7::vel)
1030 .function("acc", &trajpoly7::acc)
1031 .function("jer", &trajpoly7::jer)
1032 .property("p", &trajpoly7::get_p)
1033 .property("v", &trajpoly7::get_v)
1034 .property("a", &trajpoly7::get_a)
1035 .property("j", &trajpoly7::get_j);
1036 emscripten::class_<trajtrap>("trajtrap")
1037 .constructor<>()
1038 .function("gen", &trajtrap::gen)
1039 .function("pos", &trajtrap::pos)
1040 .function("vel", &trajtrap::vel)
1041 .function("acc", &trajtrap::acc)
1042 .property<a_float const, void>("t", &trajtrap::t)
1043 .property<a_float const, void>("p0", &trajtrap::p0)
1044 .property<a_float const, void>("p1", &trajtrap::p1)
1045 .property<a_float const, void>("v0", &trajtrap::v0)
1046 .property<a_float const, void>("v1", &trajtrap::v1)
1047 .property<a_float const, void>("vc", &trajtrap::vc)
1048 .property<a_float const, void>("ta", &trajtrap::ta)
1049 .property<a_float const, void>("td", &trajtrap::td)
1050 .property<a_float const, void>("pa", &trajtrap::pa)
1051 .property<a_float const, void>("pd", &trajtrap::pd)
1052 .property<a_float const, void>("ac", &trajtrap::ac)
1053 .property<a_float const, void>("de", &trajtrap::de);
1054 emscripten::class_<version>("version")
1055 .constructor<>()
1056 .constructor<a_uint>()
1057 .constructor<a_uint, a_uint>()
1058 .constructor<a_uint, a_uint, a_uint>()
1059 .constructor<a_uint, a_uint, a_uint, a_uint>()
1060 .property<a_uint, void>("major", &a_version::major)
1061 .property<a_uint, void>("minor", &a_version::minor)
1062 .property<a_uint, void>("third", &a_version::third)
1063 .property<a_uint, void>("extra", &a_version::extra)
1064 .function("toString", &version::toString)
1065 .function("parse", &version::parse, emscripten::allow_raw_pointers())
1066 .function("cmp", &version::cmp)
1067 .function("lt", &version::operator<)
1068 .function("gt", &version::operator>)
1069 .function("le", &version::operator<=)
1070 .function("ge", &version::operator>=)
1071 .function("eq", &version::operator==)
1072 .function("ne", &version::operator!=)
1073 .class_function("check", &a_version_check)
1074 .class_property("MAJOR", &a_version::MAJOR)
1075 .class_property("MINOR", &a_version::MINOR)
1076 .class_property("PATCH", &a_version::PATCH)
1077 .class_property("TWEAK", &a_version::TWEAK);
1078 emscripten::constant("VERSION", std::string(A_VERSION));
1079 #if defined(__has_feature) && __has_feature(address_sanitizer)
1080 emscripten::function("do_leak_check", &__lsan_do_recoverable_leak_check);
1081 #endif /* -fsanitize=address */