Skip to content

Don't return undefined when an empty model is passed to makerjs.measure.modelExtents #625

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

Merged
merged 1 commit into from
Jul 4, 2025

Conversation

xavi-
Copy link
Contributor

@xavi- xavi- commented May 31, 2025

Currently makerjs.measure.modelExtents({ models: {} }) returns undefined which makes code prone to NPE's

This PR updates modelExtents to instead return an empty IMeasureWithCenter object: { height: 0, width: 0, center: null, low: null, high: null }

@xavi-
Copy link
Contributor Author

xavi- commented May 31, 2025

It might be better to return { width: 0, height: 0, center: [0, 0], low: [0, 0], high: [0, 0] } instead since according to the types, center, low, and high aren't nullable

@danmarshall
Copy link
Contributor

Thanks for the PR!
But, since the whole library doesn't have 100% test coverage (my fault not yours), I'm a little hesitant to take this. Perhaps you could add your own defensive function in your own code:

function alwaysMeasureModel(model) {
   return makerjs.measure.modelExtents(model) || { width: 0, height: 0, center: [0, 0], low: [0, 0], high: [0, 0] };
}

@xavi-
Copy link
Contributor Author

xavi- commented Jun 19, 2025

Or perhaps the return type of modelExtents should be changed to IMeasureWithCenter | null? I created this PR mostly because I got bitten by this in production

@danmarshall
Copy link
Contributor

Sorry it bit you in production. Yes the | null is a good approach.

@xavi- xavi- force-pushed the avoid-null-modelExtents branch from 4b3382a to b7470f3 Compare July 3, 2025 00:57
@xavi- xavi- force-pushed the avoid-null-modelExtents branch from b7470f3 to d944aad Compare July 3, 2025 00:58
@xavi-
Copy link
Contributor Author

xavi- commented Jul 3, 2025

Updated PR. Also updated method to explicitly return null

@danmarshall danmarshall merged commit 1ed796b into microsoft:master Jul 4, 2025
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy