Add Rect support for ObjectFit::affine.#1791
Conversation
| let origin_x = container.x0 + (container_width - (content_width * scalex)) * 0.5; | ||
| let origin_y = container.y0 + (container_height - (content_height * scaley)) * 0.5; |
There was a problem hiding this comment.
So this new function adds a translation component to account for differences in Rect position? This need to be documented.
There was a problem hiding this comment.
Yes, it now translates arbitrary origins instead of just assuming (0,0). I added a comment to make it explicit.
|
Going to run a code review on this - hope i'm not misunderstanding the "needs review" label - been looking for a good public PR to test a new code review tool on. |
|
Sure, we welcome review by anyone. When doing it with AI, it's worth manually filtering the noise and only posting reasonable results. We don't want just unfiltered LLM output posted for every PR. |
Code reviewBranch: Found 9 findings across all lanes:
Deep lane — correctness & securityℹ Uncertain (1)
Phase 4 couldn't confirm decisively. Re-run Light lane — ux, policy, architecture
🤖 Generated with Adam's Claude Code Review Command |
That's fair. I must admit, I am an AI-only developer with no knowledge of this repo. I hope the review isn't annoying despite that. Been developing this review tool that I like better than other AI reviewers I've tried: https://github.com/adamjgmiller/adamsreview |
|
Yeah that's the risk. The breaking change note is a good example of low quality feedback. There is no changelog at all right now for Masonry, also the compilation error of going from The note about new tests only exercising The post also has too much low value info as extra noise. It could have been just the two paragraphs from the "Finding" columns. As it stands, more than 50% of the text is just noise. |
|
Thank you for the feedback, this was helpful for me. And I apologize if I wasted your time. |
| /// Both `content` and `container` can have arbitrary origins, which will be | ||
| /// correctly translated in the returned `Affine`. |
There was a problem hiding this comment.
"Correctly translated" doesn't give me a strong intuition for how this function will behave given rects with non-zero origin.
My guess would have been "it just adds a applies of container.origin - content.origin to the affine", but the code seems to do something more complex than that?
There was a problem hiding this comment.
Well it does do that, but also accounts for scale changes. In every case the content will end up being inside of container, but depending on exact fit strategy, some of content might overflow.
I'll give a brief example and its journey through this method.
10x10 Container, origin (10,10), end (20,20)
20x10 Content, origin (30,30), end(50,40)
ObjectFit::Contain
// Container vs Content factor
raw_scalex = 0.5
raw_scaley = 1.0
// For Contain we end up with this scale target
(scalex, scaley) = (0.5, 0.5)
// The following is the target origin for content
origin_x = 10 + (10 - (20 * 0.5)) * 0.5 = 10
origin_y = 10 + (10 - (10 * 0.5)) * 0.5 = 12.5
// To achieve the target size and origin, we calculate the affine
Affine::scale_x = 0.5
Affine::scale_y = 0.5
Affine::translate_x = 10 - 30 * 0.5 = -5
Affine::translate_y = 12.5 - 30 * 0.5 = -2.5
// Applying the affine later ends up giving us the correct origin and end for the content
(30,30) * affine = (30 * 0.5 + -5, 30 * 0.5 + -2.5) = (10,12.5)
(50,40) * affine = (50 * 0.5 + -5, 40 * 0.5 + -2.5) = (20,17.5)
ObjectFitdocs state that it provides strategies for inscribing a rectangle inside another rectangle. However, theObjectFit::affinemethod only operates on a pair ofSizestructs.This PR changes that to a pair of
Rectstructs so that the fitting strategies are also available for scenarios where the source/destination doesn't have a(0,0)origin.