Oolite 1.91.0.7646-241128-10e222e
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 325 of file OOJSVector.m.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kVector_x 
kVector_y 
kVector_z 

Definition at line 95 of file OOJSVector.m.

96{
97 // Property IDs
101};
@ kVector_z
Definition OOJSVector.m:100
@ kVector_x
Definition OOJSVector.m:98
@ kVector_y
Definition OOJSVector.m:99

Function Documentation

◆ GetThisVector()

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

Definition at line 410 of file OOJSVector.m.

411{
412 if (EXPECT(JSObjectGetVector(context, vectorObj, outVector))) return YES;
413
414 jsval arg = OBJECT_TO_JSVAL(vectorObj);
415 OOJSReportBadArguments(context, @"Vector3D", method, 1, &arg, @"Invalid target object", @"Vector3D");
416 return NO;
417}
#define EXPECT(x)
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
Definition OOJSVector.m:330
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)

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

Referenced by VectorAdd(), VectorAngleTo(), VectorCross(), VectorDirection(), VectorDistanceTo(), VectorDot(), VectorFromCoordinateSystem(), VectorMagnitude(), VectorMultiply(), VectorRotateBy(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorSquaredMagnitude(), VectorSubtract(), VectorToArray(), VectorToCoordinateSystem(), VectorToSource(), VectorToString(), 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 228 of file OOJSVector.m.

229{
231
232 JSObject *object = NULL;
233
234 assert(outValue != NULL);
235
236 object = JSVectorWithHPVector(context, vector);
237 if (EXPECT_NOT(object == NULL)) return NO;
238
239 *outValue = OBJECT_TO_JSVAL(object);
240 return YES;
241
243}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
Definition OOJSVector.m:202

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

Referenced by EntityGetProperty(), and ShipGetProperty().

+ 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 153 of file OOJSVector.m.

154{
155 sVectorPrototype = JS_InitClass(context, global, NULL, &sVectorClass, VectorConstruct, 0, sVectorProperties, sVectorMethods, NULL, sVectorStaticMethods);
156}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:104
static JSObject * sVectorPrototype
Definition OOJSVector.m:39
static JSFunctionSpec sVectorMethods[]
Definition OOJSVector.m:114
static JSFunctionSpec sVectorStaticMethods[]
Definition OOJSVector.m:140
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:609
static JSClass sVectorClass
Definition OOJSVector.m:78

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

+ Here is the call graph for this function:

◆ JSObjectGetVector()

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

Definition at line 330 of file OOJSVector.m.

331{
333
334 assert(outVector != NULL);
335
336 HPVector *private = NULL;
337 jsuint arrayLength;
338 jsval arrayX, arrayY, arrayZ;
339 jsdouble x, y, z;
340
341 // vectorObj can legitimately be NULL, e.g. when JS_NULL is converted to a JSObject *.
342 if (EXPECT_NOT(vectorObj == NULL))
343 {
344 COUNT(nullCount);
345 return NO;
346 }
347
348 // If this is a (JS) Vector...
349 private = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
350 if (EXPECT(private != NULL))
351 {
352 COUNT(vectorCount);
353 *outVector = *private;
354 return YES;
355 }
356
357 // If it's an array...
358 if (EXPECT(JS_IsArrayObject(context, vectorObj)))
359 {
360 // ...and it has exactly three elements...
361 if (JS_GetArrayLength(context, vectorObj, &arrayLength) && arrayLength == 3)
362 {
363 if (JS_LookupElement(context, vectorObj, 0, &arrayX) &&
364 JS_LookupElement(context, vectorObj, 1, &arrayY) &&
365 JS_LookupElement(context, vectorObj, 2, &arrayZ))
366 {
367 // ...use the three numbers as [x, y, z]
368 if (JS_ValueToNumber(context, arrayX, &x) &&
369 JS_ValueToNumber(context, arrayY, &y) &&
370 JS_ValueToNumber(context, arrayZ, &z))
371 {
372 COUNT(arrayCount);
373 *outVector = make_HPvector(x, y, z);
374 return YES;
375 }
376 }
377 }
378 }
379
380 // If it's an entity, use its position.
381 if (OOJSIsMemberOfSubclass(context, vectorObj, JSEntityClass()))
382 {
383 COUNT(entityCount);
384 Entity *entity = [(id)JS_GetPrivate(context, vectorObj) weakRefUnderlyingObject];
385 *outVector = [entity position];
386 return YES;
387 }
388
389 /*
390 If it's actually a Vector3D but with no private field (this happens for
391 Vector3D.prototype)...
392
393 NOTE: it would be prettier to do this at the top when we handle normal
394 Vector3Ds, but it's a rare case which should be kept off the fast path.
395 */
396 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL))
397 {
398 COUNT(protoCount);
399 *outVector = kZeroHPVector;
400 return YES;
401 }
402
403 COUNT(failCount);
404 return NO;
405
407}
const HPVector kZeroHPVector
Definition OOHPVector.m:28
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
#define COUNT(FIELD)
Definition OOJSVector.m:325
OOINLINE BOOL OOJSIsMemberOfSubclass(JSContext *context, JSObject *object, JSClass *superclass)
float y
float x
HPVector position
Definition Entity.h:112

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

Referenced by JSValueToHPVector(), and JSValueToVector().

+ 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 252 of file OOJSVector.m.

253{
254 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value))) return NO;
255
256 return JSObjectGetVector(context, JSVAL_TO_OBJECT(value), outVector);
257}

References EXPECT_NOT, and JSObjectGetVector().

Referenced by EntitySetProperty(), ShipSetProperty(), 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 259 of file OOJSVector.m.

260{
261 if (EXPECT_NOT(!JSVAL_IS_OBJECT(value))) return NO;
262 HPVector tmp = kZeroHPVector;
263 BOOL result = JSObjectGetVector(context, JSVAL_TO_OBJECT(value), &tmp);
264 *outVector = HPVectorToVector(tmp);
265 return result;
266}

References EXPECT_NOT, JSObjectGetVector(), and kZeroHPVector.

Referenced by ExhaustPlumeSetProperty(), OOPlanetEntity(OOJavaScriptExtensions)::getJSClass:andPrototype:, MissionRunScreen(), PlayerShipSetCustomView(), PlayerShipSetProperty(), ShipSetProperty(), SoundSourceSetProperty(), SystemSetPopulator(), 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 426 of file OOJSVector.m.

427{
429
430 HPVector *private = NULL;
431
432 if (EXPECT_NOT(vectorObj == NULL)) return NO;
433
434 private = JS_GetInstancePrivate(context, vectorObj, &sVectorClass, NULL);
435 if (private != NULL) // If this is a (JS) Vector...
436 {
437 *private = vector;
438 return YES;
439 }
440
441 if (JS_InstanceOf(context, vectorObj, &sVectorClass, NULL))
442 {
443 // Silently fail for the prototype.
444 return YES;
445 }
446
447 return NO;
448
450}

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 420 of file OOJSVector.m.

421{
422 return JSVectorSetHPVector(context,vectorObj,vectorToHPVector(vector));
423}
BOOL JSVectorSetHPVector(JSContext *context, JSObject *vectorObj, HPVector vector)
Definition OOJSVector.m:426

References JSVectorSetHPVector().

+ Here is the call graph for this function:

◆ JSVectorWithHPVector()

JSObject * JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 202 of file OOJSVector.m.

203{
205
206 JSObject *result = NULL;
207 HPVector *private = NULL;
208
209 private = malloc(sizeof *private);
210 if (EXPECT_NOT(private == NULL)) return NULL;
211
212 *private = vector;
213
214 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
215 if (result != NULL)
216 {
217 if (EXPECT_NOT(!JS_SetPrivate(context, result, private))) result = NULL;
218 }
219
220 if (EXPECT_NOT(result == NULL)) free(private);
221
222 return result;
223
225}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, sVectorClass, and sVectorPrototype.

Referenced by HPVectorToJSValue().

+ Here is the caller graph for this function:

◆ JSVectorWithVector()

JSObject * JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 159 of file OOJSVector.m.

160{
162
163 JSObject *result = NULL;
164 HPVector *private = NULL;
165
166 private = malloc(sizeof *private);
167 if (EXPECT_NOT(private == NULL)) return NULL;
168
169 *private = vectorToHPVector(vector);
170
171 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
172 if (result != NULL)
173 {
174 if (EXPECT_NOT(!JS_SetPrivate(context, result, private))) result = NULL;
175 }
176
177 if (EXPECT_NOT(result == NULL)) free(private);
178
179 return result;
180
182}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, sVectorClass, and sVectorPrototype.

Referenced by OOJSCallObjCObjectMethod(), and VectorToJSValue().

+ Here is the caller graph for this function:

◆ NSPointToVectorJSValue()

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

Definition at line 246 of file OOJSVector.m.

247{
248 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
249}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
Definition OOJSVector.m:185

References VectorToJSValue().

Referenced by PlayerShipGetProperty(), and SystemInfoGetProperty().

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

◆ VectorAdd()

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

Definition at line 683 of file OOJSVector.m.

684{
686
687 HPVector thisv, thatv, result;
688
689 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"add"))) return NO;
690 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"add", argc, OOJS_ARGV, &thatv, NULL))) return NO;
691
692 result = HPvector_add(thisv, thatv);
693
694 OOJS_RETURN_HPVECTOR(result);
695
697}
BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed)
Definition OOJSVector.m:495
static BOOL GetThisVector(JSContext *context, JSObject *vectorObj, HPVector *outVector, NSString *method) NONNULL_FUNC
Definition OOJSVector.m:410
#define OOJS_THIS
#define OOJS_ARGV
#define OOJS_RETURN_HPVECTOR(value)

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

+ Here is the call graph for this function:

◆ VectorAngleTo()

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

Definition at line 795 of file OOJSVector.m.

796{
798
799 HPVector thisv, thatv;
800 double result;
801
802 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"angleTo"))) return NO;
803 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"angleTo", argc, OOJS_ARGV, &thatv, NULL))) return NO;
804
805 result = HPdot_product(HPvector_normal(thisv), HPvector_normal(thatv));
806 if (result > 1.0) result = 1.0;
807 if (result < -1.0) result = -1.0;
808 // for identical vectors the dot_product sometimes returns a value > 1.0 because of rounding errors, resulting
809 // in an undefined result for the acos.
810 result = acos(result);
811
812 OOJS_RETURN_DOUBLE(result);
813
815}
#define OOJS_RETURN_DOUBLE(value)

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

+ Here is the call graph for this function:

◆ VectorConstruct()

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

Definition at line 609 of file OOJSVector.m.

610{
612
613 HPVector vector = kZeroHPVector;
614 HPVector *private = NULL;
615 JSObject *this = NULL;
616
617 private = malloc(sizeof *private);
618 if (EXPECT_NOT(private == NULL)) return NO;
619
620 this = JS_NewObject(context, &sVectorClass, NULL, NULL);
621 if (EXPECT_NOT(this == NULL)) return NO;
622
623 if (argc != 0)
624 {
625 if (EXPECT_NOT(!VectorFromArgumentListNoErrorInternal(context, argc, OOJS_ARGV, &vector, NULL, YES)))
626 {
627 free(private);
628 OOJSReportBadArguments(context, NULL, NULL, argc, OOJS_ARGV,
629 @"Could not construct vector from parameters",
630 @"Vector, Entity or array of three numbers");
631 return NO;
632 }
633 }
634
635 *private = vector;
636
637 if (EXPECT_NOT(!JS_SetPrivate(context, this, private)))
638 {
639 free(private);
640 return NO;
641 }
642
644
646}
static BOOL VectorFromArgumentListNoErrorInternal(JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed, BOOL permitNumberList)
Definition OOJSVector.m:453
#define OOJS_RETURN_JSOBJECT(o)

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

Referenced by InitOOJSVector().

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

◆ VectorCross()

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

Definition at line 819 of file OOJSVector.m.

820{
822
823 HPVector thisv, thatv, result;
824
825 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"cross"))) return NO;
826 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"cross", argc, OOJS_ARGV, &thatv, NULL))) return NO;
827
828 result = HPtrue_cross_product(thisv, thatv);
829
830 OOJS_RETURN_HPVECTOR(result);
831
833}

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

+ Here is the call graph for this function:

◆ VectorDirection()

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

Definition at line 861 of file OOJSVector.m.

862{
864
865 HPVector thisv, result;
866
867 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"direction"))) return NO;
868
869 result = HPvector_normal(thisv);
870
871 OOJS_RETURN_HPVECTOR(result);
872
874}

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

+ Here is the call graph for this function:

◆ VectorDistanceTo()

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

Definition at line 719 of file OOJSVector.m.

720{
722
723 HPVector thisv, thatv;
724 double result;
725
726 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"distanceTo"))) return NO;
727 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"distanceTo", argc, OOJS_ARGV, &thatv, NULL))) return NO;
728
729 result = HPdistance(thisv, thatv);
730
731 OOJS_RETURN_DOUBLE(result);
732
734}

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

+ Here is the call graph for this function:

◆ VectorDot()

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

Definition at line 776 of file OOJSVector.m.

777{
779
780 HPVector thisv, thatv;
781 double result;
782
783 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"dot"))) return NO;
784 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"dot", argc, OOJS_ARGV, &thatv, NULL))) return NO;
785
786 result = HPdot_product(thisv, thatv);
787
788 OOJS_RETURN_DOUBLE(result);
789
791}

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

+ Here is the call graph for this function:

◆ VectorFinalize()

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

Definition at line 593 of file OOJSVector.m.

594{
596
597 Vector *private = NULL;
598
599 private = JS_GetInstancePrivate(context, this, &sVectorClass, NULL);
600 if (private != NULL)
601 {
602 free(private);
603 }
604
606}
#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 495 of file OOJSVector.m.

496{
497 if (VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO)) return YES;
498 else
499 {
500 OOJSReportBadArguments(context, scriptClass, function, argc, argv,
501 @"Could not construct vector from parameters",
502 @"Vector, Entity or array of three numbers");
503 return NO;
504 }
505}

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 508 of file OOJSVector.m.

509{
510 return VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO);
511}

References VectorFromArgumentListNoErrorInternal().

+ Here is the call graph for this function:

◆ VectorFromArgumentListNoErrorInternal()

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

Definition at line 453 of file OOJSVector.m.

454{
456
457 double x, y, z;
458
459 if (EXPECT_NOT(argc == 0)) return NO;
460 assert(argv != NULL && outVector != NULL);
461
462 if (outConsumed != NULL) *outConsumed = 0;
463
464 // Is first object a vector, array or entity?
465 if (JSVAL_IS_OBJECT(argv[0]))
466 {
467 if (JSObjectGetVector(context, JSVAL_TO_OBJECT(argv[0]), outVector))
468 {
469 if (outConsumed != NULL) *outConsumed = 1;
470 return YES;
471 }
472 }
473
474 if (!permitNumberList) return NO;
475
476 // As a special case for VectorConstruct(), look for three numbers.
477 if (argc < 3) return NO;
478
479 // Given a string, JS_ValueToNumber() returns YES but provides a NaN number.
480 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &x) || isnan(x))) return NO;
481 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[1], &y) || isnan(y))) return NO;
482 if (EXPECT_NOT(!JS_ValueToNumber(context, argv[2], &z) || isnan(z))) return NO;
483
484 // We got our three numbers.
485 *outVector = make_HPvector(x, y, z);
486 if (outConsumed != NULL) *outConsumed = 3;
487
488 return YES;
489
491}

References EXPECT_NOT, JSObjectGetVector(), 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()

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

Definition at line 1027 of file OOJSVector.m.

1028{
1029 OOJS_NATIVE_ENTER(context)
1030
1031 HPVector thisv;
1032 NSString *coordScheme = nil;
1033 HPVector result;
1034
1035 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"fromCoordinateSystem"))) return NO;
1036
1037 if (EXPECT_NOT(argc < 1 ||
1038 (coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil))
1039 {
1040 OOJSReportBadArguments(context, @"Vector3D", @"fromCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
1041 return NO;
1042 }
1043
1044 OOJS_BEGIN_FULL_NATIVE(context)
1045 NSString *arg = [NSString stringWithFormat:@"%@ %f %f %f", coordScheme, thisv.x, thisv.y, thisv.z];
1046 result = [UNIVERSE coordinatesFromCoordinateSystemString:arg];
1048
1049 OOJS_RETURN_HPVECTOR(result);
1050
1052}
#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:111
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()

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

Definition at line 516 of file OOJSVector.m.

517{
518 if (!JSID_IS_INT(propID)) return YES;
519
521
522 HPVector vector;
523 OOHPScalar fValue;
524
525 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
526
527 switch (JSID_TO_INT(propID))
528 {
529 case kVector_x:
530 fValue = vector.x;
531 break;
532
533 case kVector_y:
534 fValue = vector.y;
535 break;
536
537 case kVector_z:
538 fValue = vector.z;
539 break;
540
541 default:
542 OOJSReportBadPropertySelector(context, this, propID, sVectorProperties);
543 return NO;
544 }
545
546 return JS_NewNumberValue(context, fValue, value);
547
549}
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
double OOHPScalar
Definition OOMaths.h:69

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()

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

Definition at line 878 of file OOJSVector.m.

879{
881
882 HPVector thisv;
883 double result;
884
885 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"magnitude"))) return NO;
886
887 result = HPmagnitude(thisv);
888
889 OOJS_RETURN_DOUBLE(result);
890
892}

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

+ Here is the call graph for this function:

◆ VectorMultiply()

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

Definition at line 757 of file OOJSVector.m.

758{
760
761 HPVector thisv, result;
762 double scalar;
763
764 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"multiply"))) return NO;
765 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"multiply", argc, OOJS_ARGV, &scalar, NULL))) return NO;
766
767 result = HPvector_multiply_scalar(thisv, scalar);
768
769 OOJS_RETURN_HPVECTOR(result);
770
772}
BOOL OOJSArgumentListGetNumber(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, double *outNumber, uintN *outConsumed)

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

+ Here is the call graph for this function:

◆ VectorRotateBy()

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

Definition at line 947 of file OOJSVector.m.

948{
950
951 HPVector thisv, result;
952 Quaternion q;
953
954 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotateBy"))) return NO;
955 if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Vector3D", @"rotateBy", argc, OOJS_ARGV, &q, NULL))) return NO;
956
957 result = quaternion_rotate_HPvector(q, thisv);
958
959 OOJS_RETURN_HPVECTOR(result);
960
962}
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 v)

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()

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

Definition at line 914 of file OOJSVector.m.

915{
917
918 HPVector thisv, thatv;
919 double limit;
920 BOOL gotLimit;
921 Quaternion result;
922 uintN consumed;
923 jsval *argv = OOJS_ARGV;
924
925 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotationTo"))) return NO;
926 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"rotationTo", argc, OOJS_ARGV, &thatv, &consumed))) return NO;
927
928 argc -= consumed;
929 argv += consumed;
930 if (argc != 0) // limit parameter is optional.
931 {
932 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"rotationTo", argc, argv, &limit, NULL))) return NO;
933 gotLimit = YES;
934 }
935 else gotLimit = NO;
936
937 if (gotLimit) result = quaternion_limited_rotation_between(HPVectorToVector(thisv), HPVectorToVector(thatv), limit);
938 else result = quaternion_rotation_between(HPVectorToVector(thisv), HPVectorToVector(thatv));
939
941
943}
#define OOJS_RETURN_QUATERNION(value)
Quaternion quaternion_rotation_between(Vector v0, Vector v1)
Quaternion quaternion_limited_rotation_between(Vector v0, Vector v1, float maxArc)

References EXPECT_NOT, GetThisVector(), 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()

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

Definition at line 552 of file OOJSVector.m.

553{
554 if (!JSID_IS_INT(propID)) return YES;
555
557
558 HPVector vector;
559 jsdouble dval;
560
561 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector))) return NO;
562 if (EXPECT_NOT(!JS_ValueToNumber(context, *value, &dval)))
563 {
564 OOJSReportBadPropertyValue(context, this, propID, sVectorProperties, *value);
565 return NO;
566 }
567
568 switch (JSID_TO_INT(propID))
569 {
570 case kVector_x:
571 vector.x = dval;
572 break;
573
574 case kVector_y:
575 vector.y = dval;
576 break;
577
578 case kVector_z:
579 vector.z = dval;
580 break;
581
582 default:
583 OOJSReportBadPropertySelector(context, this, propID, sVectorProperties);
584 return NO;
585 }
586
587 return JSVectorSetHPVector(context, this, vector);
588
590}
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()

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

Definition at line 738 of file OOJSVector.m.

739{
741
742 HPVector thisv, thatv;
743 double result;
744
745 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredDistanceTo"))) return NO;
746 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"squaredDistanceTo", argc, OOJS_ARGV, &thatv, NULL))) return NO;
747
748 result = HPdistance2(thisv, thatv);
749
750 OOJS_RETURN_DOUBLE(result);
751
753}

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

+ Here is the call graph for this function:

◆ VectorSquaredMagnitude()

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

Definition at line 896 of file OOJSVector.m.

897{
899
900 HPVector thisv;
901 double result;
902
903 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredMagnitude"))) return NO;
904
905 result = HPmagnitude2(thisv);
906
907 OOJS_RETURN_DOUBLE(result);
908
910}

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

+ Here is the call graph for this function:

◆ VectorStaticInterpolate()

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

Definition at line 1059 of file OOJSVector.m.

1060{
1062
1063 HPVector av, bv;
1064 double interp;
1065 HPVector result;
1066 uintN consumed;
1067 uintN inArgc = argc;
1068 jsval *argv = OOJS_ARGV;
1069 jsval *inArgv = argv;
1070
1071 if (EXPECT_NOT(argc < 3)) goto INSUFFICIENT_ARGUMENTS;
1072 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &av, &consumed))) return NO;
1073 argc -= consumed;
1074 argv += consumed;
1075 if (EXPECT_NOT(argc < 2)) goto INSUFFICIENT_ARGUMENTS;
1076 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &bv, &consumed))) return NO;
1077 argc -= consumed;
1078 argv += consumed;
1079 if (EXPECT_NOT(argc < 1)) goto INSUFFICIENT_ARGUMENTS;
1080 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"interpolate", argc, argv, &interp, NULL))) return NO;
1081
1082 result = OOHPVectorInterpolate(av, bv, interp);
1083
1084 OOJS_RETURN_HPVECTOR(result);
1085
1086INSUFFICIENT_ARGUMENTS:
1087 OOJSReportBadArguments(context, @"Vector3D", @"interpolate", inArgc, inArgv,
1088 @"Insufficient parameters",
1089 @"vector expression, vector expression and number");
1090 return NO;
1091
1093}

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

+ Here is the call graph for this function:

◆ VectorStaticRandom()

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

Definition at line 1097 of file OOJSVector.m.

1098{
1100
1101 double maxLength;
1102
1103 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL)) maxLength = 1.0;
1104
1106
1108}
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
Definition OOHPVector.m:82
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()

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

Definition at line 1112 of file OOJSVector.m.

1113{
1115
1116 double scale;
1117
1118 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &scale, NULL)) scale = 1.0;
1119
1120 OOJS_RETURN_HPVECTOR(HPvector_multiply_scalar(OORandomUnitHPVector(), scale));
1121
1123}
HPVector OORandomUnitHPVector(void)
Definition OOHPVector.m:66

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

+ Here is the call graph for this function:

◆ VectorStaticRandomDirectionAndLength()

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

Definition at line 1127 of file OOJSVector.m.

1128{
1130
1131 double maxLength;
1132
1133 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL)) maxLength = 1.0;
1134
1136
1138}
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
Definition OOHPVector.m:98

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

+ Here is the call graph for this function:

◆ VectorSubtract()

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

Definition at line 701 of file OOJSVector.m.

702{
704
705 HPVector thisv, thatv, result;
706
707 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"subtract"))) return NO;
708 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"subtract", argc, OOJS_ARGV, &thatv, NULL))) return NO;
709
710 result = HPvector_subtract(thisv, thatv);
711
712 OOJS_RETURN_HPVECTOR(result);
713
715}

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

+ Here is the call graph for this function:

◆ VectorToArray()

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

Definition at line 966 of file OOJSVector.m.

967{
969
970 HPVector thisv;
971 JSObject *result = NULL;
972 jsval nVal;
973
974 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toArray"))) return NO;
975
976 result = JS_NewArrayObject(context, 0, NULL);
977 if (result != NULL)
978 {
979 // We do this at the top because the return value slot is a GC root.
980 OOJS_SET_RVAL(OBJECT_TO_JSVAL(result));
981
982 if (JS_NewNumberValue(context, thisv.x, &nVal) && JS_SetElement(context, result, 0, &nVal) &&
983 JS_NewNumberValue(context, thisv.y, &nVal) && JS_SetElement(context, result, 1, &nVal) &&
984 JS_NewNumberValue(context, thisv.z, &nVal) && JS_SetElement(context, result, 2, &nVal))
985 {
986 return YES;
987 }
988 // If we get here, the conversion and stuffing in the previous condition failed.
989 OOJS_SET_RVAL(JSVAL_VOID);
990 }
991
992 return YES;
993
995}
#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()

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

Definition at line 999 of file OOJSVector.m.

1000{
1001 OOJS_NATIVE_ENTER(context)
1002
1003 HPVector thisv;
1004 NSString *coordScheme = nil;
1005 HPVector result;
1006
1007 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toCoordinateSystem"))) return NO;
1008
1009 if (EXPECT_NOT(argc < 1 ||
1010 (coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0])) == nil))
1011 {
1012 OOJSReportBadArguments(context, @"Vector3D", @"toCoordinateSystem", MIN(argc, 1U), OOJS_ARGV, nil, @"coordinate system");
1013 return NO;
1014 }
1015
1016 OOJS_BEGIN_FULL_NATIVE(context)
1017 result = [UNIVERSE legacyPositionFrom:thisv asCoordinateSystem:coordScheme];
1019
1020 OOJS_RETURN_HPVECTOR(result);
1021
1023}

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 185 of file OOJSVector.m.

186{
188
189 JSObject *object = NULL;
190
191 assert(outValue != NULL);
192
193 object = JSVectorWithVector(context, vector);
194 if (EXPECT_NOT(object == NULL)) return NO;
195
196 *outValue = OBJECT_TO_JSVAL(object);
197 return YES;
198
200}
JSObject * JSVectorWithVector(JSContext *context, Vector vector)
Definition OOJSVector.m:159

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

Referenced by EntityGetProperty(), ExhaustPlumeGetProperty(), NSPointToVectorJSValue(), PlanetGetProperty(), PlayerShipGetProperty(), ShipGetProperty(), SoundSourceGetProperty(), SystemInfoGetProperty(), and VisualEffectGetProperty().

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

◆ VectorToSource()

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

Definition at line 667 of file OOJSVector.m.

668{
669 OOJS_NATIVE_ENTER(context)
670
671 HPVector thisv;
672
673 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toSource"))) return NO;
674
675 NSString *str = [NSString stringWithFormat:@"Vector3D(%g, %g, %g)", thisv.x, thisv.y, thisv.z];
677
679}
#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()

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

Definition at line 652 of file OOJSVector.m.

653{
654 OOJS_NATIVE_ENTER(context)
655
656 HPVector thisv;
657
658 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toString"))) return NO;
659
660 OOJS_RETURN_OBJECT(HPVectorDescription(thisv));
661
663}

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()

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

Definition at line 837 of file OOJSVector.m.

838{
840
841 HPVector thisv, thatv, theotherv;
842 double result;
843 uintN consumed;
844 jsval *argv = OOJS_ARGV;
845
846 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"tripleProduct"))) return NO;
847 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &thatv, &consumed))) return NO;
848 argc -= consumed;
849 argv += consumed;
850 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &theotherv, NULL))) return NO;
851
852 result = HPtriple_product(thisv, thatv, theotherv);
853
854 OOJS_RETURN_DOUBLE(result);
855
857}

References EXPECT_NOT, GetThisVector(), 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:593
static JSBool VectorGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSVector.m:516
static JSBool VectorSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
Definition OOJSVector.m:552

Definition at line 78 of file OOJSVector.m.

79{
80 "Vector3D",
81 JSCLASS_HAS_PRIVATE,
82
83 JS_PropertyStub, // addProperty
84 JS_PropertyStub, // delProperty
85 VectorGetProperty, // getProperty
86 VectorSetProperty, // setProperty
87 JS_EnumerateStub, // enumerate
88 JS_ResolveStub, // resolve
89 JS_ConvertStub, // convert
90 VectorFinalize, // finalize
91 JSCLASS_NO_OPTIONAL_MEMBERS
92};

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

◆ sVectorMethods

