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

[css-values] Make 'hypot()' n-dimensional #3765

Closed
Loirooriol opened this issue Mar 26, 2019 · 11 comments
Closed

[css-values] Make 'hypot()' n-dimensional #3765

Loirooriol opened this issue Mar 26, 2019 · 11 comments
Labels
css-values-4 Current Work

Comments

@Loirooriol
Copy link
Contributor

From https://drafts.csswg.org/css-values-4/#funcdef-hypot,

The hypot(A,B) function contains two comma-separated calculations A and B, and returns the length of the hypotenuse of a right-angled triangle with legs equal to A and B.

I would like to generalize this to the euclidean norm like in JS Math.hypot. Then

  • hypot(A) would be the absolute value of A
  • hypot(A, B) would be the hypotenuse of a right-angled triangle with legs equal to A and B.
  • hypot(A, B, C) would be the length of the space diagonal of a rectangular cuboid with edge lengths A, B and C.
  • and possibly more (though maybe not as useful as the previous cases).
@Loirooriol Loirooriol added the css-values-4 Current Work label Mar 26, 2019
@AmeliaBR
Copy link
Contributor

I definitely like the idea of supporting a 3-value hypot for 3D geometry.

I can't think of any use cases for more dimensions on the web, but don't think it would complicate the implementation. The ECMAScript Math.hypot() implementation supports arbitrary numbers of arguments.

I think it confuses matters a bit to talk about hypot(A) to generate the absolute value. I mean, it doesn't hurt to support it. But, I'd rather go straight to adding an abs(A) function.

@tabatkins
Copy link
Member

Allowing 2+ arguments sounds great, I'm sorry I forgot about it initially. ^_^ Allowing a single argument to effectively be abs() is fine; the general definition handles that case with no problem. (And JS allows it as well.)

@Loirooriol
Copy link
Contributor Author

@tabatkins "the length of an N-dimensional vector" is not clear enough, you should specify that it's the euclidean norm, since vector spaces can have other kinds of norms.

@tabatkins
Copy link
Member

Technically, yes. But euclidean norm is always assumed if not specified and there's nothing else in the context hinting that you might be talking about other norms.

If someone comes at me with some Manhattan distance, I'm gonna assume they're being a smart-ass. ^_^

@AmeliaBR
Copy link
Contributor

It wouldn't hurt to specify the actual calculation (“the square root of the sum of squares of its arguments”, to use the ECMAScript text) for clarity. People who haven't taken advanced math may be confused by "the length of an N-dimensional vector", with or without specifying Euclidean space.

@Crissov
Copy link
Contributor

Crissov commented Mar 26, 2019

Shouldnʼt the function better be called norm() then? Equivalence to hypot() in JS would be worth an informative note.

(I obviously donʼt value compatibility with JS nomenclature as highly as others; also dislike redundant atan2().)

@tabatkins
Copy link
Member

People who haven't taken advanced math may be confused by "the length of an N-dimensional vector", with or without specifying Euclidean space.

Good point, I've done so.

Shouldnʼt the function better be called norm() then?

The JS-naming concordance besides, it's still also a hypotenuse of the right triangle defined by the origin, the point given by the first N-1 arguments, and the point given by all the arguments.

@Crissov
Copy link
Contributor

Crissov commented Mar 26, 2019

… except in the degenerate case with a single argument.

@tabatkins
Copy link
Member

Nope, it's still the hypotenuse there. The point given by the first N-1 arguments is the origin, because there are no arguments at all. The triangle is thus degenerate, but it still has a meaningful "hypotenuse", which is equal to the absolute value of the provided argument.

@Loirooriol
Copy link
Contributor Author

BTW, should hypot() without arguments be allowed? It would represent the norm of a vector in a 0-dimensional space, i.e. +0. Seems pretty useless, but would be consistent with JS...

@tabatkins
Copy link
Member

At that point I really think it's a step too far. Unlike 1-arg hypot() (which gives us abs()), another way of writing 0 doesn't seem useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-values-4 Current Work
Projects
None yet
Development

No branches or pull requests

4 participants