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

BufferedImageConverter cleanup #145

Open
noelwelsh opened this issue Mar 12, 2024 · 3 comments
Open

BufferedImageConverter cleanup #145

noelwelsh opened this issue Mar 12, 2024 · 3 comments

Comments

@noelwelsh
Copy link
Contributor

noelwelsh commented Mar 12, 2024

Consider the following:

  • BufferedImageConverter is quite a mouthful. Can we shorten the name? Perhaps we use the term "Writer" for anything we can convert a Picture into, and rename the current Writer to FileWriter (and Base64 becomes Base64Writer)?

  • Can we make the Frame optional? Can we get it from a DefaultRenderer? Maybe the idea of a default frame should be extracted into it's own effect (it's not really an effect, but it is associated with effects.)

  • Do we need to return the value of type A when we convert to a BufferedImage? Most of the time the user will throw it away. (Same issue exists for Base64). Maybe the convention should be you get the A if you convert to an IO but we throw it away in you immediately run that IO. This would match what happens in draw.

  • Maybe what we need is a generic conversion effect type class. Something like

    trait To[+Alg <: Algebra, Frame, Out] {
      def to[A](description: Frame, picture: Picture[Alg, A]): IO[(A, Out)]
    }
  • Java2dBufferedImageWriter in Java2dWriter.scala should be renamed and moved to its own file.

  • Add tests.

  • Add documentation.

This issue could probably be usefully turned into a project. Each bullet could be it's own issue.

@jCabala
Copy link
Collaborator

jCabala commented Mar 12, 2024

I'm happy to work on this. I could be useful to turn it into a project to submit 1 PR at the time. Can I do it or does it need to be someone with write access to the repo?

@jCabala
Copy link
Collaborator

jCabala commented Mar 13, 2024

Java2dWriter extends both FileWriter (previously Writer) and Base64Writer (previously Base64). On the other hand Java2dWriter is a separate object that only uses one function from the Java2dWriter companion object. I was thinking that it would make sense to:

  1. Move the companion object to a separate class (say Java2dWriterUtils)
  2. separate the logic of Java2dWriter into 2 traits: Java2dFileWriter and Java2dBase64Writer
  3. Create a separate file called Writers that stores all of the actual writer objects (e.g Java2dPdfWriter, Java2dGifWriter, Java2dBufferedImageWriter)

Is that reasonable or is it better to just leave it as Java2dWriter (because technically it is missleading to call it a Java2dFileWriter since it is also a Base64Writer) and have another file Java2dBufferedImageWriter?

@noelwelsh
Copy link
Contributor Author

I've created a project: https://github.com/orgs/creativescala/projects/8/

Regarding the refactorings you describe above:

  1. Moving the companion object to a class means that code is not usable (and hence not testable) without creating an instance of the class. I'd rather not add this complication if it's not necessary. Some of the code could move into Java2d, which handles other parts of rendering using the Java 2D API.

  2. I'm not sure there is value in separating the implementation of Java2dWriter. Conceptually they are distinct, and they are represented by distinct algebras / type classes. However, the implementations are related (i.e. they share a lot of the implementation.) I don't think it's a problem to have the implementations together. The concepts are already distinct, just at a different level of the code.

  3. This is reasonable.

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

No branches or pull requests

2 participants