Oolite
Loading...
Searching...
No Matches
OOJSVector.m File Reference
import "OOJSVector.h"
import "OOJavaScriptEngine.h"
import <objc/objc-runtime.h>
import "OOConstToString.h"
import "OOJSEntity.h"
import "OOJSQuaternion.h"
Include dependency graph for OOJSVector.m:

Go to the source code of this file.

Macros

#define COUNT(FIELD)

Enumerations

enum  { kVector_x , kVector_y , kVector_z }

Functions

static BOOL GetThisVector (JSContext *context, JSObject *vectorObj, HPVector *outVector, NSString *method) NONNULL_FUNC
static JSBool VectorGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool VectorSetProperty (JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static void VectorFinalize (JSContext *context, JSObject *this)
static JSBool VectorConstruct (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToString (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToSource (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorAdd (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorSubtract (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorDistanceTo (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorSquaredDistanceTo (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorMultiply (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorDot (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorAngleTo (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorFromCoordinateSystem (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToCoordinateSystem (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorCross (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorTripleProduct (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorDirection (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorMagnitude (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorSquaredMagnitude (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorRotationTo (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorRotateBy (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToArray (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticInterpolate (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandom (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandomDirection (JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandomDirectionAndLength (JSContext *context, uintN argc, jsval *vp)
void InitOOJSVector (JSContext *context, JSObject *global)
JSObject * JSVectorWithVector (JSContext *context, Vector vector)
BOOL VectorToJSValue (JSContext *context, Vector vector, jsval *outValue)
JSObject * JSVectorWithHPVector (JSContext *context, HPVector vector)
BOOL HPVectorToJSValue (JSContext *context, HPVector vector, jsval *outValue)
BOOL NSPointToVectorJSValue (JSContext *context, NSPoint point, jsval *outValue)
BOOL JSValueToHPVector (JSContext *context, jsval value, HPVector *outVector)
BOOL JSValueToVector (JSContext *context, jsval value, Vector *outVector)
BOOL JSObjectGetVector (JSContext *context, JSObject *vectorObj, HPVector *outVector)
BOOL JSVectorSetVector (JSContext *context, JSObject *vectorObj, Vector vector)
BOOL JSVectorSetHPVector (JSContext *context, JSObject *vectorObj, HPVector vector)
static BOOL VectorFromArgumentListNoErrorInternal (JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed, BOOL permitNumberList)
BOOL VectorFromArgumentList (JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed)
BOOL VectorFromArgumentListNoError (JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed)

Variables

static JSObject * sVectorPrototype
static JSClass sVectorClass
static JSPropertySpec sVectorProperties []
static JSFunctionSpec sVectorMethods []
static JSFunctionSpec sVectorStaticMethods []

Macro Definition Documentation

◆ COUNT

#define COUNT ( FIELD)
Value:
do { \
} while (0)

Definition at line 409 of file OOJSVector.m.

409#define COUNT(FIELD) \
410 do { \
411 } while (0)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kVector_x 
kVector_y 
kVector_z 

Definition at line 89 of file OOJSVector.m.

89 {
90 // Property IDs
94};
@ kVector_z
Definition OOJSVector.m:93
@ kVector_x
Definition OOJSVector.m:91
@ kVector_y
Definition OOJSVector.m:92

Function Documentation

◆ GetThisVector()

BOOL GetThisVector ( JSContext * context,
JSObject * vectorObj,
HPVector * outVector,
NSString * method )
static

Definition at line 483 of file OOJSVector.m.

484{
485 if (EXPECT(JSObjectGetVector(context, vectorObj, outVector)))
486 return YES;
487
488 jsval arg = OBJECT_TO_JSVAL(vectorObj);
489 OOJSReportBadArguments(context, @"Vector3D", method, 1, &arg, @"Invalid target object", @"Vector3D");
490 return NO;
491}
#define EXPECT(x)
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
Definition OOJSVector.m:415
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)

References EXPECT, JSObjectGetVector(), and OOJSReportBadArguments().

Referenced by VectorAdd(), VectorAdd(), VectorAngleTo(), VectorAngleTo(), VectorCross(), VectorCross(), VectorDirection(), VectorDirection(), VectorDistanceTo(), VectorDistanceTo(), VectorDot(), VectorDot(), VectorFromCoordinateSystem(), VectorFromCoordinateSystem(), VectorMagnitude(), VectorMagnitude(), VectorMultiply(), VectorMultiply(), VectorRotateBy(), VectorRotateBy(), VectorRotationTo(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorSquaredDistanceTo(), VectorSquaredMagnitude(), VectorSquaredMagnitude(), VectorSubtract(), VectorSubtract(), VectorToArray(), VectorToArray(), VectorToCoordinateSystem(), VectorToCoordinateSystem(), VectorToSource(), VectorToSource(), VectorToString(), VectorToString(), VectorTripleProduct(), and VectorTripleProduct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HPVectorToJSValue()

BOOL HPVectorToJSValue ( JSContext * context,
HPVector vector,
jsval * outValue )

Definition at line 310 of file OOJSVector.m.

311{
313
314 JSObject* object = NULL;
315
316 assert(outValue != NULL);
317
318 object = JSVectorWithHPVector(context, vector);
319 if (EXPECT_NOT(object == NULL))
320 return NO;
321
322 *outValue = OBJECT_TO_JSVAL(object);
323 return YES;
324
326}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
Definition OOJSVector.m:282

References EXPECT_NOT, JSVectorWithHPVector(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by EntityGetProperty(), ShipGetProperty(), and VectorToJSValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitOOJSVector()

void InitOOJSVector ( JSContext * context,
JSObject * global )

Definition at line 231 of file OOJSVector.m.

232{
233 sVectorPrototype = JS_InitClass(context, global, NULL, &sVectorClass, VectorConstruct, 0, sVectorProperties, sVectorMethods, NULL, sVectorStaticMethods);
234}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:96
static JSObject * sVectorPrototype
Definition OOJSVector.m:38
static JSFunctionSpec sVectorMethods[]
Definition OOJSVector.m:104
static JSFunctionSpec sVectorStaticMethods[]
Definition OOJSVector.m:204
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:683
static JSClass sVectorClass
Definition OOJSVector.m:74

References sVectorClass, sVectorMethods, sVectorProperties, sVectorPrototype, sVectorStaticMethods, and VectorConstruct().

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSObjectGetVector()

BOOL JSObjectGetVector ( JSContext * context,
JSObject * vectorObj,
HPVector * outVector )

Definition at line 415 of file OOJSVector.m.

416{
418
419 assert(outVector != NULL);
420
421 HPVector* private = NULL;
422 jsuint arrayLength;
423 jsval arrayX, arrayY, arrayZ;
424 jsdouble x, y, z;
425
426 // vectorObj can legitimately be NULL, e.g. when JS_NULL is converted to a JSObject *.
427 if (EXPECT_NOT(vectorObj == NULL)) {
428 COUNT(nullCount);
429 return NO;
430 }
431
432 // If this is a (JS) Vector...
433private
434 = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
435 if (EXPECT(private != NULL)) {
436 COUNT(vectorCount);
437 *outVector = *private;
438 return YES;
439 }
440
441 // If it's an array...
442 if (EXPECT(JS_IsArrayObject(context, vectorObj))) {
443 // ...and it has exactly three elements...
444 if (JS_GetArrayLength(context, vectorObj, &arrayLength) && arrayLength == 3) {
445 if (JS_LookupElement(context, vectorObj, 0, &arrayX) && JS_LookupElement(context, vectorObj, 1, &arrayY) && JS_LookupElement(context, vectorObj, 2, &arrayZ)) {
446 // ...use the three numbers as [x, y, z]
447 if (JS_ValueToNumber(context, arrayX, &x) && JS_ValueToNumber(context, arrayY, &y) && JS_ValueToNumber(context, arrayZ, &z)) {
448 COUNT(arrayCount);
449 *outVector = make_HPvector(x, y, z);
450 return YES;
451 }
452 }
453 }
454 }
455
456 // If it's an entity, use its position.
457 if (OOJSIsMemberOfSubclass(context, vectorObj, JSEntityClass())) {
458 COUNT(entityCount);
459 Entity* entity = [(id)JS_GetPrivate(context, vectorObj) weakRefUnderlyingObject];
460 *outVector = [entity position];
461 return YES;
462 }
463
464 /*
465 If it's actually a Vector3D but with no private field (this happens for
466 Vector3D.prototype)...
467
468 NOTE: it would be prettier to do this at the top when we handle normal
469 Vector3Ds, but it's a rare case which should be kept off the fast path.
470 */
471 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL)) {
472 COUNT(protoCount);
473 *outVector = kZeroHPVector;
474 return YES;
475 }
476
477 COUNT(failCount);
478 return NO;
479
481}
const HPVector kZeroHPVector
Definition OOHPVector.m:27
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
#define COUNT(FIELD)
Definition OOJSVector.m:409
OOINLINE BOOL OOJSIsMemberOfSubclass(JSContext *context, JSObject *object, JSClass *superclass)
float y
float x
HPVector position
Definition Entity.m:576

References COUNT, EXPECT, EXPECT_NOT, JSEntityClass(), kZeroHPVector, make_HPvector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSIsMemberOfSubclass(), Entity::position, sVectorClass, x, and y.

Referenced by GetThisVector(), JSValueToHPVector(), JSValueToHPVector(), JSValueToVector(), JSValueToVector(), VectorFromArgumentListNoErrorInternal(), VectorGetProperty(), and VectorSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSValueToHPVector()

BOOL JSValueToHPVector ( JSContext * context,
jsval value,
HPVector * outVector )

Definition at line 333 of file OOJSVector.m.

334{
335 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value)))
336 return NO;
337
338 return JSObjectGetVector(context, JSVAL_TO_OBJECT(value), outVector);
339}

References EXPECT_NOT, and JSObjectGetVector().

Referenced by EntitySetProperty(), EntitySetProperty(), ShipSetProperty(), ShipSetProperty(), SystemSetWaypoint(), and SystemSetWaypoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSValueToVector()

BOOL JSValueToVector ( JSContext * context,
jsval value,
Vector * outVector )

Definition at line 341 of file OOJSVector.m.

342{
343 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value)))
344 return NO;
346 BOOL result = JSObjectGetVector(context, JSVAL_TO_OBJECT(value), &tmp);
347 *outVector = HPVectorToVector(tmp);
348 return result;
349}
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175

References EXPECT_NOT, HPVectorToVector(), JSObjectGetVector(), and kZeroHPVector.

Referenced by ExhaustPlumeSetProperty(), ExhaustPlumeSetProperty(), MissionRunScreen(), MissionRunScreen(), PlanetSetProperty(), PlanetSetProperty(), PlayerShipSetCustomView(), PlayerShipSetCustomView(), PlayerShipSetProperty(), PlayerShipSetProperty(), ShipEntity(Private)::refreshEscortPositions, ShipSetProperty(), ShipSetProperty(), SoundSourceSetProperty(), SoundSourceSetProperty(), SystemSetPopulator(), SystemSetPopulator(), VisualEffectSetProperty(), and VisualEffectSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ JSVectorSetHPVector()

BOOL JSVectorSetHPVector ( JSContext * context,
JSObject * vectorObj,
HPVector vector )

Definition at line 498 of file OOJSVector.m.

499{
501
502 HPVector* private = NULL;
503
504 if (EXPECT_NOT(vectorObj == NULL))
505 return NO;
506
507private
508 = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
509 if (private != NULL) // If this is a (JS) Vector...
510 {
511 *private = vector;
512 return YES;
513 }
514
515 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL)) {
516 // Silently fail for the prototype.
517 return YES;
518 }
519
520 return NO;
521
523}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sVectorClass.

Referenced by JSVectorSetVector(), and VectorSetProperty().

Here is the caller graph for this function:

◆ JSVectorSetVector()

BOOL JSVectorSetVector ( JSContext * context,
JSObject * vectorObj,
Vector vector )

Definition at line 493 of file OOJSVector.m.

494{
495 return JSVectorSetHPVector(context, vectorObj, vectorToHPVector(vector));
496}
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
BOOL JSVectorSetHPVector(JSContext *context, JSValueConst vectorObj, HPVector vector)
Definition OOJSVector.m:309

References JSVectorSetHPVector(), and vectorToHPVector().

Here is the call graph for this function:

◆ JSVectorWithHPVector()

JSObject * JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 282 of file OOJSVector.m.

283{
285
286 JSObject* result = NULL;
287 HPVector* private = NULL;
288
289private
290 = malloc(sizeof *private);
291 if (EXPECT_NOT(private == NULL))
292 return NULL;
293
294 *private = vector;
295
296 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
297 if (result != NULL) {
298 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
299 result = NULL;
300 }
301
302 if (EXPECT_NOT(result == NULL))
303 free(private);
304
305 return result;
306
308}

Referenced by HPVectorToJSValue(), HPVectorToJSValue(), JSVectorWithVector(), and VectorConstruct().

Here is the caller graph for this function:

◆ JSVectorWithVector()

JSObject * JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 236 of file OOJSVector.m.

237{
239
240 JSObject* result = NULL;
241 HPVector* private = NULL;
242
243private
244 = malloc(sizeof *private);
245 if (EXPECT_NOT(private == NULL))
246 return NULL;
247
248 *private = vectorToHPVector(vector);
249
250 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
251 if (result != NULL) {
252 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
253 result = NULL;
254 }
255
256 if (EXPECT_NOT(result == NULL))
257 free(private);
258
259 return result;
260
262}

Referenced by VectorToJSValue().

Here is the caller graph for this function:

◆ NSPointToVectorJSValue()

BOOL NSPointToVectorJSValue ( JSContext * context,
NSPoint point,
jsval * outValue )

Definition at line 328 of file OOJSVector.m.

329{
330 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
331}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
Definition OOJSVector.m:264
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References make_vector(), and VectorToJSValue().

Referenced by PlayerShipGetProperty(), PlayerShipGetProperty(), SystemInfoGetProperty(), and SystemInfoGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VectorAdd()

JSBool VectorAdd ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 756 of file OOJSVector.m.

757{
759
760 HPVector thisv, thatv, result;
761
762 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"add")))
763 return NO;
764 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"add", argc, OOJS_ARGV, &thatv, NULL)))
765 return NO;
766
767 result = HPvector_add(thisv, thatv);
768
769 OOJS_RETURN_HPVECTOR(result);
770
772}
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
static BOOL GetThisVector(JSContext *context, JSObject *vectorObj, HPVector *outVector, NSString *method) NONNULL_FUNC
Definition OOJSVector.m:483
#define OOJS_THIS
#define OOJS_ARGV
#define OOJS_RETURN_HPVECTOR(value)
BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed)
Definition OOJSVector.m:384

References EXPECT_NOT, GetThisVector(), HPvector_add(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorAngleTo()

JSBool VectorAngleTo ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 874 of file OOJSVector.m.

875{
877
878 HPVector thisv, thatv;
879 double result;
880
881 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"angleTo")))
882 return NO;
883 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"angleTo", argc, OOJS_ARGV, &thatv, NULL)))
884 return NO;
885
886 result = HPdot_product(HPvector_normal(thisv), HPvector_normal(thatv));
887 if (result > 1.0)
888 result = 1.0;
889 if (result < -1.0)
890 result = -1.0;
891 // for identical vectors the dot_product sometimes returns a value > 1.0 because of rounding errors, resulting
892 // in an undefined result for the acos.
893 result = acos(result);
894
895 OOJS_RETURN_DOUBLE(result);
896
898}
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:317
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:288
#define OOJS_RETURN_DOUBLE(value)

References EXPECT_NOT, GetThisVector(), HPdot_product(), HPvector_normal(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorConstruct()

JSBool VectorConstruct ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 683 of file OOJSVector.m.

684{
686
687 HPVector vector = kZeroHPVector;
688 HPVector* private = NULL;
689 JSObject* this = NULL;
690
691private
692 = malloc(sizeof *private);
693 if (EXPECT_NOT(private == NULL))
694 return NO;
695
696 this = JS_NewObject(context, &sVectorClass, NULL, NULL);
697 if (EXPECT_NOT(this == NULL))
698 return NO;
699
700 if (argc != 0) {
701 if (EXPECT_NOT(!VectorFromArgumentListNoErrorInternal(context, argc, OOJS_ARGV, &vector, NULL, YES))) {
702 free(private);
703 OOJSReportBadArguments(context, NULL, NULL, argc, OOJS_ARGV,
704 @"Could not construct vector from parameters",
705 @"Vector, Entity or array of three numbers");
706 return NO;
707 }
708 }
709
710 *private = vector;
711
712 if (EXPECT_NOT(!JS_SetPrivate(context, this, private))) {
713 free(private);
714 return NO;
715 }
716
718
720}
#define OOJS_RETURN_JSOBJECT(o)
static BOOL VectorFromArgumentListNoErrorInternal(JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed, BOOL permitNumberList)
Definition OOJSVector.m:336

References EXPECT_NOT, kZeroHPVector, OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_JSOBJECT, OOJSReportBadArguments(), sVectorClass, and VectorFromArgumentListNoErrorInternal().

Referenced by InitOOJSVector(), and InitOOJSVector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VectorCross()

JSBool VectorCross ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 901 of file OOJSVector.m.

902{
904
905 HPVector thisv, thatv, result;
906
907 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"cross")))
908 return NO;
909 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"cross", argc, OOJS_ARGV, &thatv, NULL)))
910 return NO;
911
912 result = HPtrue_cross_product(thisv, thatv);
913
914 OOJS_RETURN_HPVECTOR(result);
915
917}
OOINLINE HPVector HPtrue_cross_product(HPVector first, HPVector second) CONST_FUNC
Definition OOHPVector.h:303

References EXPECT_NOT, GetThisVector(), HPtrue_cross_product(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorDirection()

JSBool VectorDirection ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 946 of file OOJSVector.m.

947{
949
950 HPVector thisv, result;
951
952 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"direction")))
953 return NO;
954
955 result = HPvector_normal(thisv);
956
957 OOJS_RETURN_HPVECTOR(result);
958
960}

References EXPECT_NOT, GetThisVector(), HPvector_normal(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorDistanceTo()

JSBool VectorDistanceTo ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 794 of file OOJSVector.m.

795{
797
798 HPVector thisv, thatv;
799 double result;
800
801 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"distanceTo")))
802 return NO;
803 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"distanceTo", argc, OOJS_ARGV, &thatv, NULL)))
804 return NO;
805
806 result = HPdistance(thisv, thatv);
807
808 OOJS_RETURN_DOUBLE(result);
809
811}
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298

References EXPECT_NOT, GetThisVector(), HPdistance(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorDot()

JSBool VectorDot ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 854 of file OOJSVector.m.

855{
857
858 HPVector thisv, thatv;
859 double result;
860
861 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"dot")))
862 return NO;
863 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"dot", argc, OOJS_ARGV, &thatv, NULL)))
864 return NO;
865
866 result = HPdot_product(thisv, thatv);
867
868 OOJS_RETURN_DOUBLE(result);
869
871}

References EXPECT_NOT, GetThisVector(), HPdot_product(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorFinalize()

void VectorFinalize ( JSContext * context,
JSObject * this )
static

Definition at line 668 of file OOJSVector.m.

669{
671
672 Vector* private = NULL;
673
674private
675 = JS_GetInstancePrivate(context, this, &sVectorClass, NULL);
676 if (private != NULL) {
677 free(private);
678 }
679
681}
#define OOJS_PROFILE_EXIT_VOID

References OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_VOID, and sVectorClass.

◆ VectorFromArgumentList()

BOOL VectorFromArgumentList ( JSContext * context,
NSString * scriptClass,
NSString * function,
uintN argc,
jsval * argv,
HPVector * outVector,
uintN * outConsumed )

Definition at line 573 of file OOJSVector.m.

574{
575 if (VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO))
576 return YES;
577 else {
578 OOJSReportBadArguments(context, scriptClass, function, argc, argv,
579 @"Could not construct vector from parameters",
580 @"Vector, Entity or array of three numbers");
581 return NO;
582 }
583}

References OOJSReportBadArguments(), and VectorFromArgumentListNoErrorInternal().

Here is the call graph for this function:

◆ VectorFromArgumentListNoError()

BOOL VectorFromArgumentListNoError ( JSContext * context,
uintN argc,
jsval * argv,
HPVector * outVector,
uintN * outConsumed )

Definition at line 585 of file OOJSVector.m.

586{
587 return VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO);
588}

References VectorFromArgumentListNoErrorInternal().

Here is the call graph for this function:

◆ VectorFromArgumentListNoErrorInternal()

BOOL VectorFromArgumentListNoErrorInternal ( JSContext * context,
uintN argc,
jsval * argv,
HPVector * outVector,
uintN * outConsumed,
BOOL permitNumberList )
static

Definition at line 525 of file OOJSVector.m.

526{
528
529 double x, y, z;
530
531 if (EXPECT_NOT(argc == 0))
532 return NO;
533 assert(argv != NULL && outVector != NULL);
534
535 if (outConsumed != NULL)
536 *outConsumed = 0;
537
538 // Is first object a vector, array or entity?
539 if (JSVAL_IS_OBJECT(argv[0])) {
540 if (JSObjectGetVector(context, JSVAL_TO_OBJECT(argv[0]), outVector)) {
541 if (outConsumed != NULL)
542 *outConsumed = 1;
543 return YES;
544 }
545 }
546
547 if (!permitNumberList)
548 return NO;
549
550 // As a special case for VectorConstruct(), look for three numbers.
551 if (argc < 3)
552 return NO;
553
554 // Given a string, JS_ValueToNumber() returns YES but provides a NaN number.
555 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &x) || isnan(x)))
556 return NO;
557 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[1], &y) || isnan(y)))
558 return NO;
559 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[2], &z) || isnan(z)))
560 return NO;
561
562 // We got our three numbers.
563 *outVector = make_HPvector(x, y, z);
564 if (outConsumed != NULL)
565 *outConsumed = 3;
566
567 return YES;
568
570}

