Skip to content
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

Confusing example for PVector copy() method #577

Open
stuydw opened this issue Nov 21, 2024 · 0 comments
Open

Confusing example for PVector copy() method #577

stuydw opened this issue Nov 21, 2024 · 0 comments

Comments

@stuydw
Copy link

stuydw commented Nov 21, 2024

Select the type of content error.

Other content error (please specify)

Section

Examples

Location of the error

https://processing.org/reference/PVector_copy_.html

Describe the error

In the documentation for the copy() method of the PVector class, the following code example is given:

PVector v1, v2;

void setup() {
  size(100, 100);
  v1 = new PVector(20.0, 30.0, 40.0);
  v2 = new PVector();
  v2 = v1.copy();
  ...

While not a factual error, it seems curious to me that v2 would be instantiated as a new PVector only to be assigned the result of v1.copy(). If .copy() creates a returns a new PVector object, then the initial assignment would have no effect. This led to some confusion amongst my students who had various incorrect assumptions about how .copy() works given the example code.

Suggested correction

PVector v1, v2;

void setup() {
  size(100, 100);
  v1 = new PVector(20.0, 30.0, 40.0);
  v2 = v1.copy();
  ...

Language

No response

Screenshots or references

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant