p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

[p5.js 2.0 RFC Proposal]: Using a separate math library for handling p5.js's math operations

Open RandomGamingDev opened this issue 5 months ago • 10 comments

Increasing access

As discussed in #6527: Using another library would mean a better documented and managed library with more features for p5.js, but it'll also be more performant, and we could even choose a library that can utilize the GPU for especially heavy operations. It would also make p5.js much more powerful and easier to deal with for those who want to use it for things like 4d scenes or other areas involving math which includes things from basic sites to fully fledged games and demos.

Which types of changes would be made?

  • [ ] Breaking change (Add-on libraries or sketches will work differently even if their code stays the same.)
  • [X] Systemic change (Many features or contributor workflows will be affected.)
  • [X] Overdue change (Modifications will be made that have been desirable for a long time.)
  • [ ] Unsure (The community can help to determine the type of change.)

Most appropriate sub-area of p5.js?

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

What's the problem?

The current p5.js math component is heavily cluttered as discussed at https://github.com/processing/p5.js/issues/6527 & https://github.com/processing/p5.js/issues/6527#issuecomment-1793477773 and isn't nearly as optimized as it could be which makes it hard to not only use if you're trying to understand and interact with the code, but also to contribute to, especially for a library designed to increase accessibility to beginners. Plus, it's hard to integrate p5.js with other math libraries when you need any math that's more complex, for instance if someone wanted to do something that involved linear algebra, or calculus that isn't included in p5.js, like 4d scenes.

What's the solution?

The solution would be utilizing another math library using another library would mean a better documented and managed library with more features for p5.js, but it'll also be more performant, and we could even choose a library that can utilize the GPU for especially heavy operations.

Pros (updated based on community comments)

Example list:

  • Consistency: This proposal increases API consistency by removing the old cluttered code that's long been an issue with some examples discussed here
  • Readability: This proposal makes the source code more readable by utilizing another library which will have better documentation as well as be more consistent in its usage and features as well as their relationship to the documentation. It also means removal of the cluttered p5.Math code.
  • Performance: Not only could this mean great performance enchantments, but even GPU computations for especially large tensor operations!
  • Reliability: p5.Math clearly isn't reliable due to how easily it became a hard to read mess to deal with due to its numerous bad design choices as well as misdocumented and misimplemented features. Both of these makes sense to some degree considering the fact that neither the math nor the reprogramming from scratch are the main goal of p5.js, but rather understandability and openness to beginners as well as experts. Using a math library would perfectly cater to both parties by providing a stable, customizable, powerful, efficient, well documented base for us to build p5.js off of.
  • Openness: As discussed previously, the messiness of p5.js can dissuade many who want to, not only contribute to the p5.js source code, but even just use p5.js for anything slightly involving math to a higher degree. With all of the previously mentioned pros fixed, this will mean that p5.js will thus be a lot more open to those who need to use it.

Cons (updated based on community comments)

  • Time: This proposal will take quite some time since it will require replacing the majority of p5.Math and its documentation in order to improve p5.js.

Proposal status

Under review

RandomGamingDev avatar Jan 23 '24 01:01 RandomGamingDev