References EXPECT_NOT, JSObjectGetVector(), make_HPvector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, x, and y.

Referenced by VectorConstruct(), VectorFromArgumentList(), and VectorFromArgumentListNoError().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VectorFromCoordinateSystem()

JSBool VectorFromCoordinateSystem ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1111 of file OOJSVector.m.

1112{
1113 OOJS_NATIVE_ENTER(context)
1114
1115 HPVector thisv;
1116 NSString* coordScheme = nil;
1117 HPVector result;
1118
1119 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"fromCoordinateSystem")))
1120 return NO;
1121
1122 if (EXPECT_NOT(argc < 1 || (coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil)) {
1123 OOJSReportBadArguments(context, @"Vector3D", @"fromCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
1124 return NO;
1125 }
1126
1127 OOJS_BEGIN_FULL_NATIVE(context)
1128 NSString* arg = [NSString stringWithFormat:@"%@ %f %f %f", coordScheme, thisv.x, thisv.y, thisv.z];
1129 result = [UNIVERSE coordinatesFromCoordinateSystemString:arg];
1131
1132 OOJS_RETURN_HPVECTOR(result);
1133
1135}
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define MIN(A, B)
Definition OOMaths.h:91
return nil

References EXPECT_NOT, GetThisVector(), MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ VectorGetProperty()

JSBool VectorGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 592 of file OOJSVector.m.

593{
594 if (!JSID_IS_INT(propID))
595 return YES;
596
598
599 HPVector vector;
600 OOHPScalar fValue;
601
602 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector)))
603 return NO;
604
605 switch (JSID_TO_INT(propID)) {
606 case kVector_x:
607 fValue = vector.x;
608 break;
609
610 case kVector_y:
611 fValue = vector.y;
612 break;
613
614 case kVector_z:
615 fValue = vector.z;
616 break;
617
618 default:
619 OOJSReportBadPropertySelector(context, this, propID, sVectorProperties);
620 return NO;
621 }
622
623 return JS_NewNumberValue(context, fValue, value);
624
626}
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
double OOHPScalar
Definition OOMaths.h:51

References EXPECT_NOT, JSObjectGetVector(), kVector_x, kVector_y, kVector_z, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSReportBadPropertySelector(), and sVectorProperties.

Here is the call graph for this function:

◆ VectorMagnitude()

JSBool VectorMagnitude ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 963 of file OOJSVector.m.

964{
966
967 HPVector thisv;
968 double result;
969
970 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"magnitude")))
971 return NO;
972
973 result = HPmagnitude(thisv);
974
975 OOJS_RETURN_DOUBLE(result);
976
978}
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260

References EXPECT_NOT, GetThisVector(), HPmagnitude(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorMultiply()

JSBool VectorMultiply ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 834 of file OOJSVector.m.

835{
837
838 HPVector thisv, result;
839 double scalar;
840
841 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"multiply")))
842 return NO;
843 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"multiply", argc, OOJS_ARGV, &scalar, NULL)))
844 return NO;
845
846 result = HPvector_multiply_scalar(thisv, scalar);
847
848 OOJS_RETURN_HPVECTOR(result);
849
851}
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
Definition OOHPVector.h:198
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)

References EXPECT_NOT, GetThisVector(), HPvector_multiply_scalar(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and OOJSArgumentListGetNumber().

Here is the call graph for this function:

◆ VectorRotateBy()

JSBool VectorRotateBy ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1036 of file OOJSVector.m.

1037{
1039
1040 HPVector thisv, result;
1041 Quaternion q;
1042
1043 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotateBy")))
1044 return NO;
1045 if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Vector3D", @"rotateBy", argc, OOJS_ARGV, &q, NULL)))
1046 return NO;
1047
1048 result = quaternion_rotate_HPvector(q, thisv);
1049
1050 OOJS_RETURN_HPVECTOR(result);
1051
1053}
BOOL QuaternionFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Quaternion *outQuaternion, uintN *outConsumed) GCC_ATTR((nonnull(1
HPVector quaternion_rotate_HPvector(Quaternion q, HPVector vector) CONST_FUNC

References EXPECT_NOT, GetThisVector(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, quaternion_rotate_HPvector(), and QuaternionFromArgumentList().

Here is the call graph for this function:

◆ VectorRotationTo()

JSBool VectorRotationTo ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 999 of file OOJSVector.m.

1000{
1002
1003 HPVector thisv, thatv;
1004 double limit;
1005 BOOL gotLimit;
1006 Quaternion result;
1007 uintN consumed;
1008 jsval* argv = OOJS_ARGV;
1009
1010 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotationTo")))
1011 return NO;
1012 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"rotationTo", argc, OOJS_ARGV, &thatv, &consumed)))
1013 return NO;
1014
1015 argc -= consumed;
1016 argv += consumed;
1017 if (argc != 0) // limit parameter is optional.
1018 {
1019 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"rotationTo", argc, argv, &limit, NULL)))
1020 return NO;
1021 gotLimit = YES;
1022 } else
1023 gotLimit = NO;
1024
1025 if (gotLimit)
1027 else
1029
1030 OOJS_RETURN_QUATERNION(result);
1031
1033}
#define OOJS_RETURN_QUATERNION(value)
Quaternion quaternion_rotation_between(Vector v0, Vector v1) CONST_FUNC
Quaternion quaternion_limited_rotation_between(Vector v0, Vector v1, float maxArc) CONST_FUNC

