2 #include "a/trajpoly7.h"
4 static JSClassID liba_trajpoly7_class_id
;
6 static void liba_trajpoly7_finalizer(JSRuntime
*rt
, JSValue val
)
8 js_free_rt(rt
, JS_GetOpaque(val
, liba_trajpoly7_class_id
));
11 static JSClassDef liba_trajpoly7_class
= {"trajpoly7", .finalizer
= liba_trajpoly7_finalizer
};
13 static JSValue
liba_trajpoly7_ctor(JSContext
*ctx
, JSValueConst new_target
, int argc
, JSValueConst
*argv
)
15 JSValue proto
, clazz
= JS_UNDEFINED
;
16 a_trajpoly7
*const self
= (a_trajpoly7
*)js_mallocz(ctx
, sizeof(a_trajpoly7
));
17 if (!self
) { return JS_EXCEPTION
; }
18 double args
[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
19 if (argc
> (int)A_LEN(args
)) { argc
= (int)A_LEN(args
); }
20 for (int i
= 0; i
< 3; ++i
)
22 if (JS_ToFloat64(ctx
, &args
[i
], argv
[i
])) { goto fail
; }
24 for (int i
= 3; i
< argc
; ++i
)
26 if (JS_ToFloat64(ctx
, &args
[i
], argv
[i
])) { goto fail
; }
28 a_trajpoly7_gen(self
, (a_float
)args
[0],
29 (a_float
)args
[1], (a_float
)args
[2],
30 (a_float
)args
[3], (a_float
)args
[4],
31 (a_float
)args
[5], (a_float
)args
[6],
32 (a_float
)args
[7], (a_float
)args
[8]);
33 proto
= JS_GetPropertyStr(ctx
, new_target
, "prototype");
34 if (JS_IsException(proto
)) { goto fail
; }
35 clazz
= JS_NewObjectProtoClass(ctx
, proto
, liba_trajpoly7_class_id
);
36 JS_FreeValue(ctx
, proto
);
37 if (JS_IsException(clazz
)) { goto fail
; }
38 JS_SetOpaque(clazz
, self
);
42 JS_FreeValue(ctx
, clazz
);
46 static JSValue
liba_trajpoly7_get(JSContext
*ctx
, JSValueConst this_val
, int magic
)
48 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
49 if (!self
) { return JS_EXCEPTION
; }
52 case 0: return js_array_num_new(ctx
, self
->p
, A_LEN(self
->p
));
53 case 1: return js_array_num_new(ctx
, self
->v
, A_LEN(self
->v
));
54 case 2: return js_array_num_new(ctx
, self
->a
, A_LEN(self
->a
));
55 case 3: return js_array_num_new(ctx
, self
->j
, A_LEN(self
->j
));
56 default: return JS_UNDEFINED
;
60 static JSValue
liba_trajpoly7_gen(JSContext
*ctx
, JSValueConst this_val
, int argc
, JSValueConst
*argv
)
62 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
63 if (!self
) { return JS_EXCEPTION
; }
64 double args
[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
65 if (argc
> (int)A_LEN(args
)) { argc
= (int)A_LEN(args
); }
66 for (int i
= 0; i
< 3; ++i
)
68 if (JS_ToFloat64(ctx
, &args
[i
], argv
[i
])) { return JS_EXCEPTION
; }
70 for (int i
= 3; i
< argc
; ++i
)
72 if (JS_ToFloat64(ctx
, &args
[i
], argv
[i
])) { return JS_EXCEPTION
; }
74 a_trajpoly7_gen(self
, (a_float
)args
[0],
75 (a_float
)args
[1], (a_float
)args
[2],
76 (a_float
)args
[3], (a_float
)args
[4],
77 (a_float
)args
[5], (a_float
)args
[6],
78 (a_float
)args
[7], (a_float
)args
[8]);
82 static JSValue
liba_trajpoly7_pos(JSContext
*ctx
, JSValueConst this_val
, int argc
, JSValueConst
*argv
)
85 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
86 if (!self
) { return JS_EXCEPTION
; }
88 if (JS_ToFloat64(ctx
, &dt
, argv
[0])) { return JS_EXCEPTION
; }
89 a_float pos
= a_trajpoly7_pos(self
, (a_float
)dt
);
90 return JS_NewFloat64(ctx
, (double)pos
);
93 static JSValue
liba_trajpoly7_vel(JSContext
*ctx
, JSValueConst this_val
, int argc
, JSValueConst
*argv
)
96 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
97 if (!self
) { return JS_EXCEPTION
; }
99 if (JS_ToFloat64(ctx
, &dt
, argv
[0])) { return JS_EXCEPTION
; }
100 a_float vel
= a_trajpoly7_vel(self
, (a_float
)dt
);
101 return JS_NewFloat64(ctx
, (double)vel
);
104 static JSValue
liba_trajpoly7_acc(JSContext
*ctx
, JSValueConst this_val
, int argc
, JSValueConst
*argv
)
107 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
108 if (!self
) { return JS_EXCEPTION
; }
110 if (JS_ToFloat64(ctx
, &dt
, argv
[0])) { return JS_EXCEPTION
; }
111 a_float acc
= a_trajpoly7_acc(self
, (a_float
)dt
);
112 return JS_NewFloat64(ctx
, (double)acc
);
115 static JSValue
liba_trajpoly7_jer(JSContext
*ctx
, JSValueConst this_val
, int argc
, JSValueConst
*argv
)
118 a_trajpoly7
*const self
= (a_trajpoly7
*)JS_GetOpaque2(ctx
, this_val
, liba_trajpoly7_class_id
);
119 if (!self
) { return JS_EXCEPTION
; }
121 if (JS_ToFloat64(ctx
, &dt
, argv
[0])) { return JS_EXCEPTION
; }
122 a_float jer
= a_trajpoly7_jer(self
, (a_float
)dt
);
123 return JS_NewFloat64(ctx
, (double)jer
);
126 static JSCFunctionListEntry
const liba_trajpoly7_proto
[] = {
127 JS_PROP_STRING_DEF("[Symbol.toStringTag]", "a.trajpoly7", 0),
128 JS_CGETSET_MAGIC_DEF("p", liba_trajpoly7_get
, NULL
, 0),
129 JS_CGETSET_MAGIC_DEF("v", liba_trajpoly7_get
, NULL
, 1),
130 JS_CGETSET_MAGIC_DEF("a", liba_trajpoly7_get
, NULL
, 2),
131 JS_CGETSET_MAGIC_DEF("j", liba_trajpoly7_get
, NULL
, 3),
132 JS_CFUNC_DEF("gen", 9, liba_trajpoly7_gen
),
133 JS_CFUNC_DEF("pos", 1, liba_trajpoly7_pos
),
134 JS_CFUNC_DEF("vel", 1, liba_trajpoly7_vel
),
135 JS_CFUNC_DEF("acc", 1, liba_trajpoly7_acc
),
136 JS_CFUNC_DEF("jer", 1, liba_trajpoly7_jer
),
139 int js_liba_trajpoly7_init(JSContext
*ctx
, JSModuleDef
*m
)
141 JS_NewClassID(&liba_trajpoly7_class_id
);
142 JS_NewClass(JS_GetRuntime(ctx
), liba_trajpoly7_class_id
, &liba_trajpoly7_class
);
144 JSValue
const proto
= JS_NewObject(ctx
);
145 JS_SetPropertyFunctionList(ctx
, proto
, liba_trajpoly7_proto
, A_LEN(liba_trajpoly7_proto
));
147 JSValue
const clazz
= JS_NewCFunction2(ctx
, liba_trajpoly7_ctor
, "trajpoly7", 9, JS_CFUNC_constructor
, 0);
148 JS_SetConstructor(ctx
, clazz
, proto
);
149 JS_SetClassProto(ctx
, liba_trajpoly7_class_id
, proto
);
151 return JS_SetModuleExport(ctx
, m
, "trajpoly7", clazz
);