New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Side effect of the set method inside the PVector class #5092

Closed
Maharal opened this Issue May 27, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@Maharal

Maharal commented May 27, 2017

If the user passes a vector with a size different than 2 and 3 as a parameter to the set method, there will be side effects.

// line 197, https://github.com/processing/processing/blob/master/core/src/processing/core/PVector.java
public PVector set(float[] source) {
  if (source.length >= 2) {
    x = source[0];
    y = source[1]; 
  }
  if (source.length >= 3) {
    z = source[2];
  }
  return this;
}
@GKFX

This comment has been minimized.

Show comment
Hide comment
@GKFX

GKFX May 30, 2017

Contributor

What side effects? It looks like the later members of source just get ignored.

Contributor

GKFX commented May 30, 2017

What side effects? It looks like the later members of source just get ignored.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Jun 1, 2017

Member

It's just an esoteric edge case where if someone had a 3D vector and decided to set it using a 2D vector, the z coordinate wouldn't get zeroed out. I've added a fix for 3.3.4.

Member

benfry commented Jun 1, 2017

It's just an esoteric edge case where if someone had a 3D vector and decided to set it using a 2D vector, the z coordinate wouldn't get zeroed out. I've added a fix for 3.3.4.

@benfry benfry closed this in 446485a Jun 1, 2017

@GoToLoop

This comment has been minimized.

Show comment
Hide comment
@GoToLoop

GoToLoop Jun 4, 2017

Zeroing the field z for set(float, float) & set(float[]) w/ length = 2 @ version 3.3.4, breaks any older code, such as Pjs sketches, which would expect z's current value to be kept for those overloaded set() cases.

GoToLoop commented Jun 4, 2017

Zeroing the field z for set(float, float) & set(float[]) w/ length = 2 @ version 3.3.4, breaks any older code, such as Pjs sketches, which would expect z's current value to be kept for those overloaded set() cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment