processing-website icon indicating copy to clipboard operation
processing-website copied to clipboard

Confusing example for PVector copy() method

Open stuydw opened this issue 1 year ago • 1 comments

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

stuydw avatar Nov 21 '24 13:11 stuydw

I am a beginner, and I can work on this issue as it still exists.

aaryan359 avatar Mar 03 '25 19:03 aaryan359

Hi @Stefterv ! I'd like to work on this issue. I agree that the example is confusing and the line v2 = new PVector(); is unnecessary since v1.copy() already creates and returns a new PVector object.

My plan is to:

  1. Remove line 5 (v2 = new PVector();) from the file content/references/examples/processing/PVector_copy_/PVector_copy_0.pde
  2. Test the change locally to ensure the documentation renders correctly
  3. Submit a PR with the fix

Could I be assigned to this issue so that I can submit the PR?

R-Kri avatar Oct 28 '25 18:10 R-Kri