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

Adding clipping to doodle [Draft] #157

Closed
wants to merge 5 commits into from
Closed

Conversation

VOSID8
Copy link
Contributor

@VOSID8 VOSID8 commented Apr 13, 2024

I'm done with the Algebra, Syntax, Constructor and now working on Java2d Backend. Clipit is the end implementation, taking clipping area as Closed Path as argument as it was intended to.

@main def hello(): Unit =
  val closed = ClosedPath.empty
                  .moveTo(80, -60)
                  .lineTo(10, 10).lineTo(10, 60).lineTo(80, 60).lineTo(80, -60)
  val blackSquare = Picture.triangle(200, 100).fillColor(Color.red).clipit(closed)
  blackSquare.draw()

Right now with the Java2dClip.scala file where after the setClip is done, when doing Clip, java.awt.Shape is required as argument where I have Drawing[A], and need to return vice versa.

[error] 20 |    gg.clip(image) //Graphics2D.clip() requires java.awt.Shape as argument 
[error]    |            ^^^^^
[error]    |            Found:    (image : Java2dClip.this.Drawing[A])
[error]    |            Required: java.awt.Shape

package object syntax {
object all
extends AngleSyntax
with BitmapSyntax
with ClipSyntax
Copy link
Contributor

@noelwelsh noelwelsh Apr 14, 2024

Choose a reason for hiding this comment

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

This file lists the syntax in alphabetic order. You should follow this convention.

@@ -36,6 +39,7 @@ package object syntax {
with UnsignedByteSyntax
object angle extends AngleSyntax
object bitmap extends BitmapSyntax
object clipit extends ClipSyntax
Copy link
Contributor

Choose a reason for hiding this comment

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

Should just be clip. Use alphabetic ordering.

import doodle.core.ClosedPath
import doodle.algebra.Picture

trait ClipIt extends Algebra {
Copy link
Contributor

@noelwelsh noelwelsh Apr 14, 2024

Choose a reason for hiding this comment

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

This doesn't follow the existing naming convention. Just Clip will do.

import doodle.algebra.Picture

trait ClipIt extends Algebra {
def clipit[A](image: Drawing[A], clip_path: ClosedPath): Drawing[A]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def clipit[A](image: Drawing[A], clip_path: ClosedPath): Drawing[A]
def clip[A](image: Drawing[A], clipPath: ClosedPath): Drawing[A]

}

trait ClipItConstructor {
self: BaseConstructor { type Algebra <: ClipIt } =>
Copy link
Contributor

@noelwelsh noelwelsh Apr 14, 2024

Choose a reason for hiding this comment

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

The clip method is not a constructor. It does not create a Picture from things that are not a Picture. See the description here.

Only constructors go here.

implicit class ClipOps[Alg <: ClipIt, A](
picture: Picture[Alg, A]
) {
def clipit(clip_path: ClosedPath): Picture[Alg, A] =
Copy link
Contributor

@noelwelsh noelwelsh Apr 14, 2024

Choose a reason for hiding this comment

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

Suggested change
def clipit(clip_path: ClosedPath): Picture[Alg, A] =
def clip(clipPath: ClosedPath): Picture[Alg, A] =

Scala does not use _ as a separator in names. It uses camelCase naming, not snake_case.

import doodle.java2d._
import PathElement._

trait Java2dClip extends ClipIt {
Copy link
Contributor

Choose a reason for hiding this comment

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

This implementation strategy will not work.

If you look at the other Java2D algebras you will see they are all implemented in the reified package. The Reified data structure represents all the drawing instructions, and the render method on Reified carries out those instructions. To implement clipping you need to do the same: represent the clipping as an instruction in Reified and then carry out the instruction in render.

@noelwelsh noelwelsh closed this Apr 22, 2024
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