textBounds outputs nan if number is input instead of string
Open
Nobody has claimed this yet.
Area:Typography
Bug
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
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
- Internalization
- Friendly Errors
- Other (specify if possible)
p5.js version
1.7.0
Web browser and version
FF 115.0.2
Operating System
mac 12.6
Steps to reproduce this
Steps:
- input number to textBounds
Snippet:
https://editor.p5js.org/micuat/sketches/sYWYkUTJv
let f;
function preload() {
f = loadFont("RobotoMono-VariableFont_wght.ttf")
}
function setup() {
createCanvas(400, 400);
console.log(f.textBounds("io", 0, 0, 10))
console.log(f.textBounds(10, 0, 0, 10))
}
function draw() {
background(220);
}
console:
{x: 0.9912109375, y: -7.2021484375, h: 7.2998046875, w: 10.41015625, advance: 0.9912109375}
{x: Infinity, y: Infinity, h: -Infinity, w: 0, advance: Infinity}
I'm not sure what is the expected result (number + "" would solve the issue). If number is not accepted, there should be an error message, I suppose?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied sketch and compare the string and numeric calls to p5.Font.textBounds. Determine the expected handling for numeric input, then add coverage for that behavior and confirm the result no longer produces Infinity or NaN.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100