Skip to content

[p5.js 2.0 Bug Report]: If you create a p5.Vector without arguments, the 2d vector subtracted by it will be strange. #8117

@inaridarkfox4231

Description

@inaridarkfox4231

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

Chrome

Operating system

Windows

Steps to reproduce this

Steps:

  1. Create a vector without arguments.
  2. Create a 2D vector and subtract the vector you prepared earlier.
  3. The third component will be NaN. Furthermore, If you apply rotate() to it, all components will become NaN.

Snippet:

function setup() {
  createCanvas(400,400);
  const v=createVector(100,0);
  const w=createVector();
  v.sub(w);
  console.log(v.toString());
  v.rotate(1);
  console.log(v.toString());
}
Image

If you explicitly make it two-dimensional with two zeros, there is no problem.

Image

This issue has been occurring since version 2.0.0. It has not occurred in version 1.x.

Image Image

Specifying a value without arguments is a common practice when creating a default vector, whether in two or three dimensions, so I thought this could be inconvenient in some cases.

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