Issue #4 invalid

Evaluating functions within Vec3D methods...

Anonymous created an issue

Hi there, I'm not sure if this is the right place to bring up issues, but I'm having a bit of a weird one.

The problem is best described as:

Vec3D v = new Vec3D(100, 100, 100); float scaler = 1/10; v = v.scale(scaler);

Printing v in this case will return 0, 0, -0

as if scaler is void.

However, if I instead do:

Vec3D v = new Vec3D(100, 100, 100); float scaler = 0.1; v = v.scale(scaler);

then printing v will return 10, 10, 10.

It's as if the .scaler method does not want to evaluate functions / equations and treats them as void.

Not sure if this is user error at this end, if so then please ignore me! I'm using Processing 1.2.1 and toxiclibs 0019a and 0018.



Comments (1)

  1. Karsten Schmidt repo owner

    Hi Sam,

    thanks for the effort of creating a ticket, however judging from your example, the issue has nothing to do with the Vec3D class, but is a subtle human error in this java expression:

    float scaler = 1/10;

    The result of this division will not be 0.1 as you might have thought, but will be zero! This is because both 1 and 10 are integer values and so the result of their division will be an integer too, even though you want the result as a float (as you indicated). The correct way of writing such a term would be:

    float scaler = 1.0f/10; or
    float scaler = 1/10f; or
    float scaler = (float)1/10;

    The "f" suffix forces a number to be a float.

    Hope this clears up your confusion! Ps. We all will have made this mistake at some point... :)

  2. Log in to comment