processing / processing/p5.js

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

Open
#8,539 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Math p5.js 2.0+
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

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)
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in p5.Vector.js at the reported div() line and inspect the mult() implementation, comparing both with add() and sub(). Verify the documented multi-argument examples produce the expected vector components and add regression coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.