Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd BoolVector2D/3D. #287
Add BoolVector2D/3D. #287
Conversation
|
r? anyone |
|
First question, why are those separate types instead of just extra methods for |
|
I don't think the unit makes sense for these types, and the boolean vectors have a completely separate set of methods. |
|
Second question is: what is the use case for actually needing |
|
Needs some tests. Otherwise LGTM |
| } | ||
|
|
||
| #[inline] | ||
| pub fn xy(&self) -> BoolVector2D { |
This comment has been minimized.
This comment has been minimized.
kvark
Apr 12, 2018
Member
that's just a subset of all possible swizzles. Is there a particular reason to only include those? Are those needed in practice?
This comment has been minimized.
This comment has been minimized.
nical
Apr 12, 2018
Author
Collaborator
These are the swizzles we currently have in TypedVector2D. I wouldn't mind if we add the other ones but there are so many of them I'd rather just wait until someone asks for them.
I have used them a bit outside of webrender, but the one I use most at the moment is to go from 3d to 2d because foo = myvec.xy() is nicer and more explicit than foo = myvec.to_2d() in my opinion.
Having them doesn't add any real complexity so I don't think it's worth arguing over really.
This comment has been minimized.
This comment has been minimized.
kvark
Apr 12, 2018
Member
yeah, myvec.xy() is nicer, but it's not clear why we shouldn't then be able to do myvec.yx()
This comment has been minimized.
This comment has been minimized.
nical
Apr 12, 2018
Author
Collaborator
Totally. There is really no particular reason as far as I am concern to not add yx() and friends other than being busy with other things. If you write the PR I'll r+ it.
|
@nical alright, so how do you feel about adding some tests? |
|
Done. |
|
Thanks! |
|
I'm tempted to say a github bug. It's the tip of the master branch, not sure why it shows up here since it is in master already. I tried to remove it and rebase on top of master but it still shpws up here. Anyway it rebases/merges cleanly so we can land now. |
|
Hmm... the first commit hash differs from that of the commit found in the master branch... perhaps during rebase, it asked for you to recommit a commit that was in the master branch? |
|
I did:
It didn't ask me anything in particular. |
|
Looks like it worked. |
|
@bors-servo r+ |
|
|
Add BoolVector2D/3D.
This is something I have been missing for a while, not enough to go ahead and make the PR until now, but I think it is a nice addition.
This adds boolean vectors similar to what you can see in glsl and let you rewrite things like:
```rust
if some_vec3.x > another_vec3.x ||
some_vec3.y > another_vec3.y ||
some_vec3.z > another_vec3.z) {
// do the thing!
}
```
into:
```rust
if some_vec3.greater_than(&another_vec3).any() {
// do the thing!
}
```
We don't get to use the `>` operator because rust wants it to return a boolean, but I think it already makes things quite a bit nicer as is.
This PR doesn't implement all of the various candies we can think of for vector boolean ops, nor does it implement BoolVector4D but they can be added as followups if we need/want them.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/287)
<!-- Reviewable:end -->
|
|
nical commentedApr 11, 2018
•
edited by larsbergstrom
This is something I have been missing for a while, not enough to go ahead and make the PR until now, but I think it is a nice addition.
This adds boolean vectors similar to what you can see in glsl and let you rewrite things like:
into:
We don't get to use the
>operator because rust wants it to return a boolean, but I think it already makes things quite a bit nicer as is.This PR doesn't implement all of the various candies we can think of for vector boolean ops, nor does it implement BoolVector4D but they can be added as followups if we need/want them.
This change is