Float 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 r3Float object type.

For example, the r3nurbs curve class implements method MEASURELENGTH(len), which returns the lenght of the curve through the function parameter 'len'. This would not be possible using JavaScript basic types:

// wont't work
var len;
curve.MEASURELENGHT(len);

because JavaScript basic types are passed to function as call-by-value parameters. To allow the MEASURELENGHT() method to actually change the value of the 'len' parameter, call-by-reference is required.

// this works
var len = new r3Float();
curve.MEASURELENGHT(len);

Methods
Method:

r3Float - constructor for float

Syntax:

v = new r3Float()

Parameters:

value - floating point number

Returns:

v - new float object

Description:

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

Example:

v = new r3Float(10);

Method:

add - addition

Syntax:

v2 = v.add(v1);

Parameters:

v1 - float

Returns:

v2 = result float

Description:

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

Example:

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

Method:

fadd - float addition

Syntax:

v.fadd(v2);

Parameters:

v2 - float to be added

Returns:

-

Description:

Float operation v = v+v2.

Example:

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

Method:

set - set value

Syntax:

v.set(value);

Parameters:

value - floating point number

Returns:

-

Description:

Set new value to the float

Example:

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

Method:

sub - float subtraction

Syntax:

v3 = v.sub(v2);

Parameters:

v2 - float to be subracted

Returns:

float - the result of the subtraction

Description:

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

Example:

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

Method:

fsub - float subtraction

Syntax:

v.fsub(v2);

Parameters:

v2 - float to be subracted

Returns:

-

Description:

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

Example:

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

Method:

neg - negate

Syntax:

v2 = v.neg();

Parameters:

-

Returns:

v2 - float

Description:

Returns negative value of the object.

Example:

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

Method:

fneg - negative

Syntax:

v.neg();

Parameters:

-

Returns:

-

Description:

Makes the float negative float.

Example:

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

Method:

mul - multiplication

Syntax:

v2 = v.mul(f);

Parameters:

f - float number

Returns:

v2 - result

Description:

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

Example:

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

Method:

fmul - multiplication

Syntax:

v.fmul(f);

Parameters:

f - floating point number

Returns:

-

Description:

Multiplies the float by given value

Example:

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

Method:

div - division by scalar

Syntax:

v2 = v.div(f);

Parameters:

f - floating point number

Returns:

v2 - float

Description:

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

Example:

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

Method:

fdiv - division by scalar

Syntax:

v.fdiv(f);

Parameters:

f - floating point number

Returns:

-

Description:

Divides the float by given value.

Example:

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

Method:

cmul

Syntax:

v3 = v.cmul(v2);

Parameters:

v2 - float

Returns:

v3 - float

Description:

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

Example:

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

Method:

cmp - compare

Syntax:

b = v.cmp(v2, tolerance);

Parameters:

v2 - float

tolerance - tolerance

Returns:

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

Description:

Compare the given float 'v2' agains the float in question and return true if the floats 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 float

Syntax:

v.print()

Parameters:

-

Returns:

-

Description:

Print out the current value of the float.

Example:

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