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

Provide functions for checking raw floating point values for equality. #3

Closed
olson-sean-k opened this issue Nov 29, 2017 · 2 comments
Closed
Milestone

Comments

@olson-sean-k
Copy link
Owner

Hashing functions like hash_float_array are provided because sometimes it is not possible or ergonomic to use wrapper types within another type. README.md mentions this example:

use decorum;

#[derive(Derivative)]
#[derivative(Hash)]
pub struct Vertex {
    #[derivative(Hash(hash_with = "decorum::hash_float_array"))]
    pub position: [f32; 3],
    ...
}

This vertex type may be fed to graphics code that expects raw floating point data (for example, see the gfx pipeline macros and shader compilers).

A similar problem exists for implementing Eq: if it is not possible or ergonomic to use wrapper types, there is currently no convenient way to implement Eq. This can be done via conversions, but that gets messy fairly quickly. Instead, Decorum should provide eq_float, eq_float_slice, and eq_float_array functions that are analogous to the hashing functions.

@olson-sean-k olson-sean-k added this to the 0.1.0 milestone Nov 29, 2017
@olson-sean-k
Copy link
Owner Author

Once this is available, the above example would look something like this:

use decorum;

#[derive(Derivative)]
#[derivative(Eq, Hash, PartialEq)]
pub struct Vertex {
    #[derivative(Hash(hash_with = "decorum::hash_float_array"))]
    #[derivative(PartialEq(compare_with = "decorum::eq_float_array"))]
    pub position: [f32; 3],
    ...
}

@olson-sean-k
Copy link
Owner Author

These functions are exposed by 8fdd430.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant