Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cases #16

Open
Richienb opened this issue Feb 19, 2025 · 1 comment
Open

Use cases #16

Richienb opened this issue Feb 19, 2025 · 1 comment

Comments

@Richienb
Copy link
Collaborator

Future advancement depends on being supported by use cases.

NPM downloads is not evidence because the language should only be implementing features that nudge users towards writing better code, and NPM downloads are only an indicator of popularity.

(discussion from 106th meeting)


What are the real-world use cases for which clamping is the best way to solve it?

@senocular
Copy link

senocular commented Feb 19, 2025

Taking a sampling from our (rather large) project's TypeScript codebase:

I've found 11 independent implementations of a clamp function. Signatures are as follows:

clamp = (value: number, minValue: number, maxValue: number): number
clamp(value: number, lower: number, upper: number): number
clamp(v: FrameTime | number, min: FrameTime | number, max: FrameTime | number): FrameTime | number
clamp(value: number, min: number, max: number): number
clampNumber(value: number, left?: number, right?: number): number
clampToPercent(value: number): number
clamp = (value: number, minValue: number, maxValue: number): number
clamp(a: number, minVal: number, maxVal: number): number
clamp(min: number, value: number, max: number): number
clamp(val: number, min = 0, max?: number): number
clamp(num: number, min: number, max: number): number

Going through various call sites, clamp was used when working with (not exhaustive):

  • values read from a parsed document
  • values read from a URL
  • chart spacing
  • text line spacing
  • zoom tool zoom
  • object scale
  • selection tool coordinates
  • simulated click coordinates
  • text selection bounds
  • input for a slider
  • image size for thumbnail
  • stroke size
  • stroke miter joins
  • percentage for point on a line segment
  • progression within an easing curve
  • progression of animation
  • items within duration of timeline
  • seek location within a timeline
  • color blending
  • color space conversion

Usage was especially heavy in code related to animation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants