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

Shape types should implement equality #831

Closed
Michael-F-Bryan opened this issue Jul 16, 2022 · 1 comment · Fixed by #832
Closed

Shape types should implement equality #831

Michael-F-Bryan opened this issue Jul 16, 2022 · 1 comment · Fixed by #832
Labels
type: feature New features and improvements to existing features

Comments

@Michael-F-Bryan
Copy link
Contributor

Michael-F-Bryan commented Jul 16, 2022

As currently implemented, none of the geometric types in the fj crate implement PartialEq. Is there a specific reason for this, or was it done just as a forward-compatiblity measure? For example, because we might want to add trait/function-based geometry in the future which doesn't have a definition for value equality.

If possible, it'd be nice to #[derive(PartialEq)] because then model implementations can write unit tests to check they generate the correct shape.

As an example for when this could be useful, see the following smoke test for my cuboid model.

#[test]
fn load_cuboid_and_generate_geometry() {
    let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
    let target_dir = crate_dir.parent().unwrap().parent().unwrap().join("target");

    let model = Model::from_path(crate_dir.into(), Some(target_dir.into())).unwrap();

    let mut arguments = HashMap::new();
    arguments.insert("x".to_string(), "10".to_string());
    let actual = model.load_once(&Parameters(arguments)).unwrap();

    let rectangle = fj::Sketch::from_points(vec![
        [-5.0, -1.0],
        [10.0 / 2., -2.0 / 2.],
        [10.0 / 2., 2.0 / 2.],
        [-10.0 / 2., 2.0 / 2.],
    ])
    .with_color([100, 255, 0, 200]);
    let expected = fj::Sweep::from_path(rectangle.into(), [0., 0., 3.0]);

    // TODO: Enable this assertion when we can compare shapes for equality.
    // https://github.com/hannobraun/Fornjot/issues/831

    // assert_eq!(actual, expected);
    let _ = (actual, expected);
}
@hannobraun
Copy link
Owner

hannobraun commented Jul 16, 2022

There's no deep reason for why they don't derive PartialEq, nor is there any specific reason why they derive the types they do derive, beyond "it was needed at some point". Any changes here that help you (or anyone else) are definitely welcome!

Forward compatibility is not a concern at this point. We are far away from even approaching a mature design. This stuff will change a million times more before it settles down, I'm sure.

@hannobraun hannobraun added type: feature New features and improvements to existing features topic: model labels Jul 16, 2022
Michael-F-Bryan added a commit to Michael-F-Bryan/Fornjot that referenced this issue Jul 17, 2022
Michael-F-Bryan added a commit to Michael-F-Bryan/Fornjot that referenced this issue Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature New features and improvements to existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants