Oolite
Loading...
Searching...
No Matches
OOJSVector.m File Reference
import "OOJSVector.h"
import "OOJSQuaternion.h"
import "OOJSEntity.h"
import "OOJavaScriptEngine.h"
import "Universe.h"
Include dependency graph for OOJSVector.m:

Go to the source code of this file.

Enumerations

enum  { kVector_x , kVector_y , kVector_z }

Functions

static BOOL GetThisVector (JSContext *context, JSValueConst vectorObj, HPVector *outVector, NSString *method) NONNULL_FUNC
static JSValue VectorGetProperty (JSContext *context, JSValueConst this, int magic)
static JSValue VectorSetProperty (JSContext *context, JSValueConst this, JSValueConst value, int magic)
static void VectorFinalize (JSRuntime *runtime, JSValueConst this)
static JSValue VectorConstruct (JSContext *context, JSValueConst newTarget, int argc, JSValueConst *argv)
static JSValue VectorToString (OOJS_NATIVE_ARGS)
static JSValue VectorToSource (OOJS_NATIVE_ARGS)
static JSValue VectorAdd (OOJS_NATIVE_ARGS)
static JSValue VectorSubtract (OOJS_NATIVE_ARGS)
static JSValue VectorDistanceTo (OOJS_NATIVE_ARGS)
static JSValue VectorSquaredDistanceTo (OOJS_NATIVE_ARGS)
static JSValue VectorMultiply (OOJS_NATIVE_ARGS)
static JSValue VectorDot (OOJS_NATIVE_ARGS)
static JSValue VectorAngleTo (OOJS_NATIVE_ARGS)
static JSValue VectorCross (OOJS_NATIVE_ARGS)
static JSValue VectorTripleProduct (OOJS_NATIVE_ARGS)
static JSValue VectorDirection (OOJS_NATIVE_ARGS)
static JSValue VectorMagnitude (OOJS_NATIVE_ARGS)
static JSValue VectorSquaredMagnitude (OOJS_NATIVE_ARGS)
static JSValue VectorRotationTo (OOJS_NATIVE_ARGS)
static JSValue VectorRotateBy (OOJS_NATIVE_ARGS)
static JSValue VectorToArray (OOJS_NATIVE_ARGS)
static JSValue VectorToCoordinateSystem (OOJS_NATIVE_ARGS)
static JSValue VectorFromCoordinateSystem (OOJS_NATIVE_ARGS)
static JSValue VectorStaticInterpolate (OOJS_NATIVE_ARGS)
static JSValue VectorStaticRandom (OOJS_NATIVE_ARGS)
static JSValue VectorStaticRandomDirection (OOJS_NATIVE_ARGS)
static JSValue VectorStaticRandomDirectionAndLength (OOJS_NATIVE_ARGS)
void InitOOJSVector (JSContext *context, JSValueConst global)
JSValue JSVectorWithVector (JSContext *context, Vector vector)
BOOL VectorToJSValue (JSContext *context, Vector vector, JSValue *outValue)
JSValue JSVectorWithHPVector (JSContext *context, HPVector vector)
BOOL HPVectorToJSValue (JSContext *context, HPVector vector, JSValue *outValue)
BOOL NSPointToVectorJSValue (JSContext *context, NSPoint point, JSValue *outValue)
BOOL JSValueToHPVector (JSContext *context, JSValueConst value, HPVector *outVector)
BOOL JSValueToVector (JSContext *context, JSValueConst value, Vector *outVector)
static BOOL GetArrayElementNumber (JSContext *context, JSValueConst array, uint32_t index, double *outNumber)
BOOL JSObjectGetVector (JSContext *context, JSValueConst vectorObj, HPVector *outVector)
BOOL JSVectorSetVector (JSContext *context, JSValueConst vectorObj, Vector vector)
BOOL JSVectorSetHPVector (JSContext *context, JSValueConst vectorObj, HPVector vector)
static BOOL VectorFromArgumentListNoErrorInternal (JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed, BOOL permitNumberList)
BOOL VectorFromArgumentList (JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed)
BOOL VectorFromArgumentListNoError (JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed)

Variables

static JSClassID sVectorClassID
static JSClassDef sVectorClass
static const JSCFunctionListEntry sVectorProperties []
static const JSCFunctionListEntry sVectorMethods []
static const JSCFunctionListEntry sVectorStaticMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kVector_x 
kVector_y 
kVector_z 

Definition at line 78 of file OOJSVector.m.

78 {
79 // Property IDs
83};
@ kVector_z
Definition OOJSVector.m:93
@ kVector_x
Definition OOJSVector.m:91
@ kVector_y
Definition OOJSVector.m:92

Function Documentation

◆ GetArrayElementNumber()

BOOL GetArrayElementNumber ( JSContext * context,
JSValueConst array,
uint32_t index,
double * outNumber )
static

Definition at line 225 of file OOJSVector.m.

226{
227 JSValue element = JS_GetPropertyUint32(context, array, index);
228 int status = JS_IsException(element) ? -1 : JS_ToFloat64(context, outNumber, element);
229 JS_FreeValue(context, element);
230 return status == 0;
231}

Referenced by JSObjectGetVector().

Here is the caller graph for this function:

◆ GetThisVector()

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

Definition at line 295 of file OOJSVector.m.

296{
297 if (EXPECT(JSObjectGetVector(context, vectorObj, outVector)))
298 return YES;
299
300 OOJSReportBadArguments(context, @"Vector3D", method, 1, &vectorObj, @"Invalid target object", @"Vector3D");
301 return NO;
302}
#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().

Here is the call graph for this function:

◆ HPVectorToJSValue()

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

Definition at line 183 of file OOJSVector.m.

184{
186
187 assert(outValue != NULL);
188
189 JSValue object = JSVectorWithHPVector(context, vector);
190 if (EXPECT_NOT(JS_IsException(object))) {
191 *outValue = JS_UNDEFINED;
192 return NO;
193 }
194
195 *outValue = object;
196 return YES;
197
199}
#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.

Here is the call graph for this function:

◆ InitOOJSVector()

void InitOOJSVector ( JSContext * context,
JSValueConst global )

Definition at line 129 of file OOJSVector.m.

130{
132
133 // As in SpiderMonkey, the prototype is itself an instance with no private data, treated as zero.
134 OOJSInitClass(context, global, sVectorClassID, JS_UNDEFINED, VectorConstruct, 0,
136}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:96
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
static JSClassID sVectorClassID
Definition OOJSVector.m:35
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References OOJS_COUNT, OOJSInitClass(), OOJSRegisterClass(), sVectorClass, sVectorClassID, sVectorMethods, sVectorProperties, sVectorStaticMethods, and VectorConstruct().

Here is the call graph for this function:

◆ JSObjectGetVector()

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

Definition at line 233 of file OOJSVector.m.

234{
236
237 assert(outVector != NULL);
238
239 HPVector* private = NULL;
240 int64_t arrayLength;
241 double x, y, z;
242
243 // vectorObj can legitimately be null or a primitive.
244 if (EXPECT_NOT(!JS_IsObject(vectorObj))) {
245 return NO;
246 }
247
248 // If this is a (JS) Vector...
249private
250 = JS_GetOpaque(vectorObj, sVectorClassID);
251 if (EXPECT(private != NULL)) {
252 *outVector = *private;
253 return YES;
254 }
255
256 // If it's an array...
257 if (EXPECT(JS_IsArray(vectorObj))) {
258 // ...and it has exactly three elements...
259 if (JS_GetLength(context, vectorObj, &arrayLength) == 0 && arrayLength == 3) {
260 // ...use the three numbers as [x, y, z]
261 if (GetArrayElementNumber(context, vectorObj, 0, &x) && GetArrayElementNumber(context, vectorObj, 1, &y) && GetArrayElementNumber(context, vectorObj, 2, &z)) {
262 *outVector = make_HPvector(x, y, z);
263 return YES;
264 }
265 }
266 }
267
268#if !OOJS_POC_HARNESS
269 // If it's an entity, use its position.
270 if (OOJSIsMemberOfSubclass(context, vectorObj, JSEntityClassID())) {
271 JSClassID ignored;
272 Entity* entity = [(id)JS_GetAnyOpaque(vectorObj, &ignored) weakRefUnderlyingObject];
273 *outVector = [entity position];
274 return YES;
275 }
276#endif
277
278 /*
279 If it's actually a Vector3D but with no private field (this happens for
280 Vector3D.prototype)...
281
282 NOTE: it would be prettier to do this at the top when we handle normal
283 Vector3Ds, but it's a rare case which should be kept off the fast path.
284 */
285 if (JS_GetClassID(vectorObj) == sVectorClassID) {
286 *outVector = kZeroHPVector;
287 return YES;
288 }
289
290 return NO;
291
293}
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 BOOL OOJSIsMemberOfSubclass(JSContext *context, JSObject *object, JSClass *superclass)
float y
float x
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static BOOL GetArrayElementNumber(JSContext *context, JSValueConst array, uint32_t index, double *outNumber)
Definition OOJSVector.m:225
HPVector position
Definition Entity.m:576

References EXPECT, EXPECT_NOT, GetArrayElementNumber(), JSEntityClassID(), kZeroHPVector, make_HPvector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSIsMemberOfSubclass(), Entity::position, sVectorClassID, x, and y.

Here is the call graph for this function:

◆ JSValueToHPVector()

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

Definition at line 206 of file OOJSVector.m.

207{
208 if (EXPECT_NOT(!JS_IsObject(value)))
209 return NO;
210
211 return JSObjectGetVector(context, value, outVector);
212}

References EXPECT_NOT, and JSObjectGetVector().

Here is the call graph for this function:

◆ JSValueToVector()

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

Definition at line 214 of file OOJSVector.m.

215{
216 if (EXPECT_NOT(!JS_IsObject(value)))
217 return NO;
219 BOOL result = JSObjectGetVector(context, value, &tmp);
220 *outVector = HPVectorToVector(tmp);
221 return result;
222}
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175

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

Here is the call graph for this function:

◆ JSVectorSetHPVector()

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

Definition at line 309 of file OOJSVector.m.

310{
312
313 HPVector* private = NULL;
314
315 if (EXPECT_NOT(!JS_IsObject(vectorObj)))
316 return NO;
317
318private
319 = JS_GetOpaque(vectorObj, sVectorClassID);
320 if (private != NULL) // If this is a (JS) Vector...
321 {
322 *private = vector;
323 return YES;
324 }
325
326 if (JS_GetClassID(vectorObj) == sVectorClassID) {
327 // Silently fail for the prototype.
328 return YES;
329 }
330
331 return NO;
332
334}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sVectorClassID.

Referenced by JSVectorSetVector(), and VectorSetProperty().

Here is the caller graph for this function:

◆ JSVectorSetVector()

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

Definition at line 304 of file OOJSVector.m.

305{
306 return JSVectorSetHPVector(context, vectorObj, vectorToHPVector(vector));
307}
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()

JSValue JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 158 of file OOJSVector.m.

159{
161
162 HPVector* private = NULL;
163
164private
165 = malloc(sizeof *private);
166 if (EXPECT_NOT(private == NULL))
167 return JS_ThrowOutOfMemory(context);
168
169 *private = vector;
170
171 JSValue result = JS_NewObjectClass(context, sVectorClassID);
172 if (EXPECT_NOT(JS_IsException(result))) {
173 free(private);
174 return result;
175 }
176 JS_SetOpaque(result, private);
177
178 return result;
179
181}

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

◆ JSVectorWithVector()

JSValue JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 138 of file OOJSVector.m.

139{
141
142 return JSVectorWithHPVector(context, vectorToHPVector(vector));
143
145}

References EXPECT_NOT, JSVectorWithHPVector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, sVectorClass, sVectorPrototype, and vectorToHPVector().

Here is the call graph for this function:

◆ NSPointToVectorJSValue()

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

Definition at line 201 of file OOJSVector.m.

202{
203 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
204}
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().

Here is the call graph for this function:

◆ VectorAdd()

JSValue VectorAdd ( OOJS_NATIVE_ARGS )
static

Definition at line 538 of file OOJSVector.m.

539{
541
542 HPVector thisv, thatv, result;
543
544 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"add")))
545 return JS_EXCEPTION;
546 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"add", argc, OOJS_ARGV, &thatv, NULL)))
547 return JS_EXCEPTION;
548
549 result = HPvector_add(thisv, thatv);
550
551 OOJS_RETURN_HPVECTOR(result);
552
554}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorAngleTo()

JSValue VectorAngleTo ( OOJS_NATIVE_ARGS )
static

Definition at line 656 of file OOJSVector.m.

657{
659
660 HPVector thisv, thatv;
661 double result;
662
663 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"angleTo")))
664 return JS_EXCEPTION;
665 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"angleTo", argc, OOJS_ARGV, &thatv, NULL)))
666 return JS_EXCEPTION;
667
668 result = HPdot_product(HPvector_normal(thisv), HPvector_normal(thatv));
669 if (result > 1.0)
670 result = 1.0;
671 if (result < -1.0)
672 result = -1.0;
673 // for identical vectors the dot_product sometimes returns a value > 1.0 because of rounding errors, resulting
674 // in an undefined result for the acos.
675 result = acos(result);
676
677 OOJS_RETURN_DOUBLE(result);
678
680}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorConstruct()

JSValue VectorConstruct ( JSContext * context,
JSValueConst newTarget,
int argc,
JSValueConst * argv )
static

Definition at line 484 of file OOJSVector.m.

485{
487
488 HPVector vector = kZeroHPVector;
489
490 if (argc != 0) {
491 if (EXPECT_NOT(!VectorFromArgumentListNoErrorInternal(context, argc, argv, &vector, NULL, YES))) {
492 OOJSReportBadArguments(context, NULL, NULL, argc, argv,
493 @"Could not construct vector from parameters",
494 @"Vector, Entity or array of three numbers");
495 return JS_EXCEPTION;
496 }
497 }
498
499 return JSVectorWithHPVector(context, vector);
500
502}
static BOOL VectorFromArgumentListNoErrorInternal(JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed, BOOL permitNumberList)
Definition OOJSVector.m:336

References EXPECT_NOT, JSVectorWithHPVector(), kZeroHPVector, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSReportBadArguments(), and VectorFromArgumentListNoErrorInternal().

Here is the call graph for this function:

◆ VectorCross()

JSValue VectorCross ( OOJS_NATIVE_ARGS )
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, @"cross")))
690 return JS_EXCEPTION;
691 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"cross", argc, OOJS_ARGV, &thatv, NULL)))
692 return JS_EXCEPTION;
693
694 result = HPtrue_cross_product(thisv, thatv);
695
696 OOJS_RETURN_HPVECTOR(result);
697
699}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

◆ VectorDirection()

JSValue VectorDirection ( OOJS_NATIVE_ARGS )
static

Definition at line 728 of file OOJSVector.m.

729{
731
732 HPVector thisv, result;
733
734 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"direction")))
735 return JS_EXCEPTION;
736
737 result = HPvector_normal(thisv);
738
739 OOJS_RETURN_HPVECTOR(result);
740
742}

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

Here is the call graph for this function:

◆ VectorDistanceTo()

JSValue VectorDistanceTo ( OOJS_NATIVE_ARGS )
static

Definition at line 576 of file OOJSVector.m.

577{
579
580 HPVector thisv, thatv;
581 double result;
582
583 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"distanceTo")))
584 return JS_EXCEPTION;
585 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"distanceTo", argc, OOJS_ARGV, &thatv, NULL)))
586 return JS_EXCEPTION;
587
588 result = HPdistance(thisv, thatv);
589
590 OOJS_RETURN_DOUBLE(result);
591
593}
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298

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

Here is the call graph for this function:

◆ VectorDot()

JSValue VectorDot ( OOJS_NATIVE_ARGS )
static

Definition at line 636 of file OOJSVector.m.

637{
639
640 HPVector thisv, thatv;
641 double result;
642
643 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"dot")))
644 return JS_EXCEPTION;
645 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"dot", argc, OOJS_ARGV, &thatv, NULL)))
646 return JS_EXCEPTION;
647
648 result = HPdot_product(thisv, thatv);
649
650 OOJS_RETURN_DOUBLE(result);
651
653}

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

Here is the call graph for this function:

◆ VectorFinalize()

void VectorFinalize ( JSRuntime * runtime,
JSValueConst this )
static

Definition at line 475 of file OOJSVector.m.

476{
478
479 free(JS_GetOpaque(this, sVectorClassID));
480
482}
#define OOJS_PROFILE_EXIT_VOID

References OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_VOID, and sVectorClassID.

◆ VectorFromArgumentList()

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

Definition at line 384 of file OOJSVector.m.

385{
386 if (VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO))
387 return YES;
388 else {
389 OOJSReportBadArguments(context, scriptClass, function, argc, argv,
390 @"Could not construct vector from parameters",
391 @"Vector, Entity or array of three numbers");
392 return NO;
393 }
394}

References OOJSReportBadArguments(), and VectorFromArgumentListNoErrorInternal().

Referenced by VectorAdd(), VectorAngleTo(), VectorCross(), VectorDistanceTo(), VectorDot(), VectorRotationTo(), VectorSquaredDistanceTo(), VectorStaticInterpolate(), VectorSubtract(), and VectorTripleProduct().

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

◆ VectorFromArgumentListNoError()

BOOL VectorFromArgumentListNoError ( JSContext * context,
int argc,
JSValueConst * argv,
HPVector * outVector,
int * outConsumed )

Definition at line 396 of file OOJSVector.m.

397{
398 return VectorFromArgumentListNoErrorInternal(context, argc, argv, outVector, outConsumed, NO);
399}

References VectorFromArgumentListNoErrorInternal().

Here is the call graph for this function:

◆ VectorFromArgumentListNoErrorInternal()

BOOL VectorFromArgumentListNoErrorInternal ( JSContext * context,
int argc,
JSValueConst * argv,
HPVector * outVector,
int * outConsumed,
BOOL permitNumberList )
static

Definition at line 336 of file OOJSVector.m.

337{
339
340 double x, y, z;
341
342 if (EXPECT_NOT(argc == 0))
343 return NO;
344 assert(argv != NULL && outVector != NULL);
345
346 if (outConsumed != NULL)
347 *outConsumed = 0;
348
349 // Is first object a vector, array or entity?
350 if (JS_IsObject(argv[0])) {
351 if (JSObjectGetVector(context, argv[0], outVector)) {
352 if (outConsumed != NULL)
353 *outConsumed = 1;
354 return YES;
355 }
356 }
357
358 if (!permitNumberList)
359 return NO;
360
361 // As a special case for VectorConstruct(), look for three numbers.
362 if (argc < 3)
363 return NO;
364
365 // Given a string, JS_ToFloat64() succeeds but provides a NaN number.
366 if (EXPECT_NOT(JS_ToFloat64(context, &x, argv[0]) < 0 || isnan(x)))
367 return NO;
368 if (EXPECT_NOT(JS_ToFloat64(context, &y, argv[1]) < 0 || isnan(y)))
369 return NO;
370 if (EXPECT_NOT(JS_ToFloat64(context, &z, argv[2]) < 0 || isnan(z)))
371 return NO;
372
373 // We got our three numbers.
374 *outVector = make_HPvector(x, y, z);
375 if (outConsumed != NULL)
376 *outConsumed = 3;
377
378 return YES;
379
381}

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

JSValue VectorFromCoordinateSystem ( OOJS_NATIVE_ARGS )
static

Definition at line 982 of file OOJSVector.m.

983{
984 OOJS_NATIVE_ENTER(context)
985
986 HPVector thisv;
987 NSString* coordScheme = nil;
988 HPVector result;
989
990 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"fromCoordinateSystem")))
991 return JS_EXCEPTION;
992
993 if (argc > 0)
994 coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0]);
995 if (EXPECT_NOT(coordScheme == nil)) {
996 OOJSReportBadArguments(context, @"Vector3D", @"fromCoordinateSystem", MIN(argc, 1), OOJS_ARGV, nil, @"coordinate system");
997 return OOJSNativeFailure(context);
998 }
999
1000 OOJS_BEGIN_FULL_NATIVE(context)
1001 NSString* arg = [NSString stringWithFormat:@"%@ %f %f %f", coordScheme, thisv.x, thisv.y, thisv.z];
1002 result = [UNIVERSE coordinatesFromCoordinateSystemString:arg];
1004
1005 OOJS_RETURN_HPVECTOR(result);
1006
1008}
#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
JSValue OOJSNativeFailure(JSContext *context)

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

Here is the call graph for this function:

◆ VectorGetProperty()

JSValue VectorGetProperty ( JSContext * context,
JSValueConst this,
int magic )
static

Definition at line 403 of file OOJSVector.m.

404{
406
407 HPVector vector;
408 OOHPScalar fValue;
409
410 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector)))
411 return JS_UNDEFINED;
412
413 switch (magic) {
414 case kVector_x:
415 fValue = vector.x;
416 break;
417
418 case kVector_y:
419 fValue = vector.y;
420 break;
421
422 case kVector_z:
423 fValue = vector.z;
424 break;
425
426 default:
428 return JS_EXCEPTION;
429 }
430
431 return JS_NewFloat64(context, fValue);
432
434}
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_COUNT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSReportBadPropertySelector(), and sVectorProperties.

Here is the call graph for this function:

◆ VectorMagnitude()

JSValue VectorMagnitude ( OOJS_NATIVE_ARGS )
static

Definition at line 745 of file OOJSVector.m.

746{
748
749 HPVector thisv;
750 double result;
751
752 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"magnitude")))
753 return JS_EXCEPTION;
754
755 result = HPmagnitude(thisv);
756
757 OOJS_RETURN_DOUBLE(result);
758
760}
OOINLINE OOHPScalar HPmagnitude(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:260

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

Here is the call graph for this function:

◆ VectorMultiply()

JSValue VectorMultiply ( OOJS_NATIVE_ARGS )
static

Definition at line 616 of file OOJSVector.m.

617{
619
620 HPVector thisv, result;
621 double scalar;
622
623 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"multiply")))
624 return JS_EXCEPTION;
625 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"multiply", argc, OOJS_ARGV, &scalar, NULL)))
626 return JS_EXCEPTION;
627
628 result = HPvector_multiply_scalar(thisv, scalar);
629
630 OOJS_RETURN_HPVECTOR(result);
631
633}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, OOJS_THIS, and OOJSArgumentListGetNumber().

Here is the call graph for this function:

◆ VectorRotateBy()

JSValue VectorRotateBy ( OOJS_NATIVE_ARGS )
static

Definition at line 818 of file OOJSVector.m.

819{
821
822 HPVector thisv, result;
823 Quaternion q;
824
825 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotateBy")))
826 return JS_EXCEPTION;
827 if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Vector3D", @"rotateBy", argc, OOJS_ARGV, &q, NULL)))
828 return JS_EXCEPTION;
829
830 result = quaternion_rotate_HPvector(q, thisv);
831
832 OOJS_RETURN_HPVECTOR(result);
833
835}
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_NATIVE_ARGS, 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()

JSValue VectorRotationTo ( OOJS_NATIVE_ARGS )
static

Definition at line 781 of file OOJSVector.m.

782{
784
785 HPVector thisv, thatv;
786 double limit;
787 BOOL gotLimit;
788 Quaternion result;
789 int consumed;
790 JSValueConst* argv = OOJS_ARGV;
791
792 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"rotationTo")))
793 return JS_EXCEPTION;
794 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"rotationTo", argc, OOJS_ARGV, &thatv, &consumed)))
795 return JS_EXCEPTION;
796
797 argc -= consumed;
798 argv += consumed;
799 if (argc != 0) // limit parameter is optional.
800 {
801 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"rotationTo", argc, argv, &limit, NULL)))
802 return JS_EXCEPTION;
803 gotLimit = YES;
804 } else
805 gotLimit = NO;
806
807 if (gotLimit)
809 else
811
813
815}
#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_NATIVE_ARGS, 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()

JSValue VectorSetProperty ( JSContext * context,
JSValueConst this,
JSValueConst value,
int magic )
static

Definition at line 436 of file OOJSVector.m.

437{
439
440 HPVector vector;
441 double dval;
442
443 if (EXPECT_NOT(!JSObjectGetVector(context, this, &vector)))
444 return JS_UNDEFINED;
445 if (EXPECT_NOT(JS_ToFloat64(context, &dval, value) < 0)) {
446 JS_FreeValue(context, JS_GetException(context));
448 return JS_EXCEPTION;
449 }
450
451 switch (magic) {
452 case kVector_x:
453 vector.x = dval;
454 break;
455
456 case kVector_y:
457 vector.y = dval;
458 break;
459
460 case kVector_z:
461 vector.z = dval;
462 break;
463
464 default:
466 return JS_EXCEPTION;
467 }
468
469 JSVectorSetHPVector(context, this, vector);
470 return JS_UNDEFINED;
471
473}
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)

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

Here is the call graph for this function:

◆ VectorSquaredDistanceTo()

JSValue VectorSquaredDistanceTo ( OOJS_NATIVE_ARGS )
static

Definition at line 596 of file OOJSVector.m.

597{
599
600 HPVector thisv, thatv;
601 double result;
602
603 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredDistanceTo")))
604 return JS_EXCEPTION;
605 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"squaredDistanceTo", argc, OOJS_ARGV, &thatv, NULL)))
606 return JS_EXCEPTION;
607
608 result = HPdistance2(thisv, thatv);
609
610 OOJS_RETURN_DOUBLE(result);
611
613}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293

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

Here is the call graph for this function:

◆ VectorSquaredMagnitude()

JSValue VectorSquaredMagnitude ( OOJS_NATIVE_ARGS )
static

Definition at line 763 of file OOJSVector.m.

764{
766
767 HPVector thisv;
768 double result;
769
770 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"squaredMagnitude")))
771 return JS_EXCEPTION;
772
773 result = HPmagnitude2(thisv);
774
775 OOJS_RETURN_DOUBLE(result);
776
778}
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255

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

Here is the call graph for this function:

◆ VectorStaticInterpolate()

JSValue VectorStaticInterpolate ( OOJS_NATIVE_ARGS )
static

Definition at line 865 of file OOJSVector.m.

866{
868
869 HPVector av, bv;
870 double interp;
871 HPVector result;
872 int consumed;
873 int inArgc = argc;
874 JSValueConst* argv = OOJS_ARGV;
875 JSValueConst* inArgv = argv;
876
877 if (EXPECT_NOT(argc < 3))
878 goto INSUFFICIENT_ARGUMENTS;
879 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &av, &consumed)))
880 return JS_EXCEPTION;
881 argc -= consumed;
882 argv += consumed;
883 if (EXPECT_NOT(argc < 2))
884 goto INSUFFICIENT_ARGUMENTS;
885 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"interpolate", argc, argv, &bv, &consumed)))
886 return JS_EXCEPTION;
887 argc -= consumed;
888 argv += consumed;
889 if (EXPECT_NOT(argc < 1))
890 goto INSUFFICIENT_ARGUMENTS;
891 if (EXPECT_NOT(!OOJSArgumentListGetNumber(context, @"Vector3D", @"interpolate", argc, argv, &interp, NULL)))
892 return JS_EXCEPTION;
893
894 result = OOHPVectorInterpolate(av, bv, interp);
895
896 OOJS_RETURN_HPVECTOR(result);
897
898INSUFFICIENT_ARGUMENTS:
899 OOJSReportBadArguments(context, @"Vector3D", @"interpolate", inArgc, inArgv,
900 @"Insufficient parameters",
901 @"vector expression, vector expression and number");
902 return JS_EXCEPTION;
903
905}
OOINLINE HPVector OOHPVectorInterpolate(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
Definition OOHPVector.h:222

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

Here is the call graph for this function:

◆ VectorStaticRandom()

JSValue VectorStaticRandom ( OOJS_NATIVE_ARGS )
static

Definition at line 908 of file OOJSVector.m.

909{
911
912 double maxLength;
913
914 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL))
915 maxLength = 1.0;
916
918
920}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_HPVECTOR, and OOJSArgumentListGetNumberNoError().

Here is the call graph for this function:

◆ VectorStaticRandomDirection()

JSValue VectorStaticRandomDirection ( OOJS_NATIVE_ARGS )
static

Definition at line 923 of file OOJSVector.m.

924{
926
927 double scale;
928
929 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &scale, NULL))
930 scale = 1.0;
931
933
935}
HPVector OORandomUnitHPVector(void)
Definition OOHPVector.m:62

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

Here is the call graph for this function:

◆ VectorStaticRandomDirectionAndLength()

JSValue VectorStaticRandomDirectionAndLength ( OOJS_NATIVE_ARGS )
static

Definition at line 938 of file OOJSVector.m.

939{
941
942 double maxLength;
943
944 if (argc == 0 || !OOJSArgumentListGetNumberNoError(context, argc, OOJS_ARGV, &maxLength, NULL))
945 maxLength = 1.0;
946
948
950}
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
Definition OOHPVector.m:88

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

Here is the call graph for this function:

◆ VectorSubtract()

JSValue VectorSubtract ( OOJS_NATIVE_ARGS )
static

Definition at line 557 of file OOJSVector.m.

558{
560
561 HPVector thisv, thatv, result;
562
563 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"subtract")))
564 return JS_EXCEPTION;
565 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"subtract", argc, OOJS_ARGV, &thatv, NULL)))
566 return JS_EXCEPTION;
567
568 result = HPvector_subtract(thisv, thatv);
569
570 OOJS_RETURN_HPVECTOR(result);
571
573}
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236

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

Here is the call graph for this function:

◆ VectorToArray()

JSValue VectorToArray ( OOJS_NATIVE_ARGS )
static

Definition at line 838 of file OOJSVector.m.

839{
841
842 HPVector thisv;
843
844 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toArray")))
845 return JS_EXCEPTION;
846
847 JSValue result = JS_NewArray(context);
848 if (EXPECT_NOT(JS_IsException(result)))
849 return result;
850
851 // JS_SetPropertyUint32() takes ownership of the element values.
852 if (JS_SetPropertyUint32(context, result, 0, JS_NewFloat64(context, thisv.x)) < 0 || JS_SetPropertyUint32(context, result, 1, JS_NewFloat64(context, thisv.y)) < 0 || JS_SetPropertyUint32(context, result, 2, JS_NewFloat64(context, thisv.z)) < 0) {
853 JS_FreeValue(context, result);
854 return JS_EXCEPTION;
855 }
856
857 return result;
858
860}

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

Here is the call graph for this function:

◆ VectorToCoordinateSystem()

JSValue VectorToCoordinateSystem ( OOJS_NATIVE_ARGS )
static

Definition at line 954 of file OOJSVector.m.

955{
956 OOJS_NATIVE_ENTER(context)
957
958 HPVector thisv;
959 NSString* coordScheme = nil;
960 HPVector result;
961
962 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toCoordinateSystem")))
963 return JS_EXCEPTION;
964
965 if (argc > 0)
966 coordScheme = OOStringFromJSValue(context, OOJS_ARGV[0]);
967 if (EXPECT_NOT(coordScheme == nil)) {
968 OOJSReportBadArguments(context, @"Vector3D", @"toCoordinateSystem", MIN(argc, 1), OOJS_ARGV, nil, @"coordinate system");
969 return OOJSNativeFailure(context);
970 }
971
973 result = [UNIVERSE legacyPositionFrom:thisv asCoordinateSystem:coordScheme];
975
976 OOJS_RETURN_HPVECTOR(result);
977
979}

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

Here is the call graph for this function:

◆ VectorToJSValue()

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

Definition at line 147 of file OOJSVector.m.

148{
150
151 assert(outValue != NULL);
152
153 return HPVectorToJSValue(context, vectorToHPVector(vector), outValue);
154
156}
BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue)
Definition OOJSVector.m:310

References HPVectorToJSValue(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and vectorToHPVector().

Here is the call graph for this function:

◆ VectorToSource()

JSValue VectorToSource ( OOJS_NATIVE_ARGS )
static

Definition at line 522 of file OOJSVector.m.

523{
524 OOJS_NATIVE_ENTER(context)
525
526 HPVector thisv;
527
528 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toSource")))
529 return JS_EXCEPTION;
530
531 NSString* str = [NSString stringWithFormat:@"Vector3D(%g, %g, %g)", thisv.x, thisv.y, thisv.z];
533
535}
#define OOJS_RETURN_OBJECT(o)

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

Here is the call graph for this function:

◆ VectorToString()

JSValue VectorToString ( OOJS_NATIVE_ARGS )
static

Definition at line 507 of file OOJSVector.m.

508{
509 OOJS_NATIVE_ENTER(context)
510
511 HPVector thisv;
512
513 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"toString")))
514 return JS_EXCEPTION;
515
516 OOJS_RETURN_OBJECT(HPVectorDescription(thisv));
517
519}

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

Here is the call graph for this function:

◆ VectorTripleProduct()

JSValue VectorTripleProduct ( OOJS_NATIVE_ARGS )
static

Definition at line 702 of file OOJSVector.m.

703{
705
706 HPVector thisv, thatv, theotherv;
707 double result;
708 int consumed;
709 JSValueConst* argv = OOJS_ARGV;
710
711 if (EXPECT_NOT(!GetThisVector(context, OOJS_THIS, &thisv, @"tripleProduct")))
712 return JS_EXCEPTION;
713 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &thatv, &consumed)))
714 return JS_EXCEPTION;
715 argc -= consumed;
716 argv += consumed;
717 if (EXPECT_NOT(!VectorFromArgumentList(context, @"Vector3D", @"tripleProduct", argc, argv, &theotherv, NULL)))
718 return JS_EXCEPTION;
719
720 result = HPtriple_product(thisv, thatv, theotherv);
721
722 OOJS_RETURN_DOUBLE(result);
723
725}
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_NATIVE_ARGS, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, and VectorFromArgumentList().

Here is the call graph for this function:

Variable Documentation

◆ sVectorClass

JSClassDef sVectorClass
static
Initial value:
= {
.class_name = "Vector3D",
.finalizer = VectorFinalize,
}
static void VectorFinalize(JSContext *context, JSObject *this)
Definition OOJSVector.m:668

Definition at line 73 of file OOJSVector.m.

73 {
74 .class_name = "Vector3D",
75 .finalizer = VectorFinalize,
76};

◆ sVectorClassID

JSClassID sVectorClassID
static

◆ sVectorMethods

const JSCFunctionListEntry sVectorMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("toSource", 0, VectorToSource),
JS_CFUNC_DEF("toString", 0, VectorToString),
JS_CFUNC_DEF("add", 1, VectorAdd),
JS_CFUNC_DEF("angleTo", 1, VectorAngleTo),
JS_CFUNC_DEF("cross", 1, VectorCross),
JS_CFUNC_DEF("direction", 0, VectorDirection),
JS_CFUNC_DEF("fromCoordinateSystem", 1, VectorFromCoordinateSystem),
JS_CFUNC_DEF("distanceTo", 1, VectorDistanceTo),
JS_CFUNC_DEF("dot", 1, VectorDot),
JS_CFUNC_DEF("magnitude", 0, VectorMagnitude),
JS_CFUNC_DEF("multiply", 1, VectorMultiply),
JS_CFUNC_DEF("rotateBy", 1, VectorRotateBy),
JS_CFUNC_DEF("rotationTo", 1, VectorRotationTo),
JS_CFUNC_DEF("squaredDistanceTo", 1, VectorSquaredDistanceTo),
JS_CFUNC_DEF("squaredMagnitude", 0, VectorSquaredMagnitude),
JS_CFUNC_DEF("subtract", 1, VectorSubtract),
JS_CFUNC_DEF("toArray", 0, VectorToArray),
JS_CFUNC_DEF("toCoordinateSystem", 1, VectorToCoordinateSystem),
JS_CFUNC_DEF("tripleProduct", 2, VectorTripleProduct),
}
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

Definition at line 92 of file OOJSVector.m.

92 {
93 // JS name, min args, function
94 JS_CFUNC_DEF("toSource", 0, VectorToSource),
95 JS_CFUNC_DEF("toString", 0, VectorToString),
96 JS_CFUNC_DEF("add", 1, VectorAdd),
97 JS_CFUNC_DEF("angleTo", 1, VectorAngleTo),
98 JS_CFUNC_DEF("cross", 1, VectorCross),
99 JS_CFUNC_DEF("direction", 0, VectorDirection),
100#ifndef OOJS_POC_HARNESS
101 JS_CFUNC_DEF("fromCoordinateSystem", 1, VectorFromCoordinateSystem),
102#endif
103 JS_CFUNC_DEF("distanceTo", 1, VectorDistanceTo),
104 JS_CFUNC_DEF("dot", 1, VectorDot),
105 JS_CFUNC_DEF("magnitude", 0, VectorMagnitude),
106 JS_CFUNC_DEF("multiply", 1, VectorMultiply),
107 JS_CFUNC_DEF("rotateBy", 1, VectorRotateBy),
108 JS_CFUNC_DEF("rotationTo", 1, VectorRotationTo),
109 JS_CFUNC_DEF("squaredDistanceTo", 1, VectorSquaredDistanceTo),
110 JS_CFUNC_DEF("squaredMagnitude", 0, VectorSquaredMagnitude),
111 JS_CFUNC_DEF("subtract", 1, VectorSubtract),
112 JS_CFUNC_DEF("toArray", 0, VectorToArray),
113#ifndef OOJS_POC_HARNESS
114 JS_CFUNC_DEF("toCoordinateSystem", 1, VectorToCoordinateSystem),
115#endif
116 JS_CFUNC_DEF("tripleProduct", 2, VectorTripleProduct),
117};

◆ sVectorProperties

const JSCFunctionListEntry sVectorProperties[]
static
Initial value:
= {
}
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
#define OOJS_PROP_READWRITE_CB

Definition at line 85 of file OOJSVector.m.

85 {
86 // JS name, getter, setter, ID, flags
90};

◆ sVectorStaticMethods

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

119 {
120 // JS name, min args, function
121 JS_CFUNC_DEF("interpolate", 3, VectorStaticInterpolate),
122 JS_CFUNC_DEF("random", 0, VectorStaticRandom),
123 JS_CFUNC_DEF("randomDirection", 0, VectorStaticRandomDirection),
124 JS_CFUNC_DEF("randomDirectionAndLength", 0, VectorStaticRandomDirectionAndLength),
125};