RazrFalcon / tiny-skia

A tiny Skia subset ported to Rust
BSD 3-Clause "New" or "Revised" License
1.12k stars 69 forks source link

Implement `PartialEq` for `Paint` and subtypes #75

Closed hecrj closed 1 year ago

hecrj commented 1 year ago

I'm experimenting with diffing and incremental rendering in iced with tiny-skia and I need to be able to compare Paint types.

RazrFalcon commented 1 year ago

Hi! I don't mind this change, but be aware that comparing patterns might be very expensive. Since you will be comparing pixmap bytes.

Also, since Paint has a lifetime, you cannot really store it. So comparison becomes kinda useless.

The only way to make it easier is to store pattern's image in Arc, but it might only increase the complexity.

hecrj commented 1 year ago

Right, iced doesn't support patterns so we are just using a 'static paint for now. If we ever support it, we will probably write our own PartialEq implementation to do shallow pointer equality only.

In any case, figured this could be a nice change since nothing seems to be in the way for these traits to be derived and may help others prototype ideas as well.

Thanks for the pointers!

RazrFalcon commented 1 year ago

I thought that we could add a custom PartialEq for Pattern that would compare only data pointers (aka as_ptr()) + length, without comparing the actual data. But it might be too restrictive and confusing. And it seems like the default PartialEq implementation for slices is smart enough. And since patterns are usually small I guess it should be fine.