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 Vec::sign_bits #345

Merged
merged 7 commits into from Oct 1, 2022
Merged

Add Vec::sign_bits #345

merged 7 commits into from Oct 1, 2022

Conversation

atlv24
Copy link
Contributor

@atlv24 atlv24 commented Sep 29, 2022

This is dependent on the fixes in #344 (those problems were found while adding this function)

I need this function for optimized tetrahedron face winding order checks (four dot products being put in a Vec and then grabbing the sign bits to check if its either 0b0000 or 0b1111, thus having all the same winding order and not being degenerate) among other things.

BVec::bitmask almost does this, but gets the LSB for scalar implementations, but I need it on Vec anyways so its irrelevant

@bitshifter
Copy link
Owner

I'm wondering what the most general purpose method would be for most users here.

For example, there are already methods on VecN for is_finiite -> bool (all elements finite) and is_nan -> bool (any elements are nan). I've tried to match the naming use on f32/f64 there although I guess it's not entirely consistent about whether the result is any or all. There is also is_nan_mask which returns BVecN.

For your usage it seems like a is_sign_negative which returns true if all elements are sign negative would fit your use case? That would probably fit better with the existing naming scheme. Do you need a u32 mask beyond checking if it's all zeros or all ones?

@atlv24
Copy link
Contributor Author

atlv24 commented Oct 1, 2022

My use-case needs to distinguish between three cases: all positive, all negative, or mixed signs. I don't need to know what the specific mix is if its mixed. Sample code:

    match sign_winding.sign_bits();
    {
        // All positive
        0 => sign_origin.cmpge(Vec4::splat(-f32::EPSILON)),

        // All negative
        0xf => sign_origin.cmple(Vec4::splat(f32::EPSILON)),

        // Mixed signs, degenerate tetrahedron
        _ => BVec4A::splat(true)
    }

@bitshifter
Copy link
Owner

Kind of a note to myself, it might be good to add TRUE and FALSE constants to BVecN types for this kind of use.

@atlv24
Copy link
Contributor Author

atlv24 commented Oct 1, 2022

Funny, there's a FALSE const for all BVecN types but no TRUE. I can PR this if its convenient

@bitshifter
Copy link
Owner

The current false is private I think. If you want to make a PR, go for it.

@bitshifter bitshifter merged commit 30f1788 into bitshifter:main Oct 1, 2022
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.

None yet

2 participants