JSFunctionSpec sVectorMethods[]
static
Initial value:
=
{
{ "toSource", VectorToSource, 0, },
{ "toString", VectorToString, 0, },
{ "add", VectorAdd, 1, },
{ "angleTo", VectorAngleTo, 1, },
{ "cross", VectorCross, 1, },
{ "direction", VectorDirection, 0, },
{ "distanceTo", VectorDistanceTo, 1, },
{ "dot", VectorDot, 1, },
{ "fromCoordinateSystem", VectorFromCoordinateSystem, 1, },
{ "magnitude", VectorMagnitude, 0, },
{ "multiply", VectorMultiply, 1, },
{ "rotateBy", VectorRotateBy, 1, },
{ "rotationTo", VectorRotationTo, 1, },
{ "squaredDistanceTo", VectorSquaredDistanceTo, 1, },
{ "squaredMagnitude", VectorSquaredMagnitude, 0, },
{ "subtract", VectorSubtract, 1, },
{ "toArray", VectorToArray, 0, },
{ "toCoordinateSystem", VectorToCoordinateSystem, 1, },
{ "tripleProduct", VectorTripleProduct, 2, },
{ 0 }
}
static JSBool VectorFromCoordinateSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool VectorToArray(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:966
static JSBool VectorAdd(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:683
static JSBool VectorToString(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:652
static JSBool VectorCross(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:819
static JSBool VectorSubtract(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:701
static JSBool VectorRotateBy(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:947
static JSBool VectorToCoordinateSystem(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:999
static JSBool VectorDistanceTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:719
static JSBool VectorMagnitude(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:878
static JSBool VectorDot(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:776
static JSBool VectorRotationTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:914
static JSBool VectorTripleProduct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:837
static JSBool VectorDirection(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:861
static JSBool VectorAngleTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:795
static JSBool VectorToSource(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:667
static JSBool VectorSquaredMagnitude(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:896
static JSBool VectorSquaredDistanceTo(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:738
static JSBool VectorMultiply(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:757

Definition at line 114 of file OOJSVector.m.

115{
116 // JS name Function min args
117 { "toSource", VectorToSource, 0, },
118 { "toString", VectorToString, 0, },
119 { "add", VectorAdd, 1, },
120 { "angleTo", VectorAngleTo, 1, },
121 { "cross", VectorCross, 1, },
122 { "direction", VectorDirection, 0, },
123 { "distanceTo", VectorDistanceTo, 1, },
124 { "dot", VectorDot, 1, },
125 { "fromCoordinateSystem", VectorFromCoordinateSystem, 1, },
126 { "magnitude", VectorMagnitude, 0, },
127 { "multiply", VectorMultiply, 1, },
128 { "rotateBy", VectorRotateBy, 1, },
129 { "rotationTo", VectorRotationTo, 1, },
130 { "squaredDistanceTo", VectorSquaredDistanceTo, 1, },
131 { "squaredMagnitude", VectorSquaredMagnitude, 0, },
132 { "subtract", VectorSubtract, 1, },
133 { "toArray", VectorToArray, 0, },
134 { "toCoordinateSystem", VectorToCoordinateSystem, 1, },
135 { "tripleProduct", VectorTripleProduct, 2, },
136 { 0 }
137};

Referenced by InitOOJSVector().

◆ sVectorProperties

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

Definition at line 104 of file OOJSVector.m.

105{
106 // JS name ID flags
110 { 0 }
111};

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

◆ sVectorPrototype

JSObject* sVectorPrototype
static

Definition at line 39 of file OOJSVector.m.

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

◆ sVectorStaticMethods

JSFunctionSpec sVectorStaticMethods[]
static
Initial value:
=
{
{ "interpolate", VectorStaticInterpolate, 3, },
{ "random", VectorStaticRandom, 0, },
{ "randomDirection", VectorStaticRandomDirection, 0, },
{ "randomDirectionAndLength", VectorStaticRandomDirectionAndLength, 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 140 of file OOJSVector.m.

141{
142 // JS name Function min args
143 { "interpolate", VectorStaticInterpolate, 3, },
144 { "random", VectorStaticRandom, 0, },
145 { "randomDirection", VectorStaticRandomDirection, 0, },
146 { "randomDirectionAndLength", VectorStaticRandomDirectionAndLength, 0, },
147 { 0 }
148};

Referenced by InitOOJSVector().