drawbot icon indicating copy to clipboard operation
drawbot copied to clipboard

add methods to fit and center the bezierpath to a given bounds

Open typoman opened this issue 5 years ago • 4 comments

I've used these many times and I thought it could be useful to be added to the BezierPath object. I hope it's not too arbitrary!

typoman avatar Oct 13 '19 17:10 typoman

Also if you think this can be added, I think alignTop, alignBottom, etc to a given bound is also useful.

typoman avatar Oct 13 '19 17:10 typoman

test case:

from drawBot import *
from datetime import datetime


size(800, 800)
b = BezierPath()
b.oval(234, 324, 345, 342)
fill(None)
stroke(0)

b2 = BezierPath()
b2.rect(200, 200, 400, 400)
b.fit(b2.bounds())
drawPath(b2)
drawPath(b)


import os, subprocess
fn = os.path.split(os.path.realpath(__file__))[1] + datetime.now().strftime("%Y|%m|%d-%H%M%S")
saveImage(f"{fn}.pdf")
subprocess.call(['open', "%s.pdf" %fn])

typoman avatar Oct 13 '19 18:10 typoman

After a bit of thinking, maybe align to a path is better than bounds. Then there can be a method as alignToPath(other_path, "center") which does the job?

typoman avatar Oct 15 '19 11:10 typoman

After a bit of thinking, maybe align to a path is better than bounds.

Hm, I don't think so. I want to think a bit more about this PR. The base idea is good, and I've used similar things (but not exactly the same :) ) a lot before, so I agree something like this is useful.

justvanrossum avatar Oct 15 '19 12:10 justvanrossum

Are you interested in continuing/finishing this PR? If not, we should probably close.

justvanrossum avatar Feb 14 '24 14:02 justvanrossum