Skip to content

textBounds outputs nan if number is input instead of string #6298

Open
@micuat

Description

@micuat

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:

  1. 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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions