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

Math fixes #545

Merged
merged 9 commits into from
May 6, 2022
Merged

Math fixes #545

merged 9 commits into from
May 6, 2022

Conversation

connor-lennox
Copy link
Contributor

Addresses several of the minor comments from my last PR.

A few of the changes mentioned there are not implemented here: namely the switch of the Point::Distance function (this is still an associated function taking in two references) and the shortening of Point calculation when pushing lines (subtracting a Vector from a Point gives a Vector, but adding a Vector to a Point gives a Point - this discrepancy is strange and how it is handled changes how things will be condensed).

@connor-lennox connor-lennox requested a review from hannobraun as a code owner May 6, 2022 17:14
Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @connor-lennox, looks great!

I've left one comment where I noticed something that's not idea, but no big deal.

.as_slice()
.iter()
.map(|f| Scalar::from(*f))
.collect::<Vec<Scalar>>()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unfortunate that we're going through a Vec here, due to the heap allocation that's probably expensive. I don't know how to change it off the top of my head, however. I'd have to experiment with it hands-on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wanted to avoid a Vec here. You can't collect an iterator into an array, though. One alternative way to implement this is to iterate over the slice elements and assign into some mutable array (not as pretty, but avoids the Vec)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why not leave the code as it was before, with a slight modification:

let projection = Perspective3::new(aspect_ratio, fovy, znear, zfar);
let mut res = [0f64; 16];
res.copy_from_slice(
    (projection.to_projective() * self.0).matrix().as_slice(),
);
res.map(|f| Scalar::from(*f))

Should work?

But yeah, it's not that important. I'd be happy to merge a change that avoids the Vec, but I'm also fine with leaving it as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a good way to avoid the Vec while still keeping things tidy. I don't think this will make or break the performance but it'll be good to keep in mind for later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. No reason to bend over backwards right now. If there's really a problem, we can fix it.

@hannobraun hannobraun merged commit a4df039 into hannobraun:main May 6, 2022
@connor-lennox connor-lennox deleted the math-fixes branch May 6, 2022 19:57
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.

2 participants