Skip to content

[p5.js 2.0 Bug Report]: p5.Vector.random2D() creates a 3D vector instead of a 2D vector. #8118

@sidwellr

Description

@sidwellr

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0.5

Web browser and version

Brave 1.81.136

Operating system

Linux Mint 6.8.0-78-generic

Steps to reproduce this

Vectors in version 1 are always 3D, so this was correct. But version 2 allows arbitrary length vectors, including 2D vectors, so p5.Vector.random2D() should create a 2D vector now. It is common to add the random vector to an existing one, and adding a 3D vector to a 2D one creates an inconsistent result (see my comment to issue #8117).

The first example in the documentation shows an example of this:

function setup() {
  // Create a p5.Vector object.
  let v = p5.Vector.random2D();

  // Prints "p5.Vector Object : [x, y, 0]" to the console
  // where x and y are small random numbers.
  print(v.toString());
}

The code should print the 2D vector "[x, y]", not the 3D vector "[x, y, 0]". (The example will need to be updated as well.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions