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 kurbo conversions to scene API #171

Merged
merged 8 commits into from
May 19, 2022
Merged

Add kurbo conversions to scene API #171

merged 8 commits into from
May 19, 2022

Conversation

dfrg
Copy link
Collaborator

@dfrg dfrg commented May 18, 2022

This is a small follow up PR to #168 that adds an optional dependency on kurbo to the scene crate along with the associated two-way conversions between common types when the feature is enabled.

There is a question of which version of kurbo we want to depend on. This currently uses 0.8.3 which is the latest available on crates.io while piet-gpu inherits version 0.7.0 from its older piet dependency.

dfrg added 5 commits May 18, 2022 16:22
Adds kurbo as an optional dependency and implements conversions to/from the common types.

This also removes the direct pinot dependency and changes moscato (temporarily) to a git based dep to allow iteration on the underlying glyph loading code without PR churn here.
Reassigns value 13 to PlusLighter to match the upcoming blend fixes
* Add impl Into<Affine> for pushing transforms.
* Small QOL API changes to Scene and Fragment.
* Add some missing docs.
This matches the changes in the fix_blends PR.
@raphlinus raphlinus mentioned this pull request May 19, 2022
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

I have these comments in my queue, I think it makes sense for you to see them even though I'm not fully settled on some of the decisions.

use super::geometry::{Affine, Point, Rect};
use super::path::Element;

impl From<kurbo::Point> for Point {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is ergonomic but doesn't exactly follow Rust conventions - usually From is for lossless conversions, so there's f32->f64 but not the other way around. There was a proposal for a standard lossy conversion trait but I'm not sure it went anywhere. I think this is good enough for now but want to check with a Rust expert to see if there is a better pattern. In any case, we can change it later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. If you'd feel better with explicit to_kurbo/from_kurbo methods, I actually don't mind going that direction. I found that impl Into in the builder interface isn't all that useful anyway due to these types being mostly buried in options and iterators.

Copy link
Contributor

Choose a reason for hiding this comment

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

The ->kurbo direction is fine. If "into" is not actually a big ergonomic win in practice then I think having an explicit method is a better choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the From impls and replaced them with from_kurbo methods for the lossy conversions.

piet-scene/src/scene/builder.rs Outdated Show resolved Hide resolved
@@ -83,6 +85,13 @@ pub struct Scene {
}

impl Scene {
/// Creates a new builder for filling the scene. Any current content in
/// the scene is cleared.
pub fn build<'a>(&'a mut self, rcx: &'a mut ResourceContext) -> Builder<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this name is confusing, usually "build" is at the end of a fluent-style chain, converting a builder type into a (usually non-mutable) instance of what's being build. Perhaps "start_build"? It's also possible I don't really understand the logic here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this name is poorly chosen. start_build could work, or maybe new_builder. I think I'll just remove these and keep the original free functions for now.

Copy link
Collaborator Author

@dfrg dfrg May 19, 2022

Choose a reason for hiding this comment

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

These were redundant anyway so they've been removed. Easiest way to solve a naming issue :)

piet-scene/src/scene/blend.rs Show resolved Hide resolved
dfrg added 2 commits May 19, 2022 18:04
Moves the more descriptive comments to the free functions.
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Ok this looks good now, thanks!

@dfrg dfrg merged commit 663607d into linebender:master May 19, 2022
@dfrg dfrg deleted the kurbo_conv branch May 19, 2022 22:19
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