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

Add function to compute norm(s) #4508

Open
MDLC01 opened this issue Jul 5, 2024 · 2 comments · May be fixed by #4581
Open

Add function to compute norm(s) #4508

MDLC01 opened this issue Jul 5, 2024 · 2 comments · May be fixed by #4581
Labels
feature request New feature or request good contribution Good, isolated issue for someone that wants to contribute scripting About Typst's coding capabilities

Comments

@MDLC01
Copy link
Contributor

MDLC01 commented Jul 5, 2024

Description

calc.hypot(x, y) == calc.sqrt(x * x y * y) for floats and integers. For lengths, calc.hypot(x, y) would work similarly, keeping the unit.

Use Case

Computing hypotenuses with lengths is currently very annoying because multiplying lengths is not allowed. This would solve this problem.

@MDLC01 MDLC01 added the feature request New feature or request label Jul 5, 2024
@Enivex
Copy link
Collaborator

Enivex commented Jul 5, 2024

How about just making calc.abs variadic, and equal to the euclidean norm? It makes sense for any number of arguments, as long as they're either all lengths or all numbers.

@MDLC01
Copy link
Contributor Author

MDLC01 commented Jul 6, 2024

I like this idea, but I can see two problems: readability (it's not obvious to the uninformed reader what calc.abs(x, y, z) does), and discoverability. It may be better to create a separate calc.norm function and keep calc.abs separate, just for calculating absolute values. This would solve the readability problem, and also improve discoverability.

Additionally, we might as well go all the way and accept a positional argument to specify what p-norm to compute (not sure what the name would be though).

@laurmaedje laurmaedje added scripting About Typst's coding capabilities good contribution Good, isolated issue for someone that wants to contribute labels Jul 14, 2024
@laurmaedje laurmaedje changed the title Add calc.hypot to compute hypotenuses Add function to compute norms Jul 16, 2024
@laurmaedje laurmaedje changed the title Add function to compute norms Add function to compute norm(s) Jul 16, 2024
@HydroH HydroH linked a pull request Jul 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request good contribution Good, isolated issue for someone that wants to contribute scripting About Typst's coding capabilities
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants