creativescala / doodle

Compositional vector graphics in Scala / Scala.JS
https://creativescala.org/doodle/
Apache License 2.0
327 stars 75 forks source link

BufferedImageConverter cleanup #145

Open noelwelsh opened 6 months ago

noelwelsh commented 6 months ago

Consider the following:

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

jCabala commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

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.