References EXPECT_NOT, GetThisVector(), HPVectorToVector(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_QUATERNION, OOJS_THIS, OOJSArgumentListGetNumber(), quaternion_limited_rotation_between(), quaternion_rotation_between(), and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorSetProperty()

JSBool VectorSetProperty ( JSContext * context,
JSObject * this,
jsid propID,
JSBool strict,
jsval * value )
static

Definition at line 628 of file OOJSVector.m.

629{
630 if (!JSID_IS_INT(propID))
631 return YES;
632
634
635 HPVector vector;
636 jsdouble dval;
637
638 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector)))
639 return NO;
640 if (EXPECT_NOT(!JS_ValueToNumber(context, *value, &dval))) {
641 OOJSReportBadPropertyValue(context, this, propID, sVectorProperties, *value);
642 return NO;
643 }
644
645 switch (JSID_TO_INT(propID)) {
646 case kVector_x:
647 vector.x = dval;
648 break;
649
650 case kVector_y:
651 vector.y = dval;
652 break;
653
654 case kVector_z:
655 vector.z = dval;
656 break;
657
658 default:
659 OOJSReportBadPropertySelector(context, this, propID, sVectorProperties);
660 return NO;
661 }
662
663 return JSVectorSetHPVector(context, this, vector);
664
666}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)

References EXPECT_NOT, JSObjectGetVector(), JSVectorSetHPVector(), kVector_x, kVector_y, kVector_z, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSReportBadPropertySelector(), OOJSReportBadPropertyValue(), and sVectorProperties.

Here is the call graph for this function:

◆ VectorSquaredDistanceTo()

JSBool VectorSquaredDistanceTo ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 814 of file OOJSVector.m.

815{
817
818 HPVector thisv, thatv;
819 double result;
820
821 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredDistanceTo")))
822 return NO;
823 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"squaredDistanceTo", argc, OOJS_ARGV, &thatv, NULL)))
824 return NO;
825
826 result = HPdistance2(thisv, thatv);
827
828 OOJS_RETURN_DOUBLE(result);
829
831}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293

References EXPECT_NOT, GetThisVector(), HPdistance2(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorSquaredMagnitude()

JSBool VectorSquaredMagnitude ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 981 of file OOJSVector.m.

982{
984
985 HPVector thisv;
986 double result;
987
988 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredMagnitude")))
989 return NO;
990
991 result = HPmagnitude2(thisv);
992
993 OOJS_RETURN_DOUBLE(result);
994
996}
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255

References EXPECT_NOT, GetThisVector(), HPmagnitude2(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorStaticInterpolate()

JSBool VectorStaticInterpolate ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1140 of file OOJSVector.m.

1141{
1143
1144 HPVector av, bv;
1145 double interp;
1146 HPVector result;
1147 uintN consumed;
1148 uintN inArgc = argc;
1149 jsval* argv = OOJS_ARGV;
1150 jsval* inArgv = argv;
1151
1152 if (EXPECT_NOT(argc < 3))
1153 goto INSUFFICIENT_ARGUMENTS;
1154 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &av, &consumed)))
1155 return NO;
1156 argc -= consumed;
1157 argv += consumed;
1158 if (EXPECT_NOT(argc < 2))
1159 goto INSUFFICIENT_ARGUMENTS;
1160 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &bv, &consumed)))
1161 return NO;
1162 argc -= consumed;
1163 argv += consumed;
1164 if (EXPECT_NOT(argc < 1))
1165 goto INSUFFICIENT_ARGUMENTS;
1166 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"interpolate", argc, argv, &interp, NULL)))
1167 return NO;
1168
1169 result = OOHPVectorInterpolate(av, bv, interp);
1170
1171 OOJS_RETURN_HPVECTOR(result);
1172
1173INSUFFICIENT_ARGUMENTS:
1174 OOJSReportBadArguments(context, @"Vector3D", @"interpolate", inArgc, inArgv,
1175 @"Insufficient parameters",
1176 @"vector expression, vector expression and number");
1177 return NO;
1178
1180}
OOINLINE HPVector OOHPVectorInterpolate(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
Definition OOHPVector.h:222

References EXPECT_NOT, OOHPVectorInterpolate(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJSArgumentListGetNumber(), OOJSReportBadArguments(), and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorStaticRandom()

JSBool VectorStaticRandom ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1183 of file OOJSVector.m.

1184{
1186
1187 double maxLength;
1188
1189 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL))
1190 maxLength = 1.0;
1191
1193
1195}
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
Definition OOHPVector.m:75
BOOL OOJSArgumentListGetNumberNoError(JSContext *context, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)

References OOHPVectorRandomSpatial(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, and OOJSArgumentListGetNumberNoError().

Here is the call graph for this function:

◆ VectorStaticRandomDirection()

JSBool VectorStaticRandomDirection ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1198 of file OOJSVector.m.

1199{
1201
1202 double scale;
1203
1204 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &scale, NULL))
1205 scale = 1.0;
1206
1208
1210}
HPVector OORandomUnitHPVector(void)
Definition OOHPVector.m:62

References HPvector_multiply_scalar(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJSArgumentListGetNumberNoError(), and OORandomUnitHPVector().

Here is the call graph for this function:

◆ VectorStaticRandomDirectionAndLength()

JSBool VectorStaticRandomDirectionAndLength ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1213 of file OOJSVector.m.

1214{
1216
1217 double maxLength;
1218
1219 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL))
1220 maxLength = 1.0;
1221
1223
1225}
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
Definition OOHPVector.m:88

References OOHPVectorRandomRadial(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, and OOJSArgumentListGetNumberNoError().

Here is the call graph for this function:

◆ VectorSubtract()

JSBool VectorSubtract ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 775 of file OOJSVector.m.

776{
778
779 HPVector thisv, thatv, result;
780
781 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"subtract")))
782 return NO;
783 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"subtract", argc, OOJS_ARGV, &thatv, NULL)))
784 return NO;
785
786 result = HPvector_subtract(thisv, thatv);
787
788 OOJS_RETURN_HPVECTOR(result);
789
791}
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236

References EXPECT_NOT, GetThisVector(), HPvector_subtract(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorToArray()

JSBool VectorToArray ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1056 of file OOJSVector.m.

1057{
1059
1060 HPVector thisv;
1061 JSObject* result = NULL;
1062 jsval nVal;
1063
1064 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toArray")))
1065 return NO;
1066
1067 result = JS_NewArrayObject(context, 0, NULL);
1068 if (result != NULL) {
1069 // We do this at the top because the return value slot is a GC root.
1070 OOJS_SET_RVAL(OBJECT_TO_JSVAL(result));
1071
1072 if (JS_NewNumberValue(context, thisv.x, &nVal) && JS_SetElement(context, result, 0, &nVal) && JS_NewNumberValue(context, thisv.y, &nVal) && JS_SetElement(context, result, 1, &nVal) && JS_NewNumberValue(context, thisv.z, &nVal) && JS_SetElement(context, result, 2, &nVal)) {
1073 return YES;
1074 }
1075 // If we get here, the conversion and stuffing in the previous condition failed.
1076 OOJS_SET_RVAL(JSVAL_VOID);
1077 }
1078
1079 return YES;
1080
1082}
#define OOJS_SET_RVAL(v)

References EXPECT_NOT, GetThisVector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_SET_RVAL, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorToCoordinateSystem()

JSBool VectorToCoordinateSystem ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 1085 of file OOJSVector.m.

1086{
1087 OOJS_NATIVE_ENTER(context)
1088
1089 HPVector thisv;
1090 NSString* coordScheme = nil;
1091 HPVector result;
1092
1093 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toCoordinateSystem")))
1094 return NO;
1095
1096 if (EXPECT_NOT(argc < 1 || (coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil)) {
1097 OOJSReportBadArguments(context, @"Vector3D", @"toCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
1098 return NO;
1099 }
1100
1101 OOJS_BEGIN_FULL_NATIVE(context)
1102 result = [UNIVERSE legacyPositionFrom:thisv asCoordinateSystem:coordScheme];
1104
1105 OOJS_RETURN_HPVECTOR(result);
1106
1108}

References EXPECT_NOT, GetThisVector(), MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, OOJSReportBadArguments(), and OOStringFromJSValue().

Here is the call graph for this function:

◆ VectorToJSValue()

BOOL VectorToJSValue ( JSContext * context,
Vector vector,
jsval * outValue )

Definition at line 264 of file OOJSVector.m.

265{
267
268 JSObject* object = NULL;
269
270 assert(outValue != NULL);
271
272 object = JSVectorWithVector(context, vector);
273 if (EXPECT_NOT(object == NULL))
274 return NO;
275
276 *outValue = OBJECT_TO_JSVAL(object);
277 return YES;
278
280}
JSObject * JSVectorWithVector(JSContext *context, Vector vector)
Definition OOJSVector.m:236

References EXPECT_NOT, JSVectorWithVector(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Referenced by EntityGetProperty(), ExhaustPlumeGetProperty(), NSPointToVectorJSValue(), NSPointToVectorJSValue(), OONativeVector(OOJavaScriptConversion)::oo_jsValueInContext:, PlanetGetProperty(), PlayerShipGetProperty(), OOJSPopulatorDefinition::runCallback:, ShipGetProperty(), SoundSourceGetProperty(), SystemInfoGetProperty(), and VisualEffectGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VectorToSource()

JSBool VectorToSource ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 740 of file OOJSVector.m.

741{
742 OOJS_NATIVE_ENTER(context)
743
744 HPVector thisv;
745
746 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toSource")))
747 return NO;
748
749 NSString* str = [NSString stringWithFormat:@"Vector3D(%g, %g, %g)", thisv.x, thisv.y, thisv.z];
751
753}
#define OOJS_RETURN_OBJECT(o)

References EXPECT_NOT, GetThisVector(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorToString()

JSBool VectorToString ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 725 of file OOJSVector.m.

726{
727 OOJS_NATIVE_ENTER(context)
728
729 HPVector thisv;
730
731 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toString")))
732 return NO;
733
734 OOJS_RETURN_OBJECT(HPVectorDescription(thisv));
735
737}

References EXPECT_NOT, GetThisVector(), OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, and OOJS_THIS.

Here is the call graph for this function:

◆ VectorTripleProduct()

JSBool VectorTripleProduct ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 920 of file OOJSVector.m.

921{
923
924 HPVector thisv, thatv, theotherv;
925 double result;
926 uintN consumed;
927 jsval* argv = OOJS_ARGV;
928
929 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"tripleProduct")))
930 return NO;
931 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &thatv, &consumed)))
932 return NO;
933 argc -= consumed;
934 argv += consumed;
935 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &theotherv, NULL)))
936 return NO;
937
938 result = HPtriple_product(thisv, thatv, theotherv);
939
940 OOJS_RETURN_DOUBLE(result);
941
943}
OOINLINE OOHPScalar HPtriple_product(HPVector first, HPVector second, HPVector third) INLINE_CONST_FUNC
Definition OOHPVector.h:322

References EXPECT_NOT, GetThisVector(), HPtriple_product(), OOJS_ARGV, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

Variable Documentation

◆ sVectorClass

JSClass sVectorClass
static
Initial value:
= {
"Vector3D",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static void VectorFinalize(JSContext *context, JSObject *this)
Definition OOJSVector.m:668
static JSBool VectorGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSVector.m:592
static JSBool VectorSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSVector.m:628

Definition at line 74 of file OOJSVector.m.

74 {
75 "Vector3D",
76 JSCLASS_HAS_PRIVATE,
77
78 JS_PropertyStub, // addProperty
79 JS_PropertyStub, // delProperty
80 VectorGetProperty, // getProperty
81 VectorSetProperty, // setProperty
82 JS_EnumerateStub, // enumerate
83 JS_ResolveStub, // resolve
84 JS_ConvertStub, // convert
85 VectorFinalize, // finalize
86 JSCLASS_NO_OPTIONAL_MEMBERS
87};

Referenced by InitOOJSVector(), InitOOJSVector(), JSObjectGetVector(), JSVectorSetHPVector(), JSVectorWithHPVector(), JSVectorWithVector(), VectorConstruct(), and VectorFinalize().

◆ sVectorMethods

JSFunctionSpec sVectorMethods[]
static

Definition at line 104 of file OOJSVector.m.

104 {
105 // JS name Function min args
106 {
107 "toSource",
109 0,
110 },
111 {
112 "toString",
114 0,
115 },
116 {
117 "add",
118 VectorAdd,
119 1,
120 },
121 {
122 "angleTo",
124 1,
125 },
126 {
127 "cross",
129 1,
130 },
131 {
132 "direction",
134 0,
135 },
136 {
137 "distanceTo",
139 1,
140 },
141 {
142 "dot",
143 VectorDot,
144 1,
145 },
146 {
147 "fromCoordinateSystem",
149 1,
150 },
151 {
152 "magnitude",
154 0,
155 },
156 {
157 "multiply",
159 1,
160 },
161 {
162 "rotateBy",
164 1,
165 },
166 {
167 "rotationTo",
169 1,
170 },
171 {
172 "squaredDistanceTo",
174 1,
175 },
176 {
177 "squaredMagnitude",
179 0,
180 },
181 {
182 "subtract",
184 1,
185 },
186 {
187 "toArray",
189 0,
190 },
191 {
192 "toCoordinateSystem",
194 1,
195 },
196 {
197 "tripleProduct",
199 2,
200 },
201 { 0 }
202};
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)
Definition OOJSVector.m:756
static JSBool VectorToString(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:725
static JSBool VectorCross(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:901
static JSBool VectorSubtract(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:775
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)
Definition OOJSVector.m:794
static JSBool VectorMagnitude(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:963
static JSBool VectorDot(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:854
static JSBool VectorRotationTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:999
static JSBool VectorTripleProduct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:920
static JSBool VectorDirection(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:946
static JSBool VectorAngleTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:874
static JSBool VectorToSource(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:740
static JSBool VectorSquaredMagnitude(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:981
static JSBool VectorSquaredDistanceTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:814
static JSBool VectorMultiply(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:834

Referenced by InitOOJSVector(), and InitOOJSVector().

◆ sVectorProperties

JSPropertySpec sVectorProperties[]
static
Initial value:
= {
{ 0 }
}
#define OOJS_PROP_READWRITE_CB

Definition at line 96 of file OOJSVector.m.

96 {
97 // JS name ID flags
101 { 0 }
102};

Referenced by InitOOJSVector(), InitOOJSVector(), VectorGetProperty(), VectorGetProperty(), VectorSetProperty(), and VectorSetProperty().

◆ sVectorPrototype

JSObject* sVectorPrototype
static

Definition at line 38 of file OOJSVector.m.

Referenced by InitOOJSVector(), JSVectorWithHPVector(), and JSVectorWithVector().

◆ sVectorStaticMethods

JSFunctionSpec sVectorStaticMethods[]
static
Initial value:
= {
{
"interpolate",
3,
},
{
"random",
0,
},
{
"randomDirection",
0,
},
{
"randomDirectionAndLength",
0,
},
{ 0 }
}
static JSBool VectorStaticRandomDirectionAndLength(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticInterpolate(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandom(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorStaticRandomDirection(JSContext *context, uintN argc, jsval *vp)

Definition at line 204 of file OOJSVector.m.

204 {
205 // JS name Function min args
206 {
207 "interpolate",
209 3,
210 },
211 {
212 "random",
214 0,
215 },
216 {
217 "randomDirection",
219 0,
220 },
221 {
222 "randomDirectionAndLength",
224 0,
225 },
226 { 0 }
227};

Referenced by InitOOJSVector(), and InitOOJSVector().