processing / processing/p5.js

Add a clamp() alias for constrain() or mention clamp in the docs

Open
#7,191 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Math Enhancement
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Increasing access

People who come from other frameworks and languages will have an easier time finding the relevant function for clamping numbers in p5.js.

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)
Feature enhancement details

The typical name for the constrain(x, min, max) function in p5.js, used across the math and computing world, is clamp. E.g. see OpenGL, Godot/Unity, C#, Java, CSS, and C++.
In comparision, less popular names include clip, used by Numpy and Octave/Mathematica/Wolphram, and, well, constrain, used by Processing/Arduino/P5.js and MakeCode.

Hence I think that it would make sense to either have clamp() as an alias to constrain() (ideal for me, as I always end up reaching for "clamp" before realizing it's different in p5), or to add a note in constrain()'s documentation that explains it's also known as clamp() elsewhere (which, together with https://github.com/processing/p5.js-website/issues/493 would allow people like me to find constrain() faster).

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 with the p5.js constrain() reference and the Math area identified in the issue. Determine whether the contribution should provide a clamp() alias or document clamp as an alternate name; done means the chosen option is available or discoverable through the constrain() documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, documentation
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.