Skip to content

[2.0] Stabilize the undocumented dimensions field of p5.Vector #8155

@GregStanton

Description

@GregStanton

[2.0] Stabilize the undocumented dimensions field of p5.Vector

Possible bugs

The dimensions field isn't currently documented, but it appears to users when they use the command console.log(myVector), and it may sometimes have inaccurate values, as observed here and here.

Thanks to @sidwellr for the following summary:

The gist of the comments linked above is that dimensions does not always reflect the true dimensions of the vector. For example, createVector() (with no params) creates a 3D vector [0, 0, 0] but sets dimensions to 2. And p5.Vector.sub(createVector(1, 2), createVector(1, 2, 3)) will return a 3D vector with dimensions set to 2.

Proposal: Renaming dimensions to dimensionSize prior to release

This would likely be a useful feature, with precedent in other libraries, e.g. babylon.js has dimension. But, prior to release, it may be renamed to dimensionSize, which works better in the context of p5. This name would be clearer, and it'd allow a consistent interface across vectors, matrices, and potentially tensors:

Data structure Proposed property Example value Data type
Vector [x, y, z] .dimensionSize 3 Number
Matrix (3 rows, 4 cols) .dimensionSizes [3, 4] Array
Matrix (3 rows, 4 cols) .dimensionCount 2 Number

This naming scheme prevents users from falling into type traps and ambiguity traps, as described in this comment.

Settable?

Also, there would need to be discussion about whether to (a) protect this field from modification or (b) support modification, e.g. by padding a vector with zeros or truncating it if needed. Right now, as @sidwellr noted, "users can currently set dimensions to any value, including nonsensical ones like 2.5 and 'frog'."

Tasks

  • Fix bugs
  • Reach consensus on the rename.
  • Implement the rename, if accepted by the community.
  • Reach consensus on writability and associated behavior.
  • Implement the agreed upon writability behavior.

Edits:

  1. Added points from @sidwellr.
  2. Added table to illustrate naming scheme, and clarified its benefits.
  3. Added task list.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions