processing/p5.js

Incorrect FES message for normal()

nickmcintyre opened this issue · 2 comments

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

1.9.2

Web browser and version

Chrome 124.0.6367.60

Operating system

macOS 14.4.1

Steps to reproduce this

Steps:

  1. Create a p5.Vector object.
  2. Pass the object to normal().

Snippet:

// Create a p5.Vector object.
let n = createVector(-0.4, -0.4, 0.8);

// Draw the shape.
// Use normal() to set vertex normals.
beginShape();
normal(n);
vertex(-30, -30, 0);
// ...rest of the shape.
endShape();

I noticed this while working on the reference. Passing a p5.Vector to normal() generates the following FES message:

🌸 p5.js says: [sketch.js, line 29] normal() was expecting Vector
for the first parameter, received object instead. (http://p5js.org/reference/#/p5/normal)

See the full sketch.

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

Hey,

I was able to replicate this issue and possibly found a fix.
It seems that in src\core\shape\vertex.js for the normal() method the documentation was written as @param {Vector} vector and since Vector isn't a native JS class when the FES couldn't use instanceOf to check and typeOf checked the e.g. in your example let n = createVector(-0.4, -0.4, 0.8); which would return object since Vector is not a native JS class.

A quick and easy fix would be to change @param {Vector} vector to @param {p5.Vector} vector so FES can correctly check the parameter.

I linked a PR below that would fix this issue. Let me know if there is any issue with it.

Thanks!