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

Convert LineTo to MoveTo #133

Closed
AndreKR opened this issue Apr 24, 2017 · 3 comments
Closed

Convert LineTo to MoveTo #133

AndreKR opened this issue Apr 24, 2017 · 3 comments

Comments

@AndreKR
Copy link
Contributor

AndreKR commented Apr 24, 2017

If I call LineTo(x, y) on an empty path, it is automatically converted to MoveTo(0, 0); LineTo(x, y).

It would be super comfortable if it would instead be converted to MoveTo(x, y).

What do you think? I can't really imagine anyone relying on the fact that a path implicitly starts at (0, 0), so this would be barely a breaking change - especially since the coordinates of the top left pixel are (.5, .5).

@llgcode
Copy link
Owner

llgcode commented Apr 24, 2017

I think I understand the purpose. This change will may break things, but who use this? I agree may be nobody. Not sure if it works for bezier. Could be an option of a path builder?

AndreKR added a commit to AndreKR/draw2d that referenced this issue Apr 25, 2017
Same for QuadCurveTo and CubicCurveTo.

Closes llgcode#133
@AndreKR
Copy link
Contributor Author

AndreKR commented Apr 25, 2017

I think for bezier we can just ignore whatever is passed as control points for the starting point. See this example:

points := []struct{x, y float64}{
	{50, 20},
	{80, 80},
	{20, 80},
	{50, 20}, // could use path.Close() as well
}

bezierPoints := []struct{cx, cy, x, y float64}{
	{0, 0, 50, 20}, // control point (0, 0) will be ignored for the starting point
	{65, 20, 80, 80},
	{80, 95, 20, 80},
	{20, 25, 50, 20},
}

path := new(draw2d.Path)
bezierPath := new(draw2d.Path)

for _, p := range points {
	path.LineTo(p.x, p.y)
}

for _, p := range bezierPoints {
	bezierPath.QuadCurveTo(p.cx, p.cy, p.x, p.y)
}

i := image.NewRGBA(image.Rect(0, 0, 100, 100))
draw.Draw(i, i.Bounds(), image.NewUniform(image.White), image.ZP, draw.Src)
gc := draw2dimg.NewGraphicContext(i)
gc.SetStrokeColor(colornames.Green)
gc.Stroke(path)
gc.SetStrokeColor(colornames.Red)
gc.Stroke(bezierPath)

f, err := os.Create("/test.png")
log.Println(err)
png.Encode(f, i)

Before the change:
before

After the change:
after

Changes see #134.

@llgcode
Copy link
Owner

llgcode commented Apr 25, 2017

Thanks for the example. It illustrates very well the purpose of the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants