Skip to content

[p5.js 2.0 Bug Report] : v.div(2, 4, 6) divides everything by first arg only, v.mult(2, 3, 4) does nothing #8539

@avinxshKD

Description

@avinxshKD

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.2.1-rc.0

Web browser and version

Any (reproduced on Chrome 132)

Operating system

Windows 11

Steps to reproduce this

div() with multiple number args uses args[0] for all components instead of args[i]. So v.div(2, 4, 6) on (10, 20, 30) gives (5, 10, 15) instead of (5, 5, 5)

One char typo p5.Vector.js line 1241:

this._values = this._values.map((val, i) => val / args[0]); // should be args[i]

Also mult() straight up has no branch for multiple number args. v.mult(2, 3, 4) silently returns the vector unchanged. No warning, nothing. Docs say both should work

add() and sub() handle this fine btw

function setup() {
  let v1 = createVector(10, 20, 30);
  v1.div(2, 4, 6);
  console.log(v1.toString()); // (5, 10, 15) — wrong, should be (5, 5, 5)

  let v2 = createVector(10, 20, 30);
  v2.mult(2, 3, 4);
  console.log(v2.toString()); // (10, 20, 30) — unchanged, should be (20, 60, 120)
}

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