-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Conversation
package object syntax { | ||
object all | ||
extends AngleSyntax | ||
with BitmapSyntax | ||
with ClipSyntax |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 } => |
There was a problem hiding this comment.
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] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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
.
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.
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.