31#ifndef OOJS_POC_HARNESS
39static JSValue
VectorGetProperty(JSContext* context, JSValueConst
this,
int magic);
40static JSValue
VectorSetProperty(JSContext* context, JSValueConst
this, JSValueConst value,
int magic);
42static JSValue
VectorConstruct(JSContext* context, JSValueConst newTarget,
int argc, JSValueConst* argv);
62#ifndef OOJS_POC_HARNESS
74 .class_name =
"Vector3D",
100#ifndef OOJS_POC_HARNESS
113#ifndef OOJS_POC_HARNESS
151 assert(outValue != NULL);
165 = malloc(
sizeof *
private);
167 return JS_ThrowOutOfMemory(context);
176 JS_SetOpaque(result,
private);
187 assert(outValue != NULL);
191 *outValue = JS_UNDEFINED;
227 JSValue element = JS_GetPropertyUint32(context, array, index);
228 int status = JS_IsException(element) ? -1 : JS_ToFloat64(context, outNumber, element);
229 JS_FreeValue(context, element);
237 assert(outVector != NULL);
251 if (
EXPECT(
private != NULL)) {
252 *outVector = *
private;
257 if (
EXPECT(JS_IsArray(vectorObj))) {
259 if (JS_GetLength(context, vectorObj, &arrayLength) == 0 && arrayLength == 3) {
272 Entity* entity = [(id)JS_GetAnyOpaque(vectorObj, &ignored) weakRefUnderlyingObject];
300 OOJSReportBadArguments(context,
@"Vector3D", method, 1, &vectorObj,
@"Invalid target object",
@"Vector3D");
344 assert(argv != NULL && outVector != NULL);
346 if (outConsumed != NULL)
350 if (JS_IsObject(argv[0])) {
352 if (outConsumed != NULL)
358 if (!permitNumberList)
366 if (
EXPECT_NOT(JS_ToFloat64(context, &
x, argv[0]) < 0 || isnan(
x)))
368 if (
EXPECT_NOT(JS_ToFloat64(context, &
y, argv[1]) < 0 || isnan(
y)))
370 if (
EXPECT_NOT(JS_ToFloat64(context, &z, argv[2]) < 0 || isnan(z)))
375 if (outConsumed != NULL)
390 @"Could not construct vector from parameters",
391 @"Vector, Entity or array of three numbers");
431 return JS_NewFloat64(context, fValue);
436static JSValue
VectorSetProperty(JSContext* context, JSValueConst
this, JSValueConst value,
int magic)
445 if (
EXPECT_NOT(JS_ToFloat64(context, &dval, value) < 0)) {
446 JS_FreeValue(context, JS_GetException(context));
484static JSValue
VectorConstruct(JSContext* context, JSValueConst newTarget,
int argc, JSValueConst* argv)
493 @"Could not construct vector from parameters",
494 @"Vector, Entity or array of three numbers");
531 NSString* str = [NSString stringWithFormat:@"Vector3D(%g, %g, %g)", thisv.x, thisv.y, thisv.z];
675 result = acos(result);
847 JSValue result = JS_NewArray(context);
852 if (JS_SetPropertyUint32(context, result, 0, JS_NewFloat64(context, thisv.x)) < 0 || JS_SetPropertyUint32(context, result, 1, JS_NewFloat64(context, thisv.y)) < 0 || JS_SetPropertyUint32(context, result, 2, JS_NewFloat64(context, thisv.z)) < 0) {
853 JS_FreeValue(context, result);
875 JSValueConst* inArgv = argv;
878 goto INSUFFICIENT_ARGUMENTS;
884 goto INSUFFICIENT_ARGUMENTS;
890 goto INSUFFICIENT_ARGUMENTS;
898INSUFFICIENT_ARGUMENTS:
900 @"Insufficient parameters",
901 @"vector expression, vector expression and number");
952#ifndef OOJS_POC_HARNESS
959 NSString* coordScheme =
nil;
973 result = [UNIVERSE legacyPositionFrom:thisv asCoordinateSystem:coordScheme];
987 NSString* coordScheme =
nil;
1001 NSString* arg = [NSString stringWithFormat:@"%@ %f %f %f", coordScheme, thisv.x, thisv.y, thisv.z];
1002 result = [UNIVERSE coordinatesFromCoordinateSystemString:arg];
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
const HPVector kZeroHPVector
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
HPVector OORandomUnitHPVector(void)
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
OOINLINE HPVector HPtrue_cross_product(HPVector first, HPVector second) CONST_FUNC
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
OOINLINE OOHPScalar HPtriple_product(HPVector first, HPVector second, HPVector third) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
OOINLINE HPVector OOHPVectorInterpolate(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_EXIT_VOID
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_PROFILE_ENTER
BOOL QuaternionFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Quaternion *outQuaternion, uintN *outConsumed) GCC_ATTR((nonnull(1
static JSBool VectorStaticRandomDirectionAndLength(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorFromCoordinateSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToArray(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorAdd(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToString(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorCross(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorSubtract(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticInterpolate(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorRotateBy(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToCoordinateSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorDistanceTo(JSContext *context, uintN argc, jsval *vp)
void InitOOJSVector(JSContext *context, JSObject *global)
static JSBool VectorMagnitude(JSContext *context, uintN argc, jsval *vp)
static JSPropertySpec sVectorProperties[]
static JSBool VectorDot(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorRotationTo(JSContext *context, uintN argc, jsval *vp)
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector)
static JSFunctionSpec sVectorMethods[]
static JSBool VectorTripleProduct(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorDirection(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorAngleTo(JSContext *context, uintN argc, jsval *vp)
static JSFunctionSpec sVectorStaticMethods[]
BOOL JSValueToHPVector(JSContext *context, jsval value, HPVector *outVector)
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
static void VectorFinalize(JSContext *context, JSObject *this)
static JSBool VectorStaticRandom(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToSource(JSContext *context, uintN argc, jsval *vp)
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue)
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
JSObject * JSVectorWithVector(JSContext *context, Vector vector)
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static BOOL GetThisVector(JSContext *context, JSObject *vectorObj, HPVector *outVector, NSString *method) NONNULL_FUNC
static JSBool VectorSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool VectorSquaredMagnitude(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorSquaredDistanceTo(JSContext *context, uintN argc, jsval *vp)
BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue)
static JSClass sVectorClass
static JSBool VectorMultiply(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandomDirection(JSContext *context, uintN argc, jsval *vp)
BOOL OOJSArgumentListGetNumberNoError(JSContext *context, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)
#define OOJS_PROP_READWRITE_CB
#define OOJS_RETURN_DOUBLE(value)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE BOOL OOJSIsMemberOfSubclass(JSContext *context, JSObject *object, JSClass *superclass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define OOJS_RETURN_QUATERNION(value)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_RETURN_HPVECTOR(value)
Quaternion quaternion_rotation_between(Vector v0, Vector v1) CONST_FUNC
HPVector quaternion_rotate_HPvector(Quaternion q, HPVector vector) CONST_FUNC
Quaternion quaternion_limited_rotation_between(Vector v0, Vector v1, float maxArc) CONST_FUNC
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
JSClassID JSEntityClassID(void)
BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed)
static JSClassID sVectorClassID
BOOL JSVectorSetVector(JSContext *context, JSValueConst vectorObj, Vector vector)
static BOOL GetArrayElementNumber(JSContext *context, JSValueConst array, uint32_t index, double *outNumber)
static BOOL VectorFromArgumentListNoErrorInternal(JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed, BOOL permitNumberList)
BOOL JSVectorSetHPVector(JSContext *context, JSValueConst vectorObj, HPVector vector)
BOOL VectorFromArgumentListNoError(JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed)
JSValue OOJSNativeFailure(JSContext *context)
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)