Skip to content

[2.0] Stabilize x, y, and z fields of p5.VectorΒ #8153

@GregStanton

Description

@GregStanton

Topic

[2.0] Stabilize x, y, and z fields of p5.Vector

Problem:
From a user's perspective, a vector appears to be both 2D and 3D at the same time. This happens when toString() indicates the third component is undefined, but z is zero. The user-facing inconsistency is especially confusing for beginners, since justifications based on internal implementation or backwards compatibility are hard to document.

Solution:
The short version is that we just need to remove || 0 from the getters for the x, y, and z properties. This appears to be the last step to creating true 1D and 2D vectors in p5.js 2.0.

Possible complication... but maybe not?
Others have suggested that this change might force a refactor of certain rendering features, such as point(). However, at least for that feature, it doesn't appear that any refactoring is needed. It looks like the current implementation may work as is if p5 were to implement true 2D vectors (in which z is undefined). The implementation of the user-facing function passes a z-coordinate to the 3D renderer's point() method, but the 3D renderer already uses 0 as default value for z in case it's undefined.

Tasks:

  • Decide whether to carry out the proposed solution.
  • Implement the solution.
  • Document the solution.
  • Update the compatibility README if needed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions