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

Path MoveTo doesnt move to the right place #20

Closed
ankitson opened this issue Oct 22, 2015 · 2 comments
Closed

Path MoveTo doesnt move to the right place #20

ankitson opened this issue Oct 22, 2015 · 2 comments

Comments

@ankitson
Copy link

MoveTo in paths doesn't seem to be working as expected for me - here is a quick example from sbt console to show you what I mean:

val c = implicitly[doodle.backend.Canvas].asInstanceOf[doodle.jvm.Java2DCanvas]
val i = implicitly[doodle.backend.Interpreter].asInstanceOf[doodle.backend.StandardInterpreter]
def axes(xLen: Int, yLen: Int) = Path(List(
  MoveTo(Vec(-xLen/2,0)), 
  LineTo(Vec(xLen/2,0)),
  MoveTo(Vec(0,-yLen/2)),
  LineTo(Vec(0,yLen/2))))
axes(100,100).draw(i,c)
val linePath = Path(List(
  MoveTo(Vec(0,0)),
  LineTo(Vec(10,10))
))
linePath.draw(i,c)

And the output:
screenshot 2015-10-22 02 51 16

I'm trying to add support for rotating images and drawing circular arcs in paths, and ran into this while testing. If you can give me a pointer to what might be wrong, id be happy to take a crack at fixing it!

@ankitson ankitson changed the title Paths are off center Path MoveTo doesnt move to the right place Oct 22, 2015
@noelwelsh
Copy link
Contributor

Thanks for the report! Rotations would be awesome. Circular arcs you should be able to build on top of BezierCurveTo, as in Canvas#circle

The issue you're seeing is caused by the call to Canvas#setOrigin here. The underlying issue is that draw attempts to render the image centered in the canvas. This requires translating from the local coordinate system that an Image uses to the global coordinate system in the Canvas.

The axes image is already centered on its local coordinate system, so there is no transformation from local to global coordinate system.

The linePath image is centered at (5,5) in its local coordinate system (the line goes from (0,0) to (10, 10)), so when we call draw it add a transform from local to global coordinates. It's this transform, along with the attempt to resize the canvas, that causes the image to not be centered relative to the previous image.

I'm not sure of the best way to fix this. There are other draw methods that allow the origin to be specified, but they aren't very convenient to use.

@noelwelsh
Copy link
Contributor

The Frame API in 0.9 fixes this.

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