Integer Class

JavaScript does not support call-by-reference type of function parameters for basic types. Correspondingly, Realsoft 3D methods returning data back to the caller through the method parameters won't work. To overcome this limitation Realsoft 3D implements r3Int object type.

Methods
Method:

r3Int - constructor for int

Syntax:

v = new r3Int()

Parameters:

value - inting point number

Returns:

v - new int object

Description:

Creates a new int object. If you don't pass any parameters to the constructor, the value is initialized to zero.

Example:

v = new r3Int(10);

Method:

add - addition

Syntax:

v2 = v.add(v1);

Parameters:

v1 - int

Returns:

v2 = result int

Description:

This adds the given int to the object in question and returns the result as a new integer. The operation doesn't change the value of the object.

Example:

v = new r3Int(0.1);
r = v.add(0.1);

Method:

fadd - int addition

Syntax:

v.fadd(v2);

Parameters:

v2 - int to be added

Returns:

-

Description:

Int operation v = v+v2.

Example:

v = new r3Int(1);
v.fadd(0.1); // add 0.1 to the current value 

Method:

set - set value

Syntax:

v.set(value);

Parameters:

value - inting point number

Returns:

-

Description:

Set new value to the int

Example:

v = new r3Int();
v.set(10.3);

Method:

sub - int subtraction

Syntax:

v3 = v.sub(v2);

Parameters:

v2 - int to be subracted

Returns:

int - the result of the subtraction

Description:

Returns a new int containing the result of int operation 'v - v2'.

Example:

v = new r3Int(10);
v2 = v.sub(5);
v2.print(); // 5

Method:

fsub - int subtraction

Syntax:

v.fsub(v2);

Parameters:

v2 - int to be subracted

Returns:

-

Description:

Subtracts given int 'v2' from the int in question.

Example:

v = new r3Int(1);
v.fsub(0.5);
v.print(); // 0.5 

Method:

neg - negate

Syntax:

v2 = v.neg();

Parameters:

-

Returns:

v2 - int

Description:

Returns negative value of the object.

Example:

v = new r3Int(1);
v2 = v.neg();

Method:

fneg - negative

Syntax:

v.neg();

Parameters:

-

Returns:

-

Description:

Makes the int negative integer.

Example:

v = new r3Int(1);
v.fneg();
v.print(); // -1

Method:

mul - multiplication

Syntax:

v2 = v.mul(f);

Parameters:

f - int number

Returns:

v2 - result

Description:

Multiplies the int with the given value and returns the value.

Example:

v = new r3Int(2);
v2 = v.mul(10);
v2.print(); // 20

Method:

fmul - multiplication

Syntax:

v.fmul(f);

Parameters:

f - inting point number

Returns:

-

Description:

Multiplies the int by given value

Example:

v = new r3Int(2);
v.fmul(10); // new value == 20 

Method:

div - division by scalar

Syntax:

v2 = v.div(f);

Parameters:

f - inting point number

Returns:

v2 - int

Description:

Divides the int by given value and returns a new int holding the result.

Example:

v = new r3Int(10);
v2 = v.div(2);
v2.print(); // 5

Method:

fdiv - division by scalar

Syntax:

v.fdiv(f);

Parameters:

f - inting point number

Returns:

-

Description:

Divides the int by given value.

Example:

v = new r3Int(1);
v.fdiv(2); // 0.5 

Method:

cmul

Syntax:

v3 = v.cmul(v2);

Parameters:

v2 - int

Returns:

v3 - int

Description:

Component wise multiplication. Multiplies each component in 'v' by corresponding component of 'v2' and returns the result as a new integer.

Example:

v = new r3Vect(1, 2, 3);

Method:

cmp - compare

Syntax:

b = v.cmp(v2, tolerance);

Parameters:

v2 - int

tolerance - tolerance

Returns:

b - boolean, true if ints are identical within the given tolerance

Description:

Compare the given int 'v2' agains the int in question and return true if the ints are within the given tolerance. Otherwise returns false.

Example:

v = new r3Vect(1.1);
if(v.cmp(1.2, 0.01)) {
    print("Not identical");
} else {
    print("Identical");
}

Method:

print - print int

Syntax:

v.print()

Parameters:

-

Returns:

-

Description:

Print out the current value of the integer.

Example:

v.set(1.5);
v